程序一:以下两个程序的结果一样
(1)h = [3 2 1 -2 1 0 -4 0 3];% impulse response
x = [1 -2 3 -4 3 2 1];% input sequence
y = conv(h,x);
n = 0:14;
subplot(2,1,1);
stem(n,y);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Obtained by Convolution'); grid;
(2)x1 = [x zeros(1,8)];
y1 = filter(h,1,x1);
subplot(2,1,2);
stem(n,y1);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Generated by Filtering'); grid;

程序二:filter和conv的不同
x=[1,2,3,4,5];
h=[1,1,1];
y1=conv(h,x)
y2=filter(h,1,x)
y3=filter(x,1,h)
结果:y1 =1 3 6 9 12 9 5
y2 = 1 3 6 9 12
y3 =1 3 6
可见:filter函数y(n)是从n=0开始,认为所有n<0都为0;而conv是从卷积公式计算,包括n<0部分。
因此filter 和conv 的结果长短不同
程序三:滤波后信号幅度的变化
num=100; %总共1000个数
x=rand(1,num); %生成0~1随机数序列
x(x>0.5)=1;
x(x<=0.5)=-1;
h1=[0.2,0.5,1,0.5,0.2];
h2=[0,0,1,0,0];
y1=filter(h1,1,x);
y2=filter(h2,1,x);
n=0:99;
subplot(2,1,1);
stem(n,y1);
subplot(2,1,2);
stem(n,y2);

可见:滤波后信号的幅度是发生变化的,最大幅度值也会变化。
本文详细比较了MATLAB中filter和conv函数在信号处理中的应用,解释了两者在处理卷积过程中的区别,展示了滤波后信号幅度变化的实际案例,并介绍了滤波器对信号的影响。重点讨论了filter的截断特性与conv的完整计算。
3503

被折叠的 条评论
为什么被折叠?



