版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
數(shù)字信號處理實(shí)驗報告(八)實(shí)驗名稱:音頻頻譜分析儀設(shè)計與實(shí)現(xiàn)實(shí)驗原理:1、信號頻率、幅值和相位估計(1)頻率(周期)檢測對周期信號來說,可以用時域波形分析來確定信號的周期,也就是計算相鄰的兩個信號波峰的時間差、或過零點(diǎn)的時間差。這里采用過零點(diǎn)(ti)的時間差T(周期)。頻率即為f=1/T,由于能夠求得多個T值(ti有多個),故采用它們的平均值作為周期的估計值。(2)幅值檢測在一個周期內(nèi),求出信號最大值ymax與最小值ymin的差的一半,即A=(ymax-ymin)/2,同樣,也會求出多個A值,但第1個A值對應(yīng)的ymax和ymin不是在一個周期內(nèi)搜索得到的,故以除第1個以外的A值的平均作為幅值的估計值。(3)相位檢測采用過零法,即通過判斷與同頻零相位信號過零點(diǎn)時刻,計算其時間差,然后換成相應(yīng)的相位差。φ=2π(1-ti/T),{x}表示x的小數(shù)部分,同樣,以φ的平均值作為相位的估計值。頻率、幅值和相位估計的流程如圖所示。其中tin表示第n個過零點(diǎn),yi為第i個采樣點(diǎn)的值,F(xiàn)s為采樣頻率。2、數(shù)字信號統(tǒng)計量估計(1)峰值P的估計在樣本數(shù)據(jù)x中找出最大值與最小值,其差值為雙峰值,雙峰值的一半即為峰值。P=0.5[max(yi)-min(yi)](2)均值估計式中,N為樣本容量,下同。(3)均方值估計方差估計頻譜分析原理時域分析只能反映信號的幅值隨時間的變化情況,除單頻率分量的簡單波形外,很難明確提示信號的頻率組成和各頻率分量大小,而頻譜分析能很好的解決此問題。(1)DFT與FFT對于給定的時域信號y,可以通過Fourier變換得到頻域信息Y。Y可按下式計算式中,N為樣本容量,Δt=1/Fs為采樣間隔。采樣信號的頻譜是一個連續(xù)的頻譜,不可能計算出所有的點(diǎn)的值,故采用離散Fourier變換(DFT),即式中,Δf=Fs/N。但上式的計算效率很低,因為有大量的指數(shù)(等價于三角函數(shù))運(yùn)算,故實(shí)際中多采用快速Fourier變換(FFT)。其原理即是將重復(fù)的三角函數(shù)算計的中間結(jié)果保存起來,以減少重復(fù)三角函數(shù)計算帶來的時間浪費(fèi)。由于三角函數(shù)計算的重復(fù)量相當(dāng)大,故FFT能極大地提高運(yùn)算效率。(2)頻率、周期的估計對于Y(kΔf),如果當(dāng)kΔf=時,Y(kΔf)取最大值,則為頻率的估計值,由于采樣間隔的誤差,也存在誤差,其誤差最大為Δf/2。周期T=1/f。從原理上可以看出,如果在標(biāo)準(zhǔn)信號中混有噪聲,用上述方法仍能夠精確地估計出原標(biāo)準(zhǔn)信號的頻率和周期,這個將在下一章做出驗證3、頻譜圖為了直觀地表示信號的頻率特性,工程上常常將Fourier變換的結(jié)果用圖形的方式表示,即頻譜圖。以頻率f為橫坐標(biāo),|Y(f)|為縱坐標(biāo),可以得到幅值譜;以頻率f為橫坐標(biāo),argY(f)為縱坐標(biāo),可以得到相位譜;以頻率f為橫坐標(biāo),ReY(f)為縱坐標(biāo),可以得到實(shí)頻譜;以頻率f為橫坐標(biāo),ImY(f)為縱坐標(biāo),可以得到虛頻譜。根據(jù)采樣定理,只有頻率不超過Fs/2的信號才能被正確采集,即Fourier變換的結(jié)果中頻率大于Fs/2的部分是不正確的部分,故不在頻譜圖中顯示。即橫坐標(biāo)f∈[0,Fs/2]4、模塊劃分模塊化就是把程序劃分成獨(dú)立命名且可獨(dú)立訪問的模塊,每個模塊完成一個子功能,把這些模塊集成起來構(gòu)成一個整體,可以完成指定的功能滿足用戶需求。根據(jù)人類解決一般問題的經(jīng)驗,如果一個問題由兩個問題組合而成,那么它的復(fù)雜程度大于分別考慮每個問題時的復(fù)雜程度之和,也就是說把復(fù)雜的問題分解成許多容易解決的小問題,原來的問題也就容易解決了。這就是模塊化的根據(jù)。在模塊劃分時應(yīng)遵循如下規(guī)則:改進(jìn)軟件結(jié)構(gòu)提高模塊獨(dú)立性;模塊規(guī)模應(yīng)該適中;深度、寬度、扇出和扇入都應(yīng)適當(dāng);模塊的作用域應(yīng)該在控制域之內(nèi);力爭降低模塊接口的復(fù)雜程度;設(shè)計單入口單出口的模塊;模塊功能應(yīng)該可以預(yù)測。實(shí)驗內(nèi)容:參考以上原理,查閱相關(guān)資料,構(gòu)建交互界面,設(shè)計一個音頻頻譜分析儀,實(shí)現(xiàn)一下功能:音頻信號信號輸入,從聲卡輸入、從WAV文件輸入、從標(biāo)準(zhǔn)信號發(fā)生器輸入;信號波形分析,包括幅值、頻率、周期、相位的估計,以及統(tǒng)計量峰值、均值、均方值和方差的計算;信號頻譜分析,頻率、周期的估計,圖形顯示幅值譜、相位譜、實(shí)頻譜、虛頻譜和功率譜的曲線。實(shí)驗程序正弦波混疊正弦波方波三角波鋸齒波白噪聲functionvarargout=xty(varargin)%XTYM-fileforxty.fig%XTY,byitself,createsanewXTYorraisestheexisting%singleton*.%%H=XTYreturnsthehandletoanewXTYorthehandleto%theexistingsingleton*.%%XTY('CALLBACK',hObject,eventData,handles,...)callsthelocal%functionnamedCALLBACKinXTY.Mwiththegiveninputarguments.%%XTY('Property','Value',...)createsanewXTYorraisesthe%existingsingleton*.Startingfromtheleft,propertyvaluepairsare%appliedtotheGUIbeforeguojing_OpeningFunctiongetscalled.An%unrecognizedpropertynameorinvalidvaluemakespropertyapplication%stop.Allinputsarepassedtoguojing_OpeningFcnviavarargin.%%*SeeGUIOptionsonGUIDE'sToolsmenu.Choose"GUIallowsonlyone%instancetorun(singleton)".%%Seealso:GUIDE,GUIDATA,GUIHANDLES%Edittheabovetexttomodifytheresponsetohelpxty%LastModifiedbyGUIDEv2.502-Nov-202322:54:25%Begininitializationcode-DONOTEDITgui_Singleton=1;gui_State=struct('gui_Name',mfilename,...'gui_Singleton',gui_Singleton,...'gui_OpeningFcn',@guojing_OpeningFcn,...'gui_OutputFcn',@guojing_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%---Executesjustbeforextyismadevisible.functionguojing_OpeningFcn(hObject,eventdata,handles,varargin)%Thisfunctionhasnooutputargs,seeOutputFcn.%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%varargincommandlineargumentstoguojing(seeVARARGIN)%Choosedefaultcommandlineoutputforguojinghandles.output=hObject;%Updatehandlesstructureguidata(hObject,handles);%UIWAITmakesxtywaitforuserresponse(seeUIRESUME)%uiwait(handles.figure1);%---Outputsfromthisfunctionarereturnedtothecommandline.functionvarargout=guojing_OutputFcn(hObject,eventdata,handles)%varargoutcellarrayforreturningoutputargs(seeVARARGOUT);%hObjecthandletofigure%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Getdefaultcommandlineoutputfromhandlesstructurevarargout{1}=handles.output;%---Executesonbuttonpressinsoundcard.functionsoundcard_Callback(hObject,eventdata,handles)%hObjecthandletosoundcard(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hint:get(hObject,'Value')returnstogglestateofsoundcardset(findobj('Tag','recordtime'),'enable','on');h=findobj('Tag','filename');set(h,'enable','off');h=findobj('Tag','freq');set(h,'enable','off');h=findobj('Tag','amp');set(h,'enable','off');h=findobj('Tag','phase');set(h,'enable','off');set(handles.channel,'enable','off');set(handles.fileopen,'enable','off');set(handles.gensig,'enable','off');set(handles.wavetype,'enable','off');set(handles.add,'enable','off');set(handles.startrecord,'enable','on');%---Executesonbuttonpressingenerator.functiongenerator_Callback(hObject,eventdata,handles)%hObjecthandletogenerator(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hint:get(hObject,'Value')returnstogglestateofgeneratorh=findobj('Tag','filename');set(h,'enable','off');h=findobj('Tag','freq');set(h,'enable','on');h=findobj('Tag','amp');set(h,'enable','on');h=findobj('Tag','phase');set(h,'enable','on');set(findobj('Tag','recordtime'),'enable','off');set(handles.channel,'enable','off');set(handles.fileopen,'enable','off');set(handles.gensig,'enable','on');set(handles.wavetype,'enable','on');set(handles.add,'enable','on');set(handles.startrecord,'enable','off');functionrecordtime_Callback(hObject,eventdata,handles)%hObjecthandletorecordtime(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofrecordtimeastext%str2double(get(hObject,'String'))returnscontentsofrecordtimeasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionrecordtime_CreateFcn(hObject,eventdata,handles)%hObjecthandletorecordtime(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionfilename_Callback(hObject,eventdata,handles)%hObjecthandletofilename(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsoffilenameastext%str2double(get(hObject,'String'))returnscontentsoffilenameasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionfilename_CreateFcn(hObject,eventdata,handles)%hObjecthandletofilename(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end%---Executesonselectionchangeinpopupmenu1.functionpopupmenu1_Callback(hObject,eventdata,handles)%hObjecthandletopopupmenu1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:contents=get(hObject,'String')returnspopupmenu1contentsascellarray%contents{get(hObject,'Value')}returnsselecteditemfrompopupmenu1%---Executesduringobjectcreation,aftersettingallproperties.functionpopupmenu1_CreateFcn(hObject,eventdata,handles)%hObjecthandletopopupmenu1(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:popupmenucontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionfreq_Callback(hObject,eventdata,handles)%hObjecthandletofreq(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsoffreqastext%str2double(get(hObject,'String'))returnscontentsoffreqasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionfreq_CreateFcn(hObject,eventdata,handles)%hObjecthandletofreq(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionamp_Callback(hObject,eventdata,handles)%hObjecthandletoamp(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofampastext%str2double(get(hObject,'String'))returnscontentsofampasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionamp_CreateFcn(hObject,eventdata,handles)%hObjecthandletoamp(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionphase_Callback(hObject,eventdata,handles)%hObjecthandletophase(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofphaseastext%str2double(get(hObject,'String'))returnscontentsofphaseasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionphase_CreateFcn(hObject,eventdata,handles)%hObjecthandletophase(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end%---Executesonbuttonpressinstartrecord.functionstartrecord_Callback(hObject,eventdata,handles)%hObjecthandletostartrecord(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)Fs=str2double(get(findobj('Tag','samplerate'),'String'));handles.y=wavrecord(str2double(get(findobj('Tag','recordtime'),'String'))*Fs,Fs,'double');handles.inputtype=1;guidata(hObject,handles);plot(handles.time,handles.y);title('WAVE');ysize=size(handles.y)set(handles.samplenum,'String',num2str(ysize(1)));functionchannel_Callback(hObject,eventdata,handles)%hObjecthandletochannel(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofchannelastext%str2double(get(hObject,'String'))returnscontentsofchannelasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionchannel_CreateFcn(hObject,eventdata,handles)%hObjecthandletochannel(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end%---Executesonbuttonpressinfileopen.functionfileopen_Callback(hObject,eventdata,handles)%hObjecthandletofileopen(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)temp=wavread(get(findobj('Tag','filename'),'String'));channel=str2double(get(handles.channel,'String'));handles.y=temp(:,channel);handles.inputtype=2;guidata(hObject,handles);plot(handles.time,handles.y);title('WAVE');ysize=size(handles.y)set(handles.samplenum,'String',num2str(ysize(1)));%---Executesonbuttonpressinadd.functionadd_Callback(hObject,eventdata,handles)%hObjecthandletoadd(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hint:get(hObject,'Value')returnstogglestateofadd%---Executesonbuttonpressingensig.functiongensig_Callback(hObject,eventdata,handles)%hObjecthandletogensig(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)Fs=str2double(get(findobj('Tag','samplerate'),'String'));N=str2double(get(findobj('Tag','samplenum'),'String'));x=linspace(0,N/Fs,N);soundtype=get(handles.wavetype,'Value');frequency=str2double(get(handles.freq,'String'));amp=str2double(get(handles.amp,'String'));phase=str2double(get(handles.phase,'String'));switchsoundtypecase1y=amp*sin(2*pi*x*frequency+phase);case2y=amp*sign(sin(2*pi*x*frequency+phase));case3y=amp*sawtooth(2*pi*x*frequency+phase,0.5);case4y=amp*sawtooth(2*pi*x*frequency+phase);case5y=amp*(2*rand(size(x))-1);otherwiseerrordlg('Illegalwavetype','Chooseerrer');endifget(handles.add,'Value')==0.0handles.y=y;elsehandles.y=handles.y+y;endhandles.inputtype=3;guidata(hObject,handles);plot(handles.time,handles.y);title('WAVE');axis([0N-str2double(get(handles.amp,'String'))str2double(get(handles.amp,'String'))]);%---ExecutesonbuttonpressinWAVfile.functionWAVfile_Callback(hObject,eventdata,handles)%hObjecthandletoWAVfile(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hint:get(hObject,'Value')returnstogglestateofWAVfileh=findobj('Tag','filename');set(h,'enable','on');h=findobj('Tag','freq');set(h,'enable','off');h=findobj('Tag','amp');set(h,'enable','off');h=findobj('Tag','phase');set(h,'enable','off');set(findobj('Tag','recordtime'),'enable','off');set(handles.channel,'enable','on');set(handles.fileopen,'enable','on');set(handles.gensig,'enable','off');set(handles.wavetype,'enable','off');set(handles.add,'enable','off');set(handles.startrecord,'enable','off');functionsamplerate_Callback(hObject,eventdata,handles)%hObjecthandletosamplerate(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofsamplerateastext%str2double(get(hObject,'String'))returnscontentsofsamplerateasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionsamplerate_CreateFcn(hObject,eventdata,handles)%hObjecthandletosamplerate(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionsamplenum_Callback(hObject,eventdata,handles)%hObjecthandletosamplenum(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofsamplenumastext%str2double(get(hObject,'String'))returnscontentsofsamplenumasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionsamplenum_CreateFcn(hObject,eventdata,handles)%hObjecthandletosamplenum(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionpointfrom_Callback(hObject,eventdata,handles)%hObjecthandletopointfrom(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofpointfromastext%str2double(get(hObject,'String'))returnscontentsofpointfromasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionpointfrom_CreateFcn(hObject,eventdata,handles)%hObjecthandletopointfrom(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionpointto_Callback(hObject,eventdata,handles)%hObjecthandletopointto(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofpointtoastext%str2double(get(hObject,'String'))returnscontentsofpointtoasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionpointto_CreateFcn(hObject,eventdata,handles)%hObjecthandletopointto(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');end%---Executesonbuttonpressinanalyseall.functionanalyseall_Callback(hObject,eventdata,handles)%hObjecthandletoanalyseall(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)ifget(hObject,'Value')==0.0set(handles.pointfrom,'Enable','on');set(handles.pointto,'Enable','on');elseset(handles.pointfrom,'String','1','Enable','off');set(handles.pointto,'String',get(handles.samplenum,'String'),'Enable','off');end%Hint:get(hObject,'Value')returnstogglestateofanalyseall%---Executesonbuttonpressintimeanalyse.functiontimeanalyse_Callback(hObject,eventdata,handles)%hObjecthandletotimeanalyse(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)Fs=str2double(get(findobj('Tag','samplerate'),'String'));N=str2double(get(findobj('Tag','samplenum'),'String'));ifhandles.inputtype==0msgbox('Nowaveexist!Pleasechooseainputtype!');return;end%guolingjiancen=1;ymax=max([handles.y(1)handles.y(2)]);ymin=min([handles.y(1)handles.y(2)]);from=str2double(get(handles.pointfrom,'String'));to=str2double(get(handles.pointto,'String'));iffrom<1|to-from<5;msgbox('Errorrange!');return;endfori=from+2:to-1;ifhandles.y(i-1)<0&handles.y(i-2)<0&handles.y(i)>=0&handles.y(i+1)>0ifhandles.y(i)==0ti(n)=i;elseti(n)=i-handles.y(i)/(handles.y(i)-handles.y(i-1));%x1=i-1;%y1=handles.y(i-1);%x2=i;%y2=handles.y(i);%a=handles.y(i)-handles.y(i-1);%b=a*x1-y1;%ti(n)=b/a;endamp(n)=(ymax-ymin)/2;ymax=0;ymin=0;n=n+1;elseifymax<handles.y(i)ymax=handles.y(i);endifymin>handles.y(i)ymin=handles.y(i);endendendn=n-1;%freqenceandperiodicityfori=1:n-1T(i)=ti(i+1)-ti(i);endfreq=Fs/mean(T);set(handles.outt,'String',1/freq);set(handles.outfreq,'String',num2str(freq));%amplitudeset(handles.outamp,'String',num2str(mean(amp(2:n-1))));%phasephase=2*pi*(1-(ti(1:n-1)-1)./T+floor((ti(1:n-1)-1)./T));set(handles.outphase,'String',num2str(mean(phase)));%peakset(handles.outpeak,'String',(max(handles.y(from:to))-min(handles.y(from:to)))/2);%meanset(handles.outmean,'String',mean(handles.y(from:to)));%meansquareset(handles.outmeansquare,'String',mean(handles.y(from:to).^2));%sset(handles.outs,'String',std(handles.y(from:to))^2);%---Executesonbuttonpressinfreqanalyse.functionfreqanalyse_Callback(hObject,eventdata,handles)%hObjecthandletofreqanalyse(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)Fs=str2double(get(findobj('Tag','samplerate'),'String'));N=str2double(get(findobj('Tag','samplenum'),'String'));ifhandles.inputtype==0msgbox('Nowaveexist!Pleasechooseainputtype!');return;endfrom=str2double(get(handles.pointfrom,'String'));to=str2double(get(handles.pointto,'String'));sample=handles.y(from:to);f=linspace(0,Fs/2,(to-from+1)/2);Y=fft(sample,to-from+1);[C,I]=max(abs(Y));set(handles.foutt,'String',1/f(I));set(handles.foutfreq,'String',f(I));Y=Y(1:(to-from+1)/2);plot(handles.plot1,f,2*sqrt(Y.*conj(Y)));plot(handles.plot2,f,angle(Y));plot(handles.plot3,f,real(Y));plot(handles.plot4,f,imag(Y));plot(handles.plot5,f,abs(Y).^2);xlabel(handles.plot1,'freqency(Hz)');xlabel(handles.plot2,'freqency(Hz)');xlabel(handles.plot3,'freqency(Hz)');xlabel(handles.plot4,'freqency(Hz)');xlabel(handles.plot5,'freqency(Hz)');ylabel(handles.plot1,'amplitude');ylabel(handles.plot2,'phase(rad)');ylabel(handles.plot3,'real');ylabel(handles.plot4,'Imaginary');ylabel(handles.plot5,'power');functionoutt_Callback(hObject,eventdata,handles)%hObjecthandletooutt(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofouttastext%str2double(get(hObject,'String'))returnscontentsofouttasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionoutt_CreateFcn(hObject,eventdata,handles)%hObjecthandletooutt(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionoutfreq_Callback(hObject,eventdata,handles)%hObjecthandletooutfreq(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofoutfreqastext%str2double(get(hObject,'String'))returnscontentsofoutfreqasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionoutfreq_CreateFcn(hObject,eventdata,handles)%hObjecthandletooutfreq(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionoutamp_Callback(hObject,eventdata,handles)%hObjecthandletooutamp(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofoutampastext%str2double(get(hObject,'String'))returnscontentsofoutampasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionoutamp_CreateFcn(hObject,eventdata,handles)%hObjecthandletooutamp(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunctionoutphase_Callback(hObject,eventdata,handles)%hObjecthandletooutphase(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesstructurewithhandlesanduserdata(seeGUIDATA)%Hints:get(hObject,'String')returnscontentsofoutphaseastext%str2double(get(hObject,'String'))returnscontentsofoutphaseasadouble%---Executesduringobjectcreation,aftersettingallproperties.functionoutphase_CreateFcn(hObject,eventdata,handles)%hObjecthandletooutphase(seeGCBO)%eventdatareserved-tobedefinedinafutureversionofMATLAB%handlesempty-handlesnotcreateduntilafterallCreateFcnscalled%Hint:editcontrolsusuallyhaveawhitebackgroundonWindows.%SeeISPCandCOMPUTER.ifispc&&isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'Bac
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年昭通市消防救援支隊招錄第五批政府專職消防員(83人)參考題庫附答案
- 2026廣西南寧市西鄉(xiāng)塘區(qū)那龍衛(wèi)生院招聘編外工作人員2人筆試備考試題及答案解析
- 2025年下半年宜賓市一中翠屏初級中學(xué)校公開考核招聘合同制教師招聘(公共基礎(chǔ)知識)測試題附答案
- 2025年甘肅省中材科技(酒泉)風(fēng)電葉片有限公司招聘208人公筆試備考試題附答案
- 2025年浙江溫州醫(yī)科大學(xué)附屬第一醫(yī)院招聘生物樣本庫實(shí)驗員1人備考題庫附答案
- 2025廣東廣州市花都區(qū)獅嶺鎮(zhèn)聯(lián)合小學(xué)招聘臨聘教師1人備考題庫附答案
- AI賦能基因組醫(yī)學(xué):從技術(shù)突破到臨床實(shí)踐
- 2026福建省儲備糧管理有限公司莆田直屬庫招聘1人筆試備考試題及答案解析
- 2026福建漳州市鼓浪嶼故宮文物館招聘6人筆試備考試題及答案解析
- 2026重慶經(jīng)開區(qū)物業(yè)管理有限公司招聘筆試參考題庫及答案解析
- 主管護(hù)師聘任述職報告
- AI搜索時代:從GEO到AIBE的品牌新藍(lán)圖
- 云南省2025年高二上學(xué)期普通高中學(xué)業(yè)水平合格性考試《信息技術(shù)》試卷(解析版)
- 產(chǎn)品知識培訓(xùn)會議總結(jié)
- 四川省成都市樹德實(shí)驗中學(xué)2026屆九年級數(shù)學(xué)第一學(xué)期期末監(jiān)測試題含解析
- 與業(yè)主溝通技巧培訓(xùn)
- 專題11 圓(安徽專用)5年(2021-2025)中考1年模擬《數(shù)學(xué)》真題分類匯編
- 工程春節(jié)停復(fù)工方案(3篇)
- 社區(qū)基金使用管理辦法
- WST856-2025安全注射標(biāo)準(zhǔn)解讀
- 低壓控制基本知識培訓(xùn)課件
評論
0/150
提交評論