I want to make a linear interpolation a cubic spline of the second order interpolation. How?

4 次查看(过去 30 天)
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');

回答(2 个)

KSSV
KSSV 2017-10-20
编辑:KSSV 2017-10-20
  1 个评论
Paul Clarkson
Paul Clarkson 2017-10-20
I'm new to matlab and don't know where this would be applied. I know it would be in place of interp1 but which arguments I need to put in what places for the function.

请先登录,再进行评论。


Star Strider
Star Strider 2017-10-20
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.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by