|
数字信号处理实验的一个作业,主要是语音滤波功能
语音滤波器Guide界面如下:
MATLAB源代码:
- function varargout = FilterSpeech(varargin)
- % FILTERSPEECH MATLAB code for FilterSpeech.fig
- % FILTERSPEECH, by itself, creates a new FILTERSPEECH or raises the existing
- % singleton*.
- %
- % H = FILTERSPEECH returns the handle to a new FILTERSPEECH or the handle to
- % the existing singleton*.
- %
- % FILTERSPEECH('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in FILTERSPEECH.M with the given input arguments.
- %
- % FILTERSPEECH('Property','Value',...) creates a new FILTERSPEECH or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before FilterSpeech_OpeningFcn gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to FilterSpeech_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 FilterSpeech
- % Last Modified by GUIDE v2.5 11-Jun-2018 01:26:21
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @FilterSpeech_OpeningFcn, ...
- 'gui_OutputFcn', @FilterSpeech_OutputFcn, ...
- 'gui_LayoutFcn', [] , ...
- 'gui_Callback', []);
- if nargin && ischar(varargin{1})
- gui_State.gui_Callback = str2func(varargin{1});
- 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 FilterSpeech is made visible.
- function FilterSpeech_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 FilterSpeech (see VARARGIN)
- % Choose default command line output for FilterSpeech
- handles.output = hObject;
- set(handles.uipanel3,'parent',gcf);
- set(handles.uipanel11,'parent',gcf);
- set(handles.uipanel12,'parent',gcf);
- handles.fs=20000;
- handles.y=0;
- %set(handles.fig1,'xcolor',[1 1 1]);
- % Update handles structure
- guidata(hObject, handles);
- % UIWAIT makes FilterSpeech wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- % --- Outputs from this function are returned to the command line.
- function varargout = FilterSpeech_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 pushbutton5.
- 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)
- %handles.r=audiorecorder(44100,16,2);
- handles.r=audiorecorder(44100,16,1);
- record(handles.r);
- guidata(hObject,handles);
- % --- 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)
- pause(handles.r);
- guidata(hObject,handles);
- % --- Executes on button press in pushbutton8.
- function pushbutton8_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton8 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- resume(handles.r);
- guidata(hObject,handles);
- % --- 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)
- stop(handles.r);
- handles.myspeech=getaudiodata(handles.r);
- guidata(hObject,handles);
- % --- 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)
- [filename,~]=uiputfile({'*.wav'},'保存录音');
- if(filename==0)
- return
- end
- audiowrite(filename,handles.myspeech,44100);
- guidata(hObject,handles);
- % --- 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)
- sound(handles.myspeech,44100);
- guidata(hObject,handles);
- % --- Executes on button press in pushbutton12.
- function pushbutton12_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton12 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- clear sound;
- guidata(hObject,handles);
- % --- Executes on button press in pushbutton13.
- function pushbutton13_Callback(hObject, ~, handles)
- % hObject handle to pushbutton13 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %plot(handles.fig1,handles.myspeech);
- %handles.t=0:1/44100:(length(handles.myspeech)-1)/44100;
- handles.y=handles.myspeech;
- handles.fs=44100;
- handles.sizeOfy=size(handles.y);
- handles.t=0:1/handles.fs:(length(handles.y)-1)/handles.fs;
- plot(handles.fig1,handles.t,handles.myspeech);
- title(handles.fig1,'录音信号时域波形','color','w');
- N=length(handles.t);
- df=44100/N;
- handles.f=[0:df:df*(N-1)]-44100/2;
- plot(handles.fig2,handles.f,fftshift(abs(fft(handles.y,N))));
- title(handles.fig2,'录音信号频域波形','color','w');
- set(handles.fig1,'XColor','w','YColor','w') ;
- set(handles.fig2,'XColor','w','YColor','w') ;
- guidata(hObject,handles);
- % --- 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)
- [filename,filepath]=uigetfile('.wav','选择音频信号');
- if(filename==0)
- return
- end
- audeofile=strcat(filepath,filename);
- [handles.y,handles.fs]=audioread(audeofile);
- handles.sizeOfy=size(handles.y);
- handles.t=0:1/handles.fs:(length(handles.y)-1)/handles.fs;
- plot(handles.fig1,handles.t,handles.y);
- title(handles.fig1,'音频信号时域波形','color','w');
- N=length(handles.t);
- df=handles.fs/N;
- handles.f=[0:df:df*(N-1)]-handles.fs/2;
- handles.fy=fftshift(abs(fft(handles.y,N)));
- plot(handles.fig2,handles.f,handles.fy);
- title(handles.fig2,'音频信号频域波形','color','w');
- set(handles.fig1,'XColor','w','YColor','w') ;
- set(handles.fig2,'XColor','w','YColor','w') ;
- guidata(hObject, handles);
- % --- 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)
- set(handles.uipanel3,'visible','off');
- set(handles.uipanel11,'visible','on');
- guidata(hObject, handles);
- % --- Executes on button press in pushbutton3.
- 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)
- %sound(handles.y,0.5*handles.fs);
- set(handles.uipanel12,'visible','on');
- set(handles.uipanel3,'visible','off');
- set(handles.uipanel11,'visible','off');
- guidata(hObject,handles);
- % --- 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)
- clear sound;
- guidata(hObject,handles);
- function edit1_Callback(hObject, eventdata, handles)
- % hObject handle to edit1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit1 as text
- % str2double(get(hObject,'String')) returns contents of edit1 as a double
- % --- Executes during object creation, after setting all properties.
- function edit1_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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
- function edit2_Callback(hObject, eventdata, handles)
- % hObject handle to edit2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit2 as text
- % str2double(get(hObject,'String')) returns contents of edit2 as a double
- % --- Executes during object creation, after setting all properties.
- function edit2_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit2 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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
- function edit3_Callback(hObject, eventdata, handles)
- % hObject handle to edit3 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit3 as text
- % str2double(get(hObject,'String')) returns contents of edit3 as a double
- % --- Executes during object creation, after setting all properties.
- function edit3_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit3 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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
- function edit4_Callback(hObject, eventdata, handles)
- % hObject handle to edit4 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit4 as text
- % str2double(get(hObject,'String')) returns contents of edit4 as a double
- % --- Executes during object creation, after setting all properties.
- function edit4_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit4 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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
- function edit5_Callback(hObject, eventdata, handles)
- % hObject handle to edit5 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit5 as text
- % str2double(get(hObject,'String')) returns contents of edit5 as a double
- % --- Executes during object creation, after setting all properties.
- function edit5_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit5 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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
- function edit6_Callback(hObject, eventdata, handles)
- % hObject handle to edit6 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit6 as text
- % str2double(get(hObject,'String')) returns contents of edit6 as a double
- % --- Executes during object creation, after setting all properties.
- function edit6_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit6 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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 pushbutton14.
- function pushbutton14_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton14 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %if(handles.fs==0)
- %handles.fs=20000;
- %set(handles.text7,'string','');
- %set(handles.text7,'string','默认fs为2000Hz ');
- %end
- handles.wp1=str2double(get(handles.edit1,'string'));
- handles.wp2=str2double(get(handles.edit2,'string'));
- handles.ws1=str2double(get(handles.edit4,'string'));
- handles.ws2=str2double(get(handles.edit5,'string'));
- handles.wap1=handles.wp1*2/handles.fs;
- handles.wap2=handles.wp2*2/handles.fs;
- handles.was1=handles.ws1*2/handles.fs;
- handles.was2=handles.ws2*2/handles.fs;
- rp=str2double(get(handles.edit3,'string'));
- rs=str2double(get(handles.edit6,'string'));
- handles.dll=get(handles.popupmenu1,'value');
- if(rp>0&&rs>rp)
- if(handles.dll==1)
- if(handles.wap2>0&&handles.wap2<handles.was1&&handles.was1<1)
- [handles.n,handles.wn]=buttord(handles.wap2,handles.was1,rp,rs);
- [handles.bz,handles.az]=butter(handles.n,handles.wn,'low');
- [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
- plot(handles.fig3,F,20*log10(abs(H)));
- set(handles.text7,'string','');
- set(handles.text7,'string','参数选择合理');
- else
- set(handles.text7,'string','');
- %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
- %set(handles.text7,'string',n0);
- set(handles.text7,'string','输入频带不符合要求');
- end
- elseif(handles.dll==2)
- if(handles.wap1<1&&handles.wap1>handles.was2&&handles.was2>0)
- [handles.n,handles.wn]=buttord(handles.wap1,handles.was2,rp,rs);
- [handles.bz,handles.az]=butter(handles.n,handles.wn,'high');
- [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
- plot(handles.fig3,F,20*log10(abs(H)));
- set(handles.text7,'string','');
- set(handles.text7,'string','参数选择合理');
- else
- set(handles.text7,'string','');
- %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
- %set(handles.text7,'string',n0);
- set(handles.text7,'string','输入频带不符合要求');
- end
- elseif(handles.dll==3)
- if(handles.was1>0&&handles.was1<handles.wap1&&handles.wap1<handles.wap2&&handles.wap2<handles.was2&&handles.was2<1)
- handles.wap=[handles.wap1,handles.wap2];
- handles.was=[handles.was1,handles.was2];
- [handles.n,handles.wn]=buttord(handles.wap,handles.was,rp,rs);
- [handles.bz,handles.az]=butter(handles.n,handles.wn,'bandpass');
- [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
- plot(handles.fig3,F,20*log10(abs(H)));
- set(handles.text7,'string','');
- set(handles.text7,'string','参数选择合理');
- else
- %return
- set(handles.text7,'string','');
- %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
- %set(handles.text7,'string',n0);
- set(handles.text7,'string','输入频带不符合要求');
- end
- elseif(handles.dll==4)
- if(handles.wap1>0&&handles.wap1<handles.was1&&handles.was1<handles.was2&&handles.was2<handles.wap2&&handles.wap2<1)
- handles.wap=[handles.wap1,handles.wap2];
- handles.was=[handles.was1,handles.was2];
- [handles.n,handles.wn]=buttord(handles.wap,handles.was,rp,rs);
- [handles.bz,handles.az]=butter(handles.n,handles.wn,'stop');
- [H,F]=freqz(handles.bz,handles.az,400,handles.fs);
- plot(handles.fig3,F,20*log10(abs(H)));
- set(handles.text7,'string','');
- set(handles.text7,'string','参数选择合理');
- else
- %return
- set(handles.text7,'string','');
- %n0=strcat(get(handles.text7,'string'),'输入频带不符合要求');
- %set(handles.text7,'string',n0);
- set(handles.text7,'string','输入频带不符合要求');
- end
- end
- else
- set(handles.text7,'string','');
- %n0=strcat(get(handles.text7,'string'),'输入增益不符合要求');
- %set(handles.text7,'string',n0);
- set(handles.text7,'string','输入增益不符合要求');
- end
- set(handles.fig3,'XColor','w','YColor','w') ;
- guidata(hObject,handles);
- % --- 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 pushbutton15.
- function pushbutton15_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton15 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- if(handles.y==0)
- set(handles.text8,'string','');
- set(handles.text8,'string','无输入信号');
- return;
- else
- handles.yy=filter(handles.bz,handles.az,handles.y);
- plot(handles.fig4,handles.t,handles.yy);
- title(handles.fig4,'滤波后信号时域波形','color','w');
- plot(handles.fig5,handles.f,fftshift(abs(fft(handles.yy,length(handles.yy)))));
- title(handles.fig5,'滤波后信号频域波形','color','w');
- set(handles.fig4,'XColor','w','YColor','w') ;
- set(handles.fig5,'XColor','w','YColor','w') ;
- set(handles.text8,'string','');
- set(handles.text8,'string','输入输出合理');
- end
- guidata(hObject,handles);
- % --- Executes on button press in pushbutton16.
- function pushbutton16_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton16 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- [filename,~]=uiputfile({'*.wav'},'保存滤波后音频文件');
- if(filename==0)
- return
- end
- audiowrite(filename,handles.yy,handles.fs);
- guidata(hObject,handles);
- % --- Executes on button press in pushbutton17.
- function pushbutton17_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton17 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- sound(handles.yy,handles.fs);
- guidata(hObject,handles);
- % --- Executes on button press in pushbutton18.
- function pushbutton18_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton18 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- clear sound;
- guidata(hObject,handles);
- % --- Executes during object creation, after setting all properties.
- function uipanel1_CreateFcn(hObject, eventdata, handles)
- % hObject handle to uipanel1 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % --- If Enable == 'on', executes on mouse press in 5 pixel border.
- % --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
- function pushbutton1_ButtonDownFcn(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)
- % --- Executes on button press in pushbutton19.
- function pushbutton19_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton19 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- handles.t=0:1/handles.fs:(length(handles.y)-1)/handles.fs;
- handles.snb=str2double(get(handles.edit7,'string'));
- %handles.f0=str2double(get(handles.edit8,'string'));
- handles.nll=get(handles.popupmenu2,'value');
- if(handles.nll==1)
- % handles.y=handles.y(:,1);
- % handles.t0=0:(length(handles.y)-1)/handles.fs;
- % handles.n=handles.snb*sin(2*pi*handles.f0*handles.t0);
- handles.n=handles.snb*randn(length(handles.y),1);
- handles.y=handles.y+handles.n;
- % if(handles.sizeOfy(2)==1)
- % handles.y=handles.y+handles.n;
- % %handles.y=handles.y+handles.snb*sin(2*pi*handles.f0*handles.t);
- % elseif(handles.sizeOfy(2)==2)
- % handles.y1=handles.y(:,1);
- % handles.y2=handles.y(:,2);
- % handles.y=[handles.y1;handles.y2];
- % handles.t1=0:1/handles.fs:(length(handles.y1)-1)/handles.fs;
- % handles.n1=handles.snb*sin(2*pi*handles.f0*handles.t1);
- % handles.t2=0:1/handles.fs:(length(handles.y2)-1)/handles.fs;
- % handles.n2=handles.snb*sin(2*pi*handles.f0*handles.t2);
- % x=length(handles.y1)
- % y=length(handles.y2)
- % z=length(handles.n1)
- % s=length(handles.n2)
- % m=length(handles.y)
- % handles.y1=handles.y1+handles.n;
- % handles.y2=handles.y2+handles.n;
- % handles.y=[handles.y1,handles.y2];
- % handles.t1=0:(2*(length(handles.y)-1))/handles.fs;
- % handles.n=handles.snb*sin(2*pi*handles.f0*handles.t1);
- % handles.y=handles.y+handles.n;
- % end
- elseif(handles.nll==2)
- handles.y=awgn(handles.y,handles.snb);
- end
- plot(handles.fig1,handles.t,handles.y);
- title(handles.fig1,'混入噪声信号时域波形','color','w');
- N=length(handles.t);
- df=handles.fs/N;
- handles.f=[0:df:df*(N-1)]-handles.fs/2;
- handles.fy=fftshift(abs(fft(handles.y,N)));
- plot(handles.fig2,handles.f,handles.fy);
- title(handles.fig2,'混入噪声信号频域波形','color','w');
- set(handles.fig1,'XColor','w','YColor','w') ;
- set(handles.fig2,'XColor','w','YColor','w') ;
- guidata(hObject,handles);
- function edit8_Callback(hObject, eventdata, handles)
- % hObject handle to edit8 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit8 as text
- % str2double(get(hObject,'String')) returns contents of edit8 as a double
- % --- Executes during object creation, after setting all properties.
- function edit8_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit8 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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
- function edit7_Callback(hObject, eventdata, handles)
- % hObject handle to edit7 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'String') returns contents of edit7 as text
- % str2double(get(hObject,'String')) returns contents of edit7 as a double
- % --- Executes during object creation, after setting all properties.
- function edit7_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit7 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit 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 selection change in popupmenu2.
- function popupmenu2_Callback(hObject, eventdata, handles)
- % hObject handle to popupmenu2 (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 popupmenu2 contents as cell array
- % contents{get(hObject,'Value')} returns selected item from popupmenu2
- % --- Executes during object creation, after setting all properties.
- function popupmenu2_CreateFcn(hObject, eventdata, handles)
- % hObject handle to popupmenu2 (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 pushbutton20.
- function pushbutton20_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton20 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.uipanel11,'visible','off');
- set(handles.uipanel3,'visible','on');
- guidata(hObject,handles);
- % --- Executes during object creation, after setting all properties.
- function pushbutton14_CreateFcn(hObject, eventdata, handles)
- % hObject handle to pushbutton14 (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 selection change in popupmenu3.
- function popupmenu3_Callback(hObject, eventdata, handles)
- % hObject handle to popupmenu3 (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 popupmenu3 contents as cell array
- % contents{get(hObject,'Value')} returns selected item from popupmenu3
- % --- Executes during object creation, after setting all properties.
- function popupmenu3_CreateFcn(hObject, eventdata, handles)
- % hObject handle to popupmenu3 (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 selection change in popupmenu4.
- function popupmenu4_Callback(hObject, eventdata, handles)
- % hObject handle to popupmenu4 (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 popupmenu4 contents as cell array
- % contents{get(hObject,'Value')} returns selected item from popupmenu4
- % --- Executes during object creation, after setting all properties.
- function popupmenu4_CreateFcn(hObject, eventdata, handles)
- % hObject handle to popupmenu4 (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 pushbutton21.
- function pushbutton21_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton21 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %handles.v1=str2double(get(handles.popupmenu3,'value'));
- handles.v1=get(handles.popupmenu3,'value');
- handles.v2=get(handles.popupmenu3,'string');
- handles.vo=str2double(handles.v2(handles.v1));
- %handles.v3=str2double(get(handles.popupmenu4,'value'));
- handles.v3=get(handles.popupmenu4,'value');
- handles.v4=get(handles.popupmenu4,'string');
- handles.ve=str2double(handles.v4(handles.v3));
- sound(handles.vo.*handles.y,handles.ve.*handles.fs);
- guidata(hObject,handles);
- % --- Executes on button press in pushbutton22.
- function pushbutton22_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton22 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.uipanel12,'visible','off');
- set(handles.uipanel3,'visible','on');
- guidata(hObject,handles);
复制代码
全部资料51hei下载地址:
语音滤波器.rar
(115.3 KB, 下载次数: 29)
|
评分
-
查看全部评分
|