附录
附录(I) 设计FIR和IIR数字滤波器 %FIR Bartlett窗低通滤波器 FS=44100;
fp=600,fc=800; wp=2*pi*fp/FS; ws=2*pi*fc/FS;
Bt=ws-wp; N0=ceil(11*pi/Bt); N=N0+mod(N0+1,2); wc=(wp+ws)/2/pi; [bz,az]=fir1(N-1,wc,bartlett(N)); [h,w]=freqz(bz,az); plot(w/pi,20*log(abs(h))); 程序结果如下图:
36
%FIR-Bartlett 窗高通滤波器 Fs=44100;
fp=3000,fc=2700; wp=2*pi*fp/FS; ws=2*pi*fc/FS;
Bt=wp-ws; N0=ceil(11*pi/Bt); N=N0+mod(N0+1,2); wc=(wp+ws)/2/pi;
[bz,az]=fir1(N-1,wc,'high',bartlett(N)); [h,w]=freqz(bz,az); plot(w/pi,20*log(abs(h)));
程序结果如下图:
37
%IIR低通滤波器 fp=600;fs=800;Fs=44100; rp=1;rs=10; wp=2*pi*fp/Fs; ws=2*pi*fs/Fs; Fs1=1;T=1; wap=2*tan(wp/2); was=2*tan(ws/2);
[N,wc]=buttord(wap,was,rp,rs,'s'); [B,A]=butter(N,wc,'s'); [Bz,Az]=bilinear(B,A,Fs1); figure(4);
[h,w]=freqz(Bz,Az,512,Fs1*44100); plot(w,abs(h));
title('巴特沃斯低通滤波器');
xlabel('频率(HZ)');ylabel('耗损(dB)'); grid;
程序结果如下图:
38
%IIR高通滤波
fp=3000;fs=2700;Fs=44100; rp=1;rs=10; wp=2*pi*fp/Fs; ws=2*pi*fs/Fs; T=1;Fs1=1; wap=2*tan(wp/2); was=2*tan(ws/2);
[N,wc]=buttord(wap,was,rp,rs,'s');%wap、was通带阻带归一化的值,0≤wp≤1,0≤ws≤1。1表示数字频率pi
[B,A]=butter(N,wc,'high','s');%计算巴特沃斯模拟滤波器系统函数的分子、分母多项式系数向量ba、aa
[Bz,Az]=bilinear(B,A,Fs1); figure(4);
[h,w]=freqz(Bz,Az,512,Fs1*44100); plot(w,abs(h));
title('巴特沃斯高通滤波器');
39
xlabel('频率(HZ)');ylabel('耗损(dB)'); grid ;
程序结果如下图:
附录(II)比较滤波前后语音信号的波形及频谱 %FIR-Bartlett窗低通滤波
[y,fs,bits]=wavread('wangwei.wav'); x=y(:,1); sound(y,fs) n=length(y) y_p=fft(y,n); f=fs*(0:n/2-1)/n; figure(1)
subplot(2,1,1); plot(y);
title('原始语音信号采样后的时域波形'); xlabel('频率点数') ylabel('幅值A') subplot(2,1,2);
plot(f,abs(y_p(1:n/2)));
title('原始语音信号采样后的频谱图'); xlabel('频率Hz');
40