内容发布更新时间 : 2024/12/27 4:03:55星期一 下面是文章的全部内容请认真阅读。
附 录
14.FIR窗函数低通滤波
[y,fs,nbits]= wavread('E:\\yuanyinpin.wav'); n = length (y) Noise=0.03*randn(n,2); s=y+Noise; S=fft(s); Ft=10000; Fp=700; Fs=1400; wp=2*Fp/Ft; ws=2*Fs/Ft; rp=1; rs=50;
p=1-10.^(-rp/20); q=10.^(-rs/20); fpts=[wp ws]; mag=[1 0]; dev=[p q];
[n21,wn21,beta,ftype]=kaiserord(fpts,mag,dev); b21=fir1(n21,wn21,kaiser(n21+1,beta)); z21=fftfilt(b21,s); sound(z21,fs); m21=fft(z21);
11
附 录
figure(4);
subplot(2,2,1); plot(abs(S),'g');
title('滤波前的信号频谱','fontweight','bold'); axis([0 15000 0 1000]); grid;
subplot(2,2,2); plot(abs(m21),'r');
title('滤波后的信号频谱','fontweight','bold'); axis([0 15000 0 1000]); grid;
subplot(2,2,3); plot(s);
title('滤波前的信号波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid;
subplot(2,2,4); plot(z21);
title('滤波后的信号波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid;
程序结果如下图:
12
附 录
5.FIR窗函数带通滤波
[y,fs,nbits]= wavread('E:\\yuanyinpin.wav'); n = length (y) Noise=0.03*randn(n,2);
s=y+Noise; S=fft(s); Fp1=1200; Fp2=3000; Fs1=1000; Fs2=3200; Ft=2200;
wp1=tan(pi*Fp1/Ft); wp2=tan(pi*Fp2/Ft); ws1=tan(pi*Fs1/Ft); ws2=tan(pi*Fs2/Ft); w=wp1*wp2/ws2; bw=wp2-wp1; wp=1;
ws=(wp*wp2-w.^2)/(bw*w);
[n22,wn22]=buttord(wp,ws,1,50,'s'); [b22,a22]=butter(n22,wn22,'s'); z22=fftfilt(b22,s); sound(z22,fs);
m22=fft(z22); figure;
subplot(2,2,1); plot(abs(S),'g');
title('滤波前的信号频谱','fontweight','bold'); axis([0 15000 0 1000]); grid;
subplot(2,2,2); plot(abs(m22),'r');
title('滤波后的信号频谱','fontweight','bold'); axis([0 15000 0 1000]); grid;
subplot(2,2,3); plot(s);
title('滤波前的信号波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid;
subplot(2,2,4); plot(z22);
title('滤波后的信号波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]);
13
附 录
grid;
程序结果如下图:
6.FIR窗函数高通滤波
[y,fs,nbits]= wavread('E:\\yuanyinpin.wav'); n = length (y) Noise=0.03*randn(n,2); s=y+Noise; S=fft(s); Ft=10000; Fp=1400; Fs=700; wp=2*Fp/Ft; ws=2*Fs/Ft; rp=1; rs=50;
p=1-10.^(-rp/20); q=10.^(-rs/20); fpts=[ws wp]; mag=[0 1]; dev=[p q];
[n23,wn23,beta,ftype]=kaiserord(fpts,mag,dev);
b23=fir1(n23,wn23,'high',kaiser(n23+1,beta)); z23=fftfilt(b23,s);
14
附 录
sound(z23,fs);
m23=fft(z23); figure;
subplot(2,2,1); plot(abs(S),'g');
title('滤波前的信号频谱','fontweight','bold'); axis([0 15000 0 1000]); grid;
subplot(2,2,2); plot(abs(m23),'r');
title('滤波后的信号频谱','fontweight','bold'); axis([0 15000 0 1000]); grid;
subplot(2,2,3); plot(s);
title('滤波前的信号波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid;
subplot(2,2,4); plot(z23);
title('滤波后的信号波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid;
程序结果如下图:
15