函数格式 x1 = interp1(t,x,t1,method);
输入参数:
t - 原信号时间轴;
x - 原信号幅值;
t1 - 插值信号时间轴;
method - ‘Nearest’邻近点插值;‘Linear’线性插值;‘Spline’三次样条插值;‘Pchip’立方插值。默认情况为线性插值!
输出参数:
x1 - t1对应的信号幅值;
示例
代码
clc
clear
% 原信号
t=0:1:5;
x=sin(t);
% 插值
t1=0:0.1:5;
x1_n = interp1(t,x,t1,'nearest');
x1_L = interp1(t,x,t1,'linear');
x1_s = interp1(t,x,t1,'spline');
x1_p = interp1(t,x,t1,'pchip');
% 图形
figure
subplot(221)
scatter(t,x)
hold on
plot(t1,x1_n,'*')
legend('Orignal data','Nearest interpolation')
subplot(222)
scatter(t,x)
hold on
plot(t1,x1_L,'*')
legend('Orignal data','Liner interpolation')
subplot(223)
scatter(t,x)
hold on
plot(t1,x1_s,'*')
legend('Orignal data','Spline interpolation')
subplot(224)
scatter(t,x)
hold on
plot(t1,x1_p,'*')
legend('Orignal data','Pchip interpolation')
结果