数字信号处理第三版高西全实验

图3 实验(3)图形

4. 实验四:IIR数字滤波器设计及软件实现

function st=mstg N=800;

Fs=10000;T=1/Fs;Tp=N*T; t=0:T:(N-1)*T;k=0:N-1;f=k/Tp; fc1=Fs/10; fm1=fc1/10; fc2=Fs/20; fm2=fc2/10; fc3=Fs/40; fm3=fc3/10;

xt1=cos(2*pi*fm1*t).*cos(2*pi*fc1*t); xt2=cos(2*pi*fm2*t).*cos(2*pi*fc2*t); xt3=cos(2*pi*fm3*t).*cos(2*pi*fc3*t); st=xt1+xt2+xt3; fxt=fft(st,N); subplot(211)

plot(t,st);grid;xlabel('t/s');ylabel('s(t)') axis([0,Tp/8,min(st),max(st)]); title('(a) s(t)的波形') subplot(212)

stem(f,abs(fxt)/max(abs(fxt)),'.');grid;title('(b) s(t)的频谱'); axis([0,2000,0,1]);

end

图1 信号产生函数图形

%低通 N=800;

Fs=10000;T=1/Fs;Tp=N*T; t=0:T:(N-1)*T;k=0:N-1;f=k/Tp; fp=280;fs=450; wp=2*fp/Fs;ws=2*fs/Fs; rp=0.1;rs=60;

[N,wpo]=ellipord(wp,ws,rp,rs) [B,A]=ellip(N,rp,rs,wpo) [H,W]=freqz(B,A,1000) st=mstg; y1=filter(B,A,st) figure(2) subplot(312) plot(t,y1) title('时域波形')

axis([0,Tp,min(y1),max(y1)]) subplot(311)

plot(W/pi,20*log10(abs(H)/max(abs(H)))) title('低通滤波器损耗函数') axis([0,1,-80,10]) subplot(313) Y1=fft(y1)

stem(f,abs(Y1)/max(abs(Y1)),'.')

axis([0,Fs/5,0,1.5]) title('幅频特性曲线') %带通 N=800

Fs=10000;T=1/Fs;Tp=N*T; t=0:T:(N-1)*T;k=0:N-1;f=k/Tp; fp1=440;fpu=560;fs1=275;fsu=900 wp=[2*fp1/Fs,2*fpu/Fs]; ws=[2*fs1/Fs,2*fsu/Fs]; rp=0.1;rs=60;

[N,wpo]=ellipord(wp,ws,rp,rs) [B,A]=ellip(N,rp,rs,wpo) [H,W]=freqz(B,A,1000) st=mstg; y1=filter(B,A,st) figure(3) subplot(312) plot(t,y1) title('时域波形')

axis([0,Tp,min(y1),max(y1)]) subplot(311)

plot(W/pi,20*log10(abs(H)/max(abs(H)))) title('带通滤波器损耗函数') axis([0,1,-80,10]) subplot(313) Y1=fft(y1)

stem(f,abs(Y1)/max(abs(Y1)),'.') axis([0,Fs/5,0,1.5]) title('幅频特性曲线')

%高通 N=800;

Fs=10000;T=1/Fs;Tp=N*T; t=0:T:(N-1)*T;k=0:N-1;f=k/Tp; fp=890;fs=600; wp=2*fp/Fs;ws=2*fs/Fs; rp=0.1;rs=60;

[N,wpo]=ellipord(wp,ws,rp,rs) [B,A]=ellip(N,rp,rs,wpo,'high') [H,W]=freqz(B,A,1000) y1=filter(B,A,st) figure(4)

subplot(311)

plot(W/pi,20*log10(abs(H)/max(abs(H)))) title('高通滤波器损耗函数') axis([0,1,-80,10]) subplot(312)

plot(t,y1);title('时域波形') axis([0,Tp,min(y1),max(y1)]) subplot(313) Y1=fft(y1)

stem(f,abs(Y1)/max(abs(Y1)),'.') axis([0,Fs/5,0,1.5]);title('幅频特性曲线')

图2 低通图形

图3 带通图形

图4 高通图形

5. 实验五:FIR数字滤波器设计及软件实现

function xt=xtg

N=1000;Fs=1000;T=1/Fs;Tp=N*T; t=0:T:(N-1)*T; fc=Fs/10;f0=fc/10; mt=cos(2*pi*f0*t); ct=cos(2*pi*fc*t); xt=mt.*ct; nt=2*rand(1,N)-1;

fp=150;fs=200;Rp=0.1;As=70; fb=[fp,fs];m=[0,1];

dev=[10^(-As/20),(10^(Rp/20)-1)/(10^(Rp/20)+1)]; [n,fo,mo,W]=remezord(fb,m,dev,Fs); hn=remez(n,fo,mo,W); yt=filter(hn,1,10*nt); xt=xt+yt;

fst=fft(xt,N);k=0:N-1;f=k/Tp; subplot(211)

plot(t,xt);grid;xlabel('t/s');ylabel('x(t)');

axis([0,Tp/5,min(xt),max(xt)]);title('(a) 信号加噪声波形') subplot(212)

plot(f,abs(fst)/max(abs(fst)));grid;xlabel('f/Hz');ylabel('幅度'); axis([0,Fs/2,0,1.2]);title('(b) 信号加噪声的频谱') end

%设计低通滤波器并滤除噪声 Fs=1000;N=1000;

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4