I want to make a linear interpolation a cubic spline of the second order interpolation. How?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Here is my current code. What do I need to do in order to use the cubic spline interpolation?
% Close all open figures, clear the workspace of all existing variables,
% and blank the command window
close all; clear all; clc;
% Read the data
a=dlmread('Ethanol_05273.txt');
alpha_x=a(873:2048,1)/1000;
alpha_y=a(873:2048,2);
% Visualise the data
plot(alpha_x,alpha_y); grid on;
% FFT the data without windowing
alpha_x_f=10000./alpha_x;
F=linspace(min(alpha_x_f),max(alpha_x_f),1024);
alpha_y_f=interp1(10000./alpha_x,alpha_y,F,'pchip');
FT=fft(alpha_y_f);
figure;
plot(abs(FT));
% Apply a Hanning window before FFTing the data
% Create a Hanning weights vector of the size of the alpha_y_f vector. Note
% that the apostrophe (') just transposes the w vector
w = hann(length(alpha_y_f))';
% Visualise the Hanning weights (just for info)
figure; plot(w); title('Hanning window');
% Apply the Hanning weights, pointwise, to alpha_y_f
alpha_y_f_windowed = w.*alpha_y_f;
% Just for info, visualise the 'windowed' and 'non-windowed' data
figure; hold all;
plot(F,alpha_y_f,'red'); plot(F,alpha_y_f_windowed,'blue');
legend('non-windowed','windowed');
% FFT the 'windowed data'
FT_windowed=fft(alpha_y_f_windowed);
% Plot the FFT of the windowed data
figure; plot(abs(FT_windowed)); title('Hanning windowed FFT');
0 comentarios
Respuestas (2)
Star Strider
el 20 de Oct. de 2017
My guess is that you refer to this assignment:
alpha_y_f=interp1(10000./alpha_x,alpha_y,F,'pchip');
so to use a spline interpolation instead, use 'spline' as the ‘method’ argument.
However for signal processing purposes (that you appear to be doing), I prefer the Signal Processing Toolbox resample (link) function, since it incorporates an anti-aliasing filter. Then do the fft.
0 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!