MATLAB数据插值 - 基础知识

时间:2013-11-27 15:00:50

标签: matlab interpolation

我有一个由位置和信号组成的数据集 - 信号在分散的位置(0,115,230 ......)采样:

0   1.709219858
115 1.676595745
230 1.643026005
345 1.609456265
460 1.574940898
575 1.540898345
690 1.506855792
806 1.473286052

我希望对这些数据进行平滑处理,然后对其进行插值以填补干预位置,即:

0   x
1   x
2   x
3   x
4   x
5   x
6   x
7   x
8   x
9   x
10  x

其中x是平​​滑信号。我一直用命令平滑数据:

>> hann250=hanning(250); 

>> smooth250=conv(signal,hann250,'same');

但我完全不确定如何插入数据 - 我可以使用哪些命令以及我输入什么?我对MATLAB完全不熟悉!我也不确定我需要什么插值方法,但我打算尝试各种各样的方法(一旦我知道如何!)。谢谢,

Ť

3 个答案:

答案 0 :(得分:1)

您可以尝试样条插值:

http://www.mathworks.com/help/matlab/ref/spline.html

% read x, y from your file
xx = linspace(min(x), max(x), 1000); % generate 1000 equally spaced points
yy = spline(x,y,xx); % interpolate
plot(x,y); % original
hold all;
plot(xx,yy); % new

答案 1 :(得分:0)

您可以使用interp1

data = [0    1.7092
 115.0000    1.6766
 230.0000    1.6430
 345.0000    1.6095
 460.0000    1.5749
 575.0000    1.5409
 690.0000    1.5069
 806.0000    1.4733];

index_interp = 0:806; %// indices on which to interpolate
data_interp = interp1(data(:,1),data(:,2),index_interp,'linear');

除了'linear'之外,还有其他插值方法可用;见上面的链接。

答案 2 :(得分:0)

 a=[0   1.709219858
    115 1.676595745
    230 1.643026005
    345 1.609456265
    460 1.574940898
    575 1.540898345
    690 1.506855792
    806 1.473286052];
 signal=a(:,2);
 hann250=hanning(250); 
 smooth250=conv(signal,hann250,'same');
 x=a(:,1);
 y=smooth250;
 xi=[1:10]';
 yi=interp1(x,y,xi);

您的原始x的范围远大于您想要插入的范围(我假设它是从1:10开始,对吗?),因此plot(yi)几乎会给你一条线。 您可以尝试linearsplinecubicnearest中的哪种插值方法最适合您。如果要插值的点超出给定范围806,则可能需要extrap方法。

相关问题