给定x(n),它被上采样4倍,我想用下面的代码插值:
pkg load signal;
n = [1:100];
x = n.*cos(n);
upsampled = upsample(x,4);
b = fir1(30,0.25,'low');
interpolated = filter(b,1,upsampled)(16:end);
figure;
stem([1:4:400],x);
hold on;
stem(interpolated);
其中原始x(n)为蓝色,插值为红色。
为什么插值信号按比例缩小?
这看起来更好:
pkg load signal;
n = [1:100];
x = n.*cos(n);
upsampled = upsample(x,4);
b = fir1(30,0.25,'low');
interpolated = filter(b,1,upsampled)(16:end);
figure;
stem([1:4:400],x);
hold on;
stem(interpolated*4); %notice the multiplication by 4 here
但为什么会这样呢?或者我只是幸运?
答案 0 :(得分:2)
我可以看到明确的相关性:
upsample(x,4)
和
stem(interpolated * 4)
upsample
在变量的每对值之间插入3个零。因此,您的过滤器函数将生成一个平滑的结果。如果你的结果满足你,那很好。或者,尝试绕过这样的问题:
pkg load signal;
n = 1:100;
x = n .* cos(n);
b = fir1(30,0.25,'low');
interpolated = filter(b,1,x)(4:end);
final = upsample(interpolated,4);
figure;
stem([1:4:400],x);
hold on;
stem(final);