班级 信工082 学号 16 姓名 刘刚 实验组别
实验日期 室温 报告日期 成绩
报告内容:(目的和要求,原理,步骤,数据,计算,小结等)
实验七 语音处理系统仿真(综合滤波器设计)
一 代码:
(1)主程序:
x=wavread('login.wav');
n=0:1/22050:(size(x)-1)/22050;
x_dft=fft(x);%DFT
[x_dtft w]=freqz(x);%DTFT
subplot(2,2,1);
plot(n,x); title('原语音信号x1');
subplot(2,2,2);plot(n,abs(x_dft));
title('x的DFT变换结果x2'); grid on;
subplot(2,2,3); plot(w/pi,abs(x_dtft));
title('x2的幅度相位响应');grid on;
subplot(2,2,4);plot(w/pi,unwrap(angle(x_dtft)));
title('x2的相位相位响应');grid on;
%用FIR滤波器进行滤波
[y_low b_low]=lowpass_fir_filter(x);%调用FIR低通滤波器函数
[y_band b_band]=bandpass_fir_filter(x);%调用FIR带通滤波器函数
[y_high b_high]=highpass_fir_filter(x);%调用FIR高通滤波器函数
[hh_low ww_low]=freqz(b_low,1,512);
[hh_band ww_band]=freqz(b_band,1,512);
[hh_high ww_high]=freqz(b_high,1,512);
[h_low w_low]=freqz(y_low);
[h_band w_band]=freqz(y_band);
[h_high w_high]=freqz(y_high);
figure ;subplot(3,3,1); plot(ww_low/pi,20*log10(abs(hh_low)));
title('FIR低通滤波器');grid on;
subplot(3,3,2);plot(n,y_low);
title('经FIR低通滤波后的信号x1'); grid on;
subplot(3,3,3); plot(w_low/pi,abs(h_low));
title('x1的幅度相位响应'); grid on;
subplot(3,3,4); plot(ww_band/pi,20*log10(abs(hh_band)));
title('FIR带通滤波器'); grid on;
subplot(3,3,5); plot(n,y_band);
title('经FIR带通滤波后的信号x2'); grid on;
subplot(3,3,6); plot(w_band/pi,abs(h_band));
title('x2的幅度相位响应'); grid on;
subplot(3,3,7); plot(ww_high/pi,20*log10(abs(hh_high)));
title('FIR高通滤波器'); grid on;
subplot(3,3,8); plot(n,y_high);
title('经FIR高通滤波后的信号x3'); grid on;
subplot(3,3,9); plot(w_high/pi,abs(h_high));
title('x3的幅度相位响应'); grid on;
%用IIR滤波器进行滤波
[y_low bz_low az_low]=lowpass_iir_filter(x);%调用IIR低通滤波器函数
[y_band bz_band az_band]=bandpass_iir_filter(x);%调用IIR带通滤波器函数
[y_high bz_high az_high]=highpass_iir_filter(x);%调用IIR高通滤波器函数
[hh_low ww_low]=freqz(bz_low,az_low,256,1);
[hh_band ww_band]=freqz(bz_band,az_band,256,1);
[hh_high ww_high]=freqz(bz_high,az_high,256,1);
[h_low w_low]=freqz(y_low);
[h_band w_band]=freqz(y_band);
[h_high w_high]=freqz(y_high);
figure (3);subplot(3,3,1); plot(ww_low,abs(hh_low));
title('IIR低通滤波器'); grid on;
subplot(3,3,2);plot(n,y_low);
title('经IIR低通滤波后的信号x1'); grid on;
subplot(3,3,3); plot(w_low/pi,abs(h_low));
title('x1的幅度相位响应'); grid on;
subplot(3,3,4); plot(ww_band,abs(hh_band));
title('IIR带通滤波器'); grid on;
subplot(3,3,5); plot(n,y_band);
title('经IIR带通滤波后的信号x2'); grid on;
subplot(3,3,6); plot(w_band/pi,abs(h_band));
title('x2的幅度相位响应'); grid on;
subplot(3,3,7); plot(ww_high,abs(hh_high));
title('IIR高通滤波器'); grid on;
subplot(3,3,8); plot(n,y_high);
title('经IIR高通滤波后的信号x3'); grid on;
subplot(3,3,9); plot(w_high/pi,abs(h_high));
title('x3的幅度相位响应'); grid on;
(1)主程序:
1) FIR低通滤波器
function [y b]=bandpass_fir_filter(x)
w1=0.4*pi; w2=0.7*pi;
wn=[w1 w2];
wdelta=w2-w1;
M=ceil(3.32*pi/wdelta);
N=2*M+1;
win=hamming(N);
b=fir1(N-1,wn/pi,'bandpass',win);
y=filter(b,1,x);
2) FIR高通滤波器
function [y b]=highpass_fir_filter(x)
wp=0.6*pi; ws=0.9*pi;
wdelta=ws-wp;
M=ceil(3.32*pi/wdelta);
N=2*M+1;
wc=(ws+wp)/2;
win=hamming(N);
b=fir1(N-1,wc/pi,'high',win);
y=filter(b,1,x);
3) FIR带通滤波器
function [y b]=lowpass_fir_filter(x)
wp=0.22*pi; ws=0.46*pi;
wdelta=ws-wp;
M=ceil(3.32*pi/wdelta);
N=2*M+1; %´°
wc=(ws+wp)/2;
win=hamming(N);
b=fir1(N-1,wc/pi,win);
y=filter(b,1,x);
4) IIR低通滤波器
function [y bz az]=lowpass_iir_filter(x)
rp=1; rs=15; wp=0.25*pi; ws=0.4*pi;
wap=tan(wp/2);
was=tan(ws/2);
[n,wn]=buttord(wap,was,rp,rs,'s') ;
[z,p,k]=buttap(n);
[bp,ap]=zp2tf(z,p,k);
[bs,as]=lp2lp(bp,ap,wap);
[bz,az]=bilinear(bs,as,1/2);
y=filter(bz,az,x);
5) IIR高通滤波器
function [y bz az]=highpass_iir_filter(x)
rp=1; rs=15;
wp=0.7*pi; ws=0.85*pi;
wap=tan(wp/2); was=tan(ws/2);
[n,wn]=buttord(wap,was,rp,rs,'s') ;
[z,p,k]=buttap(n);
[bp,ap]=zp2tf(z,p,k);
[bs,as]=lp2hp(bp,ap,wap);
[bz,az]=bilinear(bs,as,1/2);
y=filter(bz,az,x);
6) IIR带通滤波器
function [y bz az]=bandpass_iir_filter(x)
rp=1; rs=15;
wp=0.35*pi; ws=0.65*pi;
wap=tan(wp/2); was=tan(ws/2);
[n,wn]=buttord(wap,was,rp,rs,'s') ;
[z,p,k]=buttap(n);
[bp,ap]=zp2tf(z,p,k);
[bs,as]=lp2bp(bp,ap,1,0.5);
[bz,az]=bilinear(bs,as,1/2);
y=filter(bz,az,x);
二 结果:
第二篇:信号与系统仿真实验报告3
上机实验三:连续LTI系统频域分析
验证试验
1_3
R=0.02;t=-2:R:2;
f=stepfun(t,-1)-stepfun(t,1);
W1=2*pi*5; %频率密度
N=500; %采样数为N
k=0:N;
W=k*W1/N; %W为频率正半轴的采样点
F=f*exp(-j*t'*W)*R; %求F(jw)
F=real(F);W=[-fliplr(W),W(2:501)];
F=[fliplr(F),F(2:501)];
subplot(2,1,1);plot(t,f);xlabel('t');ylabel('f(t)');axis([-2,2,-0.5,2]);title('f(t)=U(t+1)-U(t-1)');
subplot(2,1,2);plot(W,F);xlabel('W');ylabel('F(W)');title('f(t)的傅立叶变换');
2_1
clear all;
clc;
r=0.02;t=-5:r:5;N=200;Y=2*pi;k=-N:N;w=k*Y/N;
f1=1/2*exp(-2*t).*stepfun(t,0);%f(t)
F=r*f1*exp(-j*t'*w);%f(t)的傅立叶变换
F1=abs(F);P1=angle(F);
subplot(3,1,1);plot(t,f1);grid;xlabel('t');ylabel('f(t)');title('f(t)');
subplot(3,1,2);plot(w,F1);xlabel('w');grid;ylabel('F(jw)');
subplot(3,1,3);plot(w,P1*180/pi);grid;xlabel('w');ylabel('相位(度)');
2_2
clear all;clc;
r=0.02;t=-5:r:5;N=200
Y=2*pi;k=-N:N;w=k*Y/N;
f1=1/2*exp(-2*(t-1)).*stepfun(t,1);%f(t)
F=r*f1*exp(-j*t'*w); %f(t)的傅立叶变换
F1=abs(F);P1=angle(F);
subplot(3,1,1);plot(t,f1);grid on;xlabel('t');ylabel('f(t)');title('f(t-1)')
subplot(3,1,2);plot(w,F1);grid on;xlabel('w');ylabel('F(jw)的模');
subplot(3,1,3);plot(w,P1*180/pi);grid;xlabel('w');ylabel('相位(度)');
2_3
clear all;clc;
R=0.02;t=-2:R:2;f=stepfun(t,-1)-stepfun(t,1);
f1=f.*exp(-j*10*t);
f2=f.*exp(j*10*t);
W1=2*pi*5;
N=500;k=-N:N;W=k*W1/N;
F1=f1*exp(-j*t'*W)*R; %f1(t)傅立叶变换
F2=f2*exp(-j*t'*W)*R; %f2(t)傅立叶变换
F1=real(F1);F2=real(F2);
subplot(2,1,1);plot(W,F1);xlabel('w');ylabel('F1(jw)');title('频谱F1(jw)');
subplot(2,1,2);plot(W,F2);xlabel('w');ylabel('F2(jw)');title('频谱F2(jw)');
设计实验
1_2
clear all;
clc;
r=0.02;t=-5:r:5;N=200;Y=2*pi;k=-N:N;w=k*Y/N;
f1=exp(-3*t).*stepfun(t,0);%f(t)
F=r*f1*exp(-j*t'*w);%f(t)的傅立叶变换
F1=abs(F);P1=angle(F);
subplot(3,1,1);plot(t,f1);grid;xlabel('t');ylabel('f(t)');title('f(t)');
subplot(3,1,2);plot(w,F1);xlabel('w');grid;ylabel('F(jw)');
subplot(3,1,3);plot(w,P1*180/pi);grid;xlabel('w');ylabel('相位(度)');
1_2_2
clear all;clc;
r=0.02;t=-5:r:5;N=200
Y=2*pi;k=-N:N;w=k*Y/N;
f1=exp(-3*(t-4)).*stepfun(t,1);%f(t)
F=r*f1*exp(-j*t'*w); %f(t)的傅立叶变换
F1=abs(F);P1=angle(F);
subplot(3,1,1);plot(t,f1);grid on;xlabel('t');ylabel('f(t)');title('f(t-4)')
subplot(3,1,2);plot(w,F1);grid on;xlabel('w');ylabel('F(jw)的模');
subplot(3,1,3);plot(w,P1*180/pi);grid;xlabel('w');ylabel('相位(度)');
1_2_3
clear all;clc;
R=0.02;t=-20:R:20;f=exp(-3*t).*stepfun(t,0);
f1=f.*exp(-j*4*t);
W1=2*pi*5;
N=500;k=-N:N;W=k*W1/N;
F1=f1*exp(-j*t'*W)*R; %f1(t)傅立叶变换
F1=real(F1);
plot(W,F1);xlabel('w');ylabel('F1(jw)');title('频谱F1(jw)');