matlab代码语音信号分析和去噪处理

matlab代码语音信号分析和去噪处理
matlab代码语音信号分析和去噪处理

S X 文理学院

数理信息学院

数字信号处理

课程设计报告书题目语音信号分析与去噪处理

姓名

学号

专业班级电信11级信号处理

指导教师于刘

时间年月日

课程设计任务书

源码

function varargout = PF(varargin)

% PF MATLAB code for PF.fig

% PF, by itself, creates a new PF or raises the existing

% singleton*.

%

% H = PF returns the handle to a new PF or the handle to

% the existing singleton*.

%

% PF('CALLBACK',hObject,eventData,handles,...) calls the local

% function named CALLBACK in PF.M with the given input arguments.

%

% PF('Property','Value',...) creates a new PF or raises the

% existing singleton*. Starting from the left, property value pairs are

% applied to the GUI before PF_OpeningFcn gets called. An

% unrecognized property name or invalid value makes property application

% stop. All inputs are passed to PF_OpeningFcn via varargin.

%

% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help PF

% Last Modified by GUIDE v2.5 06-Jul-2014 11:15:51

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @PF_OpeningFcn, ...

'gui_OutputFcn', @PF_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else

gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% --- Executes just before PF is made visible.

function PF_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to PF (see VARARGIN)

% Choose default command line output for PF

handles.output = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes PF wait for user response (see UIRESUME)

% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = PF_OutputFcn(hObject, eventdata, handles)

% varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure varargout{1} = handles.output;

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

%************语音信号采集******************

global YL YH YK YG YY;

global F BB;

[fn,pn,fi]=uigetfile('*.wav','select a wav-file');%调用选择文件对话框,返回fn代表名字,pn代表路径name=strcat(pn,fn);[y1,Fs,bits]=wavread(name); %采样值放在向量y中,fs表示采样频率(hz),bits表示采样位数

T=length(y1)/Fs;

set(handles.text4,'string',Fs);

set(handles.text12,'string',T);

set(handles.text15,'string',bits);

YL=y1;YH=y1;YK=y1;YG=y1;YY=y1;BB=bits;F=Fs;

Y=fft(y1,524288);

plot(handles.axes1,0:1/Fs:(length(y1)-1)/Fs,y1);

axes(handles.axes1);

legend('原信号波形',1);

stem(handles.axes2,0:2*pi/524288:2*pi-1/524288,abs(Y),'.');

set(handles.axes2,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes2);

legend('原信号频谱',1);

%************************************************

% --- Executes on button press in pushbutton2.

function pushbutton2_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

%*****************声音播放****************************

global YY F BB;

y1=YY;Fs=F;bits=BB;

sound(YY,Fs,bits);%播放声音

function pushbutton3_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

%*******************高斯噪声************************** global h z YY YG;y1=YG;

h=0.05*randn(size(y1));

z=plus(h,y1);Z=fft(z,524288);

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Z),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes4);

legend('加入高斯噪声频谱',1);

YY=z;

% --- Executes on button press in pushbutton4.

function pushbutton4_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton4 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %***************滤除高斯噪声******************

global h z YY;

%*****************自适应算法***********************

w=[0,1];%初始2阶加权系数

u=0.00026;%最佳参数

for i=1:length(z);

y(i+1)=h(i:i+1)*w';

e(i+1)=z(i+1)-y(i+1);

w=w+2*u*e(i+1)*h(i:i+1);

end;

Y=fft(e,524288);

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Y),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]);

legend('滤除高斯噪声频谱',1);

YY=e;

%******************************************

function pushbutton5_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton5 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %******************低通滤波器*********************** global YL YY F Yli Ylf;

y1=YL;

Fs=F;

%******************IIR*****************

fp=6000;fs=8000;Fs=44100;

rp=3;rs=10;

wp=2*pi*fp/Fs;

ws=2*pi*fs/Fs;

op=2*tan(wp/2);

os=2*tan(ws/2);

[N, wc]=buttord(op,os,rp,rs,'s');

[B, A]=butter(N,wc,'s');

[Bz, Az]=bilinear(B ,A,1);

%**********FIR****************

Bt=abs(wp-ws);

N=ceil(6.6*pi/Bt);

wc=(wp+ws)/2/pi;

hn=fir1(N-1,wc,'low',hamming(N));

co=get(handles.popupmenu1,'value');

if co==2

y2=fftfilt(Bz,y1);

Yli=fft(y2,524288);

YY=y2;

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Yli),'.');

set(handles.axes4,'xlim',[0 2*pi]);

axes(handles.axes4);

legend('低通滤波频谱',1);

elseif co==3

y3=fftfilt(hn,y1);

Ylf=fft(y3,524288);

YY=y3;

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Ylf),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes4);

legend('低通滤波频谱',1);

end

% --- Executes on button press in pushbutton6.

function pushbutton6_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %*********************高通*******************

global YH YY F Yhi Yhf;

Fs=F;y1=YH;

%*********************IIR*********************

fph=10000;fsh=11000;

rph=3;rsh=10;

wph=2*pi*fph/Fs;

wsh=2*pi*fsh/Fs;

oph=2*tan(wph/2);

osh=2*tan(wsh/2);

[Nh, wch]=buttord(oph,osh,rph,rsh,'s');

[Bh, Ah]=butter(Nh,wch,'s');

[Bs,As]=lp2hp(Bh,Ah,wch);

[Bzh, Azh]=bilinear(Bs ,As,1);

%*******************FIR************************

Bth=abs(wph-wsh);

Nh0=ceil(6.6*pi/Bth);

Nh=Nh0+mod(Nh0+1,2);

wch=(wph+wsh)/2/pi;

hnh=fir1(Nh-1,wch,'high',hamming(Nh));

co=get(handles.popupmenu1,'value');

if co==2

y3=fftfilt(Bzh,y1);

Yhi=fft(y3,524288);

YY=y3;

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Yhi),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes4);

legend('高通滤波频谱',1);

elseif co==3

y4=fftfilt(hnh,y1);

Yhf=fft(y4,524288);

YY=y4;

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Yhf),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes4);

legend('高通滤波频谱',1);

end

% --- Executes on button press in pushbutton7.

function pushbutton7_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton7 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %***********************带通****************

%******************IIR**********************

global YK YY Ypi Ypf;

y1=YK;

Fs=44100;

wpp=[6000 8000]*2/Fs;

wsp=[5000 10000]*2/Fs;

rpp=3;rsp=20;

[N,Wn]=buttord(wpp,wsp,rpp,rsp,'s');

[Bp,Ap]=butter(N,Wn,'bandpass');

%*********************FIR**********************

fpl=5000;fph1=6000;

fsl=8000;fsh1=10000;

wpl=2*pi*fpl/Fs;

wph1=2*pi*fph1/Fs;

wsl=2*pi*fsl/Fs;

wsh1=2*pi*fsh1/Fs;

Bthb=abs(wpl-wsl);

Nhb=ceil(6.6*pi/Bthb);

wcl=(wpl+wph1)/2/pi;

wch1=(wsl+wsh1)/2/pi;

wn=[wcl wch1];

hnb=fir1(Nhb-1,wn,hamming(Nhb));

co=get(handles.popupmenu1,'value')

if co==2

y3=fftfilt(Bp,y1);

Ypi=fft(y3,524288);

YY=y3;

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Ypi),'.');

set(handles.axes4,'ylim',[0 40],'xlim',[0 2*pi]);

axes(handles.axes4);

legend('带通滤波频谱',1);

elseif co==3

y4=fftfilt(hnb,y1);

Ypf=fft(y4,524288);

YY=y4;

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Ypf),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes4);

legend('带通滤波频谱',1);

end

% --- Executes on button press in radiobutton1.

function radiobutton1_Callback(hObject, eventdata, handles)

% hObject handle to radiobutton1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1

% --- Executes on button press in radiobutton2.

function radiobutton2_Callback(hObject, eventdata, handles)

% hObject handle to radiobutton2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2

% --- Executes on selection change in popupmenu1.

function popupmenu1_Callback(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1

% --- Executes during object creation, after setting all properties.

function popupmenu1_CreateFcn(hObject, eventdata, handles)

% hObject handle to popupmenu1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.

% See ISPC and COMPUTER.

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

end

% --- Executes on button press in checkbox1.

function checkbox1_Callback(hObject, eventdata, handles)

% hObject handle to checkbox1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox1

% --- Executes on button press in checkbox2.

function checkbox2_Callback(hObject, eventdata, handles)

% hObject handle to checkbox2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox2

% --- Executes during object creation, after setting all properties.

function pushbutton3_CreateFcn(hObject, eventdata, handles)

% hObject handle to pushbutton3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% --- Executes on button press in pushbutton9.

function pushbutton9_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton9 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global Yli Ylf;

stem(handles.axes2,0:2*pi/524288:2*pi-1/524288,abs(Yli),'.');

set(handles.axes2,'xlim',[0 2*pi]);

axes(handles.axes2);

legend('IIR低通滤波频谱',1);

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Ylf),'.');

set(handles.axes4,'xlim',[0 2*pi]);

axes(handles.axes4);

legend('FIR低通滤波频谱',1);

% --- Executes on button press in pushbutton10.

function pushbutton10_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton10 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global Yhi Yhf;

stem(handles.axes2,0:2*pi/524288:2*pi-1/524288,abs(Yhi),'.');

set(handles.axes2,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes2);

legend('IIR高通滤波频谱',1);

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Yhf),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]);

axes(handles.axes4);

legend('FIR高通滤波频谱',1);

% --- Executes on button press in pushbutton11.

function pushbutton11_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton11 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global Ypi Ypf;

stem(handles.axes2,0:2*pi/524288:2*pi-1/524288,abs(Ypi),'.');

set(handles.axes2,'ylim',[0 40],'xlim',[0 2*pi]);

axes(handles.axes2);

legend('IIR带通滤波频谱',1);

stem(handles.axes4,0:2*pi/524288:2*pi-1/524288,abs(Ypf),'.');

set(handles.axes4,'ylim',[0 1500],'xlim',[0 2*pi]); axes(handles.axes4);

legend('FIR带通滤波频谱',1);

相关主题
相关文档
最新文档