编辑: yyy888555 | 2013-06-07 |
,'
FIR高通'
,'
FIR带通'
);
if k1==1 firlowpass;
else if k1==2 firhighpass;
else if k1==3 firbandpass;
end end end else if k==2 k2=menu('
请选择IIR滤波器类型:'
,'
IIR低通'
,'
IIR高通'
,'
IIR带通'
);
if k2==1 iirlowpass;
else if k2==2 iirhighpass;
else if k2==3 iirbandpass;
end end end end end b=menu('
do you want to continue?'
,'
yes'
,'
no'
);
if b==2 b=0;
end end temp=1;
temp=menu('
close all figure?'
,'
yes'
,'
no'
);
if temp==1 close all end 2.子程序: (!)、FIR低通滤波器: function[]= firlowpass();
[y,fs,bit]=wavread('
yuyin.wav'
) N=length(y);
%返回采样点数 t=(1:N)/fs;
df=fs/N;
%采样间隔 n1=1:N;
f=(n1-1)*df;
%频带宽度 wp=2*pi*1000/fs;
ws=2*pi*1200/fs;
width=ws-wp n=ceil(12.8*pi/width)+1 wn=(ws+wp)/2 beta=10.056 win=kaiser(n,beta) b=fir1(n-1,wn/pi,win) [H,m]=freqz(b,[1],1024,'
whole'
) figure(1) plot(m,abs(H)) title('
FIR数字低通滤波器幅度响应'
) figure(2) subplot(2,1,1) plot(t,y) title('
声音信号时域波形'
) c=fftfilt(b,y) subplot(2,1,2) plot(t,c) title('
过滤后声音信号时域波形'
) figure(3) y1=fft(y) subplot(2,1,1) plot(f,abs(y1)) title('
声音信号幅度响应'
) c1=fft(c) subplot(2,1,2) plot(f,abs(c1)) title('
过滤后声音信号幅度响应'
) sound(c,fs) 实验结果: (2)、FIR低通滤波器: function[]=firhighpass();
[y,fs,bit]=wavread('
yuyin.wav'
) N=length(y);
%返回采样点数 t=(1:N)/fs;
df=fs/N;
%采样间隔 n1=1:N;
f=(n1-1)*df;
%频带宽度 wp=2*pi*5000/fs;
ws=2*pi*4800/fs;
width=wp-ws n=ceil(12.8*pi/width)+1 wn=(ws+wp)/2 beta=10.056 b=fir1(n-1,wn/pi,'
high'
,kaiser(n,beta)) [H,m]=freqz(b,[1],1024,'
whole'
) figure(1) plot(m,abs(H)) title('
FIR数字高通滤波器幅度响应'
) figure(2) subplot(2,1,1) plot(t,y) title('
声音信号时域波形'
) c=fftfilt(b,y) subplot(2,1,2) plot(t,c) title('
过滤后声音信号时域波形'
) sound(c,fs) y1=fft(y) c1=fft(c) figure(3) subplot(2,1,1) plot(f,abs(y1)) title('
声音信号幅度响应'
) subplot(2,1,2) plot(f,abs(c1)) title('
过滤后声音信号幅度响应'
) sound(c,fs) 实验结果: (3)、FIR带通滤波器: function[]=firbandpass();
[y,fs,bit]=wavread('
yuyin.wav'
) N=length(y);
%返回采样点数 t=(1:N)/fs;
df=fs/N;
%采样间隔 n1=1:N;
f=(n1-1)*df;
%频带宽度 wp=[2*pi*1200/fs,2*pi*3000/fs] ws=[2*pi*1000/fs,2*pi*3200/fs] width=2*pi*1200/fs-2*pi*1000/fs n=ceil(12.8*pi/width)+1 wn=(ws+wp)/2 beta=10.056 win=kaiser(n,beta) b=fir1(n-1,wn/pi,win) [H,m]=freqz(b,[1],200,'
whole'
) figure(1) plot(m,abs(H)) title('
FIR数字带通滤波器幅度响应'
) figure(2) subplot(2,1,1) plot(t,y) title('
声音信号时域波形'
) c=fftfilt(b,y) subplot(2,1,2) plot(t,c) title('
过滤后声音信号时域波形'
) y1=fft(y) c1=fft(c) figure(3) subplot(2,1,1) plot(f,abs(y1)) title('
声音信号幅度响应'
) subplot(2,1,2) plot(f,abs(c1)) title('
过滤后声音信号幅度响应'
) sound(c,fs) 实验结果: (4)、IIR低通滤波器: function[]=iirlowpass();
[x,fs,bits]=wavread('
yuyin.wav'
);
%播放原始信号 N=length(x);