要求:利用MATLAB编程设计一个数字低通滤波器,对指定FSK信号进行滤波,指标要求如下:通带截止频率fp=2200Hz:
;阻带截止频率:fs=3500Hs ;采样频率 Ft=20000Hz;通带峰值起伏:ap<1dB
;最小阻带衰减: as>40dB。
bit=unifrnd(-1,+1,1,20)>0;
bit
Rb=500;
Rs=Rb;
Ts=1/Rs;
fs=20000;
T=fs/Rs;
ts=1/fs;
N=length(bit);
n_range=(0:N*T-1);
t=n_range*ts;
gTpulse=ones(1,T);
n_dly=n_range+T/2+1;
Impulses=upsample(bit,T,T/2);
rect=conv(Impulses,gTpulse);
rect=rect(n_dly);
%----------------------------------------
sRng=[0,(N*T)*ts, -1.5,+1.5];
Ffsk1=2000;
Ffsk2=4000;
mFSK=rect.*cos(2*pi*Ffsk1*t)+(1-rect).*cos(2*pi*Ffsk2*t);
figure(1);
subplot(411),plot(t,rect,'r',t,mFSK,'b'); axis(sRng);
title('2FSK信号');
xlabel('Index of Time');ylabel('Amplitude');
L_a=length(t)
%------------------------------------------
N=length(mFSK);
Fs=fs; %采样频率
xn=mFSK;
XK=abs(fft(xn,N));
f=(0:N/2)*Fs/N;
XK(1)=XK(1)/N;
XK(2:(N/2+1))=XK(2:(N/2+1))*2/N;
%subplot(212),stem(f,XK(1:(N/2+1)));
subplot(412),plot(f,XK(1:(N/2+1)));
title('2FSK信号的频谱');axis([-1 Fs/2+1 0 1]);
grid on;xlabel('f - Hz');ylabel('Amplitude');
%-=================================================
%==================================================
Fpass=2200;
Fstop=3500;
Fs=20000;
Rp=1;
Rs=40;
%=====================
dp=1-10^(-Rp/20);
ds=10^(-Rs/20);
Wp=2*Fpass/Fs;
Ws=2*Fstop/Fs;
fedge=[Fpass,Fstop];
mval=[1,0];
dev=[dp,ds];
[N,fpts,mag,wt] = remezord(fedge,mval,dev,Fs);
b = remez(N+2,fpts,mag,wt);
[H,w] = freqz(b,1,256);
[h,t_h]=impz(H,101);
%[N,Wn]=buttord(Wp,Ws,Rp,Rs);
%[num,den]=butter(N,Wn);
%[num,den]=bilinear(num,den,Fs);
%[H,w]=freqz(num,den,256);
%[h,t_h]=impz(num,den,101);
%out=conv(rect,h);
out=filter(b,1,mFSK);
%-=================================================
%==================================================
subplot(413),plot(t,out);
title('2FSK信号经过低通滤波后的时域波形');
%--------------------------------------------------
N=length(out);
%Fs=fs; %采样频率
xn=out;
XK=abs(fft(xn,N));
f=(0:N/2)*Fs/N;
XK(1)=XK(1)/N;
XK(2:(N/2+1))=XK(2:(N/2+1))*2/N;
subplot(414),plot(f,XK(1:(N/2+1)));
title('2FSK信号经过低通滤波后的频谱');axis([-1 Fs/2+1 0 1]);
xlabel('f - Hz');ylabel('Amplitude');
%---------------------------------
figure(2);
subplot(211),plot(w/pi,20*log10(abs(H)));title('FIR');
axis([0,1,-45,5]);xlabel('w/pi');ylabel('dB');
grid on;
subplot(212),stem(t_h,h);title('FIR滤波器的时域波形');
滤波前后结果对比: