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