回复 2# gracefulhe
我也一直想搞明白这个问题,下面是我写的一个简单程序,第一段就是设计一个FIR滤波器了,
第二段就是将一个脉冲送入滤波器后,得出的数据做FFT,画幅频图,
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fs = 1000;
Wp = 300;
Ws = 400;
Rp = 3;
Rs = 60;
fcuts = [Wp Ws];
devs = [(10^(Rp/20)-1)/(10^(Rp/20)+1) 10^(-Rs/20)];
mags = [1 0];
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,fs);
b = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
[h,f] = freqz(b,1,2^10,fs);
subplot(2,1,1);
plot(f,20*log10(abs(h)));
title('FIR Frequency Response/dB');
grid;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = 2^10;
x = [1,zeros(1,N-1)];
y = filter(b,1,x);
Xk = fft(y,N);
mag = abs(Xk)*2/38; % 因为滤波器的阶数为38,故输出信号前38个数是有效值,后面的数都是0,为得到实际的幅度,这里分母为38
f = [0:N-1]*fs/N;
subplot(2,1,2);
plot(f(1:N/2),20*log10(mag(1:N/2)));
grid;
从下图来看,输出信号的幅频图和滤波器频率响应形状一样,但是纵坐标明显不一样,到底我这是那里出了问题呢?
|