基于matlab的语音信号处理 下载本文

内容发布更新时间 : 2024/12/26 16:29:38星期一 下面是文章的全部内容请认真阅读。

附 录

附录III 源程序代码

function varargout = G0606001(varargin) % G0606001 MATLAB code for G0606001.fig

% G0606001, by itself, creates a new G0606001 or raises the existing % singleton*. %

% H = G0606001 returns the handle to a new G0606001 or the handle to % the existing singleton*. %

% G0606001('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in G0606001.M with the given input arguments. %

% G0606001('Property','Value',...) creates a new G0606001 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before G0606001_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to G0606001_OpeningFcn via varargin. %

% *See GUI Options on GUIDE's Tools menu. Choose \ % instance to run (singleton)\ %

% See also: GUIDE, GUIDATA, GUIHANDLES

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

% Last Modified by GUIDE v2.5 06-Jun-2016 12:08:17

% Begin initialization code - DO NOT EDIT gui_Singleton = 1;

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

'gui_OpeningFcn', @G0606001_OpeningFcn, ... 'gui_OutputFcn', @G0606001_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []);

if nargin && ischar(varargin{1})

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

16

附 录

end 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 G0606001 is made visible.

function G0606001_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 G0606001 (see VARARGIN)

% Choose default command line output for G0606001 handles.output = hObject;

% Update handles structure guidata(hObject, handles);

% UIWAIT makes G0606001 wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = G0606001_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;

17

附 录

% --- Executes on button press in pushbutton12.

function pushbutton12_Callback(hObject, eventdata, handles) [y,fs,nbits]=wavread('E:\\yuanyinpin.wav'); %IIRμíí¨ n = length (y) Noise=0.03*randn(n,2); s=y+Noise;

S=fft(s); Ft=20000; Fp=700; Fs=1400; wp=2*pi*Fp/Ft; ws=2*pi*Fs/Ft;

[n11,wn11]=buttord(wp,ws,1,50,'s'); [b11,a11]=butter(n11,wn11,'s'); [num11,den11]=bilinear(b11,a11,0.5); z11=filter(num11,den11,s); sound(z11,fs);

m11=fft(z11); figure; subplot(2,2,1); plot(abs(S),'g');

title('滤波前信号的频谱','fontweight','bold'); axis([ 0 15000 0 1000]); grid; subplot(2,2,2); plot(abs(m11),'r');

title('滤波后信号的频谱','fontweight','bold'); axis([ 0 15000 0 1000]); grid; subplot(2,2,3); plot(s);

title('滤波前信号的波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid; subplot(2,2,4); plot(z11);

title('滤波后信号的波形','fontweight','bold');

18

附 录

axis([67000 87000 -0.5 0.5]); grid;

% --- Executes on button press in pushbutton13.

function pushbutton13_Callback(hObject, eventdata, handles)

[y,fs,nbits]= wavread('E:\\yuanyinpin.wav'); n = length (y) Noise=0.03*randn(n,2); s=y+Noise; S=fft(s); Fp1=1400; Fs1=700; Ft=10000;

wp1=tan(pi*Fp1/Ft); ws1=tan(pi*Fs1/Ft); wp=1;

ws=wp1*wp/ws1;

[n13,wn13]=cheb1ord(wp,ws,1,50,'s'); [b13,a13]=cheby1(n13,1,wn13,'s'); [num,den]=lp2hp(b13,a13,wn13); [num13,den13]=bilinear(num,den,0.5); z13=filter(num13,den13,s); sound(z13,fs);

m13=fft(z13); figure; subplot(2,2,1); plot(abs(S),'g');

title('滤波前信号的频谱','fontweight','bold'); axis([0 15000 0 1000]); grid; subplot(2,2,2); plot(abs(m13),'r');

title('滤波后信号的频谱','fontweight','bold'); axis([0 15000 0 1000]); grid; subplot(2,2,3); plot(s);

19

附 录

title('滤波前信号的波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid; subplot(2,2,4); plot(z13);

title('滤波后信号的波形','fontweight','bold'); axis([67000 87000 -0.5 0.5]); grid;

% --- Executes on button press in pushbutton14.

function pushbutton14_Callback(hObject, eventdata, handles) [y,fs,nbits]= wavread('E:\\yuanyinpin.wav'); n = length (y) Noise=0.03*randn(n,2); s=y+Noise; S=fft(s); Ft=20000; Fp=700; Fs=1400; wp=2*Fp/Ft; ws=2*Fs/Ft; rp=1; rs=50;

p=1-10.^(-rp/20); q=10.^(-rs/20); fpts=[wp ws]; mag=[1 0]; dev=[p q];

[n21,wn21,beta,ftype]=kaiserord(fpts,mag,dev); b21=fir1(n21,wn21,kaiser(n21+1,beta)); z21=fftfilt(b21,s); sound(z21,fs);

m21=fft(z21); figure(4); subplot(2,2,1); plot(abs(S),'g');

20