I want to make a linear interpolation a cubic spline of the second order interpolation. How?
4 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Star Strider
on 20 Oct 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 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!