您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 电子设计/PCB > 基于MATLAB的语音信号滤波设计与实现
北京理工大学珠海学院课程设计学院:信息科学技术学院专业:06级信息工程班级:信工3班姓名:谢明学号:0601331007基于MATLAB的语音信号滤波设计与实现一、实验目的:(1)完成对语音信号的采集、频谱分析及滤波。(2)比较滤波前后语音信号的波形及频谱。二、实验原理:三.实验设计内容巴特沃思滤波器滤波%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%参数初始化%%%%%%%%%%%%%%%%clearall;%关闭以往仿真的数据栈A=5;%噪声的振幅u1=0.01;%噪声振幅的衰减系数u2=0.02;u3=0.03;f1=50;%多频噪声频率f2=200;f3=800;[Y,fs,bits]=wavread('0601331007.wav')%读出信号1,采样率和采样位数%sound(Y,fs);%[X,Fs,bits]=wavread('0601331007.wav');%读出信号2,采样率和采样位数n=length(Y);%求采样信号1的长度%m=length(X);%求采样信号2的长度t=0:1/fs:(n-1)/fs;%求采样信号1时域上的采样点数%t1=0:1/Fs:(m-1)/fs;%求采样信号2时域上的采样点数%%%%%%t=(0:n-1)/fs;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%构造噪声%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%y1=u1*A*sin(2*pi*f1*t)+u1*A*sin(2*pi*f2*t)%两两噪声相加y2=u1*A*sin(2*pi*f3*t)y=y1+y2%%%%%%Z1=u1*A*sin(2*pi*f1*t1)+u1*A*sin(2*pi*f2*t1)%两两噪声相加%%%%%%Z2=u1*A*sin(2*pi*f3*t1)%%%%%%Z=Z1+Z2%figure(1)%画出噪声的时域图,取200个点%%%%%%%%%%plot(t,y);gridon;%plot(t(1:200),y(1:200));gridon;%%xlabel('时间(t)');%ylabel('幅度(y)');%title('噪声的时域图');%%Fy=fft(y,n);%对噪声进行傅立叶变换%Fy1=abs(Fy);%n1=floor(n/2);%对zhang求采样点数的一半%n2=floor(m/2);%对zhanglow求采样点数的一半%f=(0:n1)*fs/n;%时域上的采样点数%f1=(0:n2)*Fs/m;%时域上的采样点数%%figure(2)%画出噪声的频谱图%plot(f,Fy1(1:n1+1));gridon;%xlabel('频率(f)');%ylabel('幅度(Fy1)');%title('噪声的频谱图');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%加噪声前后的时域图比较%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Y=Y(:,1);%此处假设声音是双声道的,只取单声道作分析%X=X(:,1);%此处假设声音是双声道的,只取单声道作分析Y1=y+Y';%对采样信号进行转置再加上噪声%pause(10);%暂停10ssound(Y1,fs);%读出加噪声后的采样信号%figure(3)%画出加噪声前后的时域比较图%subplot(2,1,1);plot(t,Y);gridon;%plot(t(1:1000),Y(1:1000));gridon;%xlabel('时间(t)');%ylabel('幅度(Y)');%title('加噪声前的时域图');%%subplot(2,1,2);plot(t,Y1);gridon;%%%%%%%%%%plot(t(1:1000),Y1(1:1000));gridon;%xlabel('时间(t)');%ylabel('幅度(Y1)');%title('加噪声后的时域图');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%加噪声前后的频域图比较%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%FY=fft(Y1,n);%对加噪声后的采样信号1进行傅立叶变换%FY1=abs(FY);%FY2=fft(Y,n);%对加噪声前的采样信号1进行傅立叶变换%FY3=abs(FY2);%FX=fft(X,m);%对加噪声前的采样信号2进行傅立叶变换%FX4=abs(FX);%%figure(4)%画出加噪声前后的频域比较图%subplot(2,1,1);%plot(f,FY3(1:n1+1));gridon;%xlabel('频率(f)');%ylabel('幅度(FY3)');%title('加噪声前的频谱图');%%subplot(2,1,2);%plot(f,FY1(1:n1+1));gridon;%xlabel('频率(f)');%ylabel('幅度(FY1)');%title('加噪声后的频谱图');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%不同音调相同音量信号的频域、时域图比较%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%figure(5)%subplot(2,2,1);plot(f,FY3(1:n1+1));gridon;%xlabel('频率(f)');ylabel('幅度(FY3)');title('zhang加噪声前的频谱图');%subplot(2,2,3);plot(f1,FX4(1:n2+1));gridon;%xlabel('频率(f)');ylabel('幅度(FX4)');title('zhanglow加噪声前的频谱图');%subplot(2,2,2);plot(t,Y);gridon;%xlabel('时间(t)');ylabel('幅度(Y)');title('zhang加噪声前的时域图');%subplot(2,2,4);plot(t1,X);gridon;%xlabel('时间(t1)');ylabel('幅度(X)');title('zhanglow加噪声前的时域图');%%sound(Y1,fs);%读出加噪后的信号%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%构造巴特沃思滤波器%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%figure(6);%画出zhang加噪声后的时域图plot(t,Y1);xlabel('时间(t)');ylabel('幅度(Y1)');title('lishuai加噪声后的时域图');gridon;%axis([0.040.06-33]);%%%%%%%%%%%%%%构造800Hz的带阻滤波器%%%%%%%%%%%%%f0_stop1=800;%fc=20;%设定过渡带的频率Rp=1;%通带区的波纹系数Rs=30;%阻带区的波纹系数wp_stop1=[(f0_stop1-fc)/(fs/2)(f0_stop1+fc)/(fs/2)];%通带的拐角频率ws_stop1=[(f0_stop1-5*fc)/(fs/2)(f0_stop1+5*fc)/(fs/2)];%阻带的拐角频率[N_stop1,wc_stop1]=buttord(wp_stop1,ws_stop1,Rp,Rs,'s');%求出巴特沃思滤波器的阶数N及频率参数wc[num_stop1,den_stop1]=butter(N_stop1,wc_stop1,'stop');%求出巴特沃斯带阻数字滤波器的传递函数模型系数[h_stop1,w_stop1]=freqz(num_stop1,den_stop1,fs)%求出离散系统频率响应的数值figure(7);subplot(2,3,1);%画出带阻滤波器的幅频特性图plot(w_stop1*fs/(2*pi),20*log10(abs(h_stop1)));xlabel('频率(w_stop1)');ylabel('幅度(h_stop1)');title('带阻滤波器在800Hz处的幅频特性图');gridon;B_stop1=filter(num_stop1,den_stop1,Y1);%对含噪信号Y1进行带阻滤波%pause(10);%sound(B_stop1,fs);%读出滤去800Hz噪声后的采样信号subplot(2,3,4);%画出带阻滤波器滤去800Hz噪声后的时域图plot(t,B_stop1);xlabel('时间(t))');ylabel('幅度(B_stop1)');title('用带阻滤波器滤去800Hz噪声后的时域图');gridon;%axis([0.040.06-303]);%%%%%%%%%%%%%%构造200Hz的带阻滤波器%%%%%%%%%%%%%%%%%%%%%%f0_stop2=200;wp_stop2=[(f0_stop2-fc)/(fs/2)(f0_stop2+fc)/(fs/2)];%通带的拐角频率ws_stop2=[(f0_stop2-5*fc)/(fs/2)(f0_stop2+5*fc)/(fs/2)];%阻带的拐角频率[N_stop2,wc_stop2]=buttord(wp_stop2,ws_stop2,Rp,Rs,'s');%求出巴特沃思滤波器的阶数N及频率参数wc[num_stop2,den_stop2]=butter(N_stop2,wc_stop2,'stop');%求出巴特沃斯带阻数字滤波器的传递函数模型系数[h_stop2,w_stop2]=freqz(num_stop2,den_stop2,fs)%求出离散系统频率响应的数值subplot(2,3,2);plot(w_stop2*fs/(2*pi),20*log10(abs(h_stop2)));xlabel('频率(w_stop2)');ylabel('幅度(h_stop2)');title('带阻滤波器在200Hz处的幅频特性图');gridon;B_stop2=filter(num_stop2,den_stop2,B_stop1);%对含噪信号Y1进行带阻滤波%pause(10);%sound(B_stop2,fs);%读出滤去800Hz和200Hz噪声后的采样信号subplot(2,3,5);%画出带阻滤波器滤去800Hz和200Hz噪声后的时域图plot(t,B_stop2);xlabel('时间(t))');ylabel('幅度(B_stop2)');title('带阻滤波器滤去800Hz和200Hz噪声后的时域图');gridon;%axis([0.040.06-33]);%%%%%%%%%%%%%%构造50Hz的带阻滤波器%%%%%%%%%%%%%%%%%%%%%%f0_stop3=50ws_stop3=(f0_stop3-fc)/(fs/2)%阻带的拐角频率wp_stop3=(f0_stop3+5*fc)/(fs/2)%通带的拐角频率Wws=0.0075;Wwp=0.0375;[N_stop3,wc_stop3]=buttord(Wwp,Wws,Rp,Rs,'s');%求出巴特沃思滤波器的阶数N及频率参数wc[num_stop3,dem_stop3]=butter(N_stop3,wc_stop3,'high');%求出巴特沃斯高通数字滤波器的传递函数模型系数[h_stop3,w_stop3]
本文标题:基于MATLAB的语音信号滤波设计与实现
链接地址:https://www.777doc.com/doc-4145629 .html