您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 畜牧/养殖 > 语音信号matlab+GUI滤波处理
functionvarargout=digitalfilter(varargin)%DIGITALFILTERMATLABcodefordigitalfilter.fig%DIGITALFILTER,byitself,createsanewDIGITALFILTERorraisestheexisting%singleton*.%%H=DIGITALFILTERreturnsthehandletoanewDIGITALFILTERorthehandleto%theexistingsingleton*.%%DIGITALFILTER('CALLBACK',hObject,eventData,handles,...)callsthelocal%functionnamedCALLBACKinDIGITALFILTER.Mwiththegiveninputarguments.%%DIGITALFILTER('Property','Value',...)createsanewDIGITALFILTERorraisesthe%existingsingleton*.Startingfromtheleft,propertyvaluepairsare%appliedtotheGUIbeforedigitalfilter_OpeningFcngetscalled.An%unrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.Allinputsarepassedtodigitalfilter_OpeningFcnviavarargin.%%*SeeGUIOptionsonGUIDE'sToolsmenu.ChooseGUIallowsonlyone%instancetorun(singleton).%%Seealso:GUIDE,GUIDATA,GUIHANDLES%Edittheabovetexttomodifytheresponsetohelpdigitalfilter%LastModifiedbyGUIDEv2.511-Dec-201315:44:57%Begininitializationcode-DONOTEDITgui_Singleton=1;gui_State=struct('gui_Name',mfilename,...'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@digitalfilter_OpeningFcn,...'gui_OutputFcn',@digitalfilter_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);ifnargin&&ischar(varargin{1})gui_State.gui_Callback=str2func(varargin{1});endifnargout[varargout{1:nargout}]=gui_mainfcn(gui_State,varargin{:});elsegui_mainfcn(gui_State,varargin{:});end%Endinitializationcode-DONOTEDIT%---Executesjustbeforedigitalfilterismadevisible.functiondigitalfilter_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstodigitalfilter(seeVARARGIN)%Choosedefaultcommandlineoutputfordigitalfilterhandles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesdigitalfilterwaitforuserresponse(seeUIRESUME)%uiwait(handles.figure1);%---Outputsfromthisfunctionarereturnedtothecommandline.functionvarargout=digitalfilter_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;functionfiltering_Callback(hObject,eventdata,handles)%m_filter_choice_string=get(handles.m_filter_choice,'String');%读取此时设计的滤波器的类型,“Howpass、Lowpass、Bandpass、Bandstop”%set(handles.play_af,'Visible','off');filter_order_value=str2num(get(handles.filter_order,'String'));filter_startf_value=str2num(get(handles.filter_startf,'String'));filter_stopf_value=str2num(get(handles.filter_stopf,'String'));filtering_value=get(handles.filtering,'Value');globalfs;N=filter_order_value;if(get(handles.filter_hp,'Value')==1)wn=filter_stopf_value/fs*2;b=fir1(N,wn,'high');endif(get(handles.filter_lp,'Value')==1)wn=filter_stopf_value/fs*2;b=fir1(N,wn,'low');endif(get(handles.filter_bp,'Value')==1)w1=filter_startf_value/fs*2;w2=filter_stopf_value/fs*2;b=fir1(N,[w1w2],'bandpass');endif(get(handles.filter_bs,'Value')==1)w1=filter_startf_value/fs*2;w2=filter_stopf_value/fs*2;b=fir1(N,[w1w2],'DC-1');end%%设计滤波器//用下拉菜单实现%switchm_filter_choice_string%caseHP%%高通%wn=filter_stopf_value/44100*2;%b=fir1(N,wn,'high');%caseLP%%低通%wn=filter_stopf_value/44100*2;%b=fir1(N,wn,'low');%caseBP%%带通%w1=filter_startf_value/44100*2;%w2=w1+filter_band/44100*2;%b=fir1(N,[w1w2],'bandpass');%caseBS%%带阻%w1=filter_startf_value/44100*2;%w2=w1+filter_band/44100*2;%b=fir1(N,[w1w2],'DC-1');%end;%%滤波处理if(filtering_value==1)%fs=44100;%语音信号采样频率为22050%x=wavread('C:\DocumentsandSettings\CYJ-714\MyDocuments\MATLAB\meiname.wav');%读取语音信号的数据,赋给变量x%x1=x(:,2);%抽取一声道%t=(0:length(x1)-1)/44100%%X1=fft(x1,1024);%对信号做1024点FFT变globalfs;globalxx1;%xx1是截取后的音频信号x1=xx1;t=(0:length(xx1)-1)/44100;f=fs*(0:511)/1024;s=filter(b,1,x1);S1=fft(s,1024);%对信号做1024点FFT变换%%画出图形*4%axes(handles.m_filter);%freqz(b,1);%生成频率响应参数%set(handles.m_filter,'XminorTick','on')%axes(handles.m_signal_be);%plot(t,x1,'g');%holdon;%plot(t,s,'r');%legend('a','b');%title('原始语音信号');xlabel('time');ylabel('magnitude');%axis('manual');%holdon;%set(handles.m_signal_be,'XminorTick','on')axes(handles.m_signal_af)plot(t,s);%axis([010-0.80.8]);title('滤波后语音信号');xlabel('time');ylabel('magnitude');%set(handles.m_signal_af,'XminorTick','on')%axes(handles.m_fft_be);%axisauto;%plot(f,abs(X1(1:512)),'g');%holdon;%plot(f,abs(S1(1:512)),'r');%legend;%title('原始语音信号频谱');xlabel('frequency');ylabel('magnitude');%axis('manual');%holdon;%set(handles.m_fft_be,'XminorTick','on')axes(handles.m_fft_af);plot(f,abs(S1(1:512)));%axis([025000014]);title('滤波后语音信号频谱');xlabel('frequency');ylabel('magnitude');axes(handles.m_filter);H=fft(b,1024);%求出它的DFT变换,然后用plot分别画图即可。plot([1:512]/1024*fs,20*log10(abs(H(1:512))));%这个是幅频特性衰减函数%plot(angle(H));%这个是相频特性,%[h,f1]=freqz(b,1);%生成频率响应参数%subplot(2,1,1);%plot(f1,abs(h));%画幅频响应图%subplot(2,1,2);%plot(f1,angle(h));%画相频响应图%handles.song=s1;globa
本文标题:语音信号matlab+GUI滤波处理
链接地址:https://www.777doc.com/doc-4387122 .html