基于matlab的频谱分析仪设计.docx
- 文档编号:30302652
- 上传时间:2023-08-13
- 格式:DOCX
- 页数:10
- 大小:347.34KB
基于matlab的频谱分析仪设计.docx
《基于matlab的频谱分析仪设计.docx》由会员分享,可在线阅读,更多相关《基于matlab的频谱分析仪设计.docx(10页珍藏版)》请在冰豆网上搜索。
基于matlab的频谱分析仪设计
FrequencyAnalyzer
YangXiaoM2013705103
HuaZhongUniversityofScienceandTechnology
SchoolofMechanicalScienceandEngineering
Abstract:
MatlabIsanumericalanalysis,matrixcalculation,scientificdatavisualizationandnonlineardynamicstatesystemmodelingandsimulation,andotherfunctionsofpracticalsoftwareengineering.It’seasytousethewindowsenvironmentandcastoffatraditionontheinteractiveprogramminglanguage(suchasC,Fortran)EditmodeInlargerange.Inthisreport,Thetaskistodesignafrequencyanalyzerbyusingmatlab.
Keyword:
frequencyanalyzer;Matlab;time-domainanalysis;frequency-domainanalysis;
1.Preface
MATLABiscalledMatrixLaboratory,whichisdesignedbytheUnitedStatesMathWorkscompany.It’sacommercialmathematicalsoftware.MatlabcanbeuseforMatrixoperations,mappingfunctionsanddata,algorithm,creatingtheuserinterface,connecttootherprogramminglanguagesprocedures,mainlyusedinengineeringcalculations,controldesign,signalprocessingandcommunications,imageprocessing,signaldetection,designandfinancialmodelinganalysisandotherfields.GUI(GraphicalUserInterface,referredtoasGUI,knownGraphicalUserInterface)isdisplayedusingthegraphicaluserinterfaceofcomputeroperations..MatlabhasapowerfulGUltool.Inthisreport,byusingmatlabGUItoolwecoulddesignafrequencyanalyzer.
Frequencyanalyzeristheinstrumentwhichcouldbeusedtostudythestructureoftheelectricalsignalspectrum,andusedtomeasurethesignalparametersofsignaldistortion,modulation,frequencystabilityandspectralpurity.Frequencyanalyzercouldbeusedtomeasuresomeparametersofamplifierandfiltercircuitsystem,anditisakindofmultipurposeelectronicmeasuringinstrument.
FFT(FastFourierTransformation)isthefastalgorithmofDFT(discreteFouriertransformtion),whichisbasedondiscreteFouriertransform.ByusingFFTwecouldgettheanswerfasterthanDFT.
2.Introduce
Thefrequencyanalyzerwhichisdesignedbyusingmatlabhavethreemodels:
record,playwavfileandgeneratorsomewaves.Everymodelcouldmakethreekindsofwaveforms:
thetimedomainfigure,thefrequencyspectrumdomainfigureandthepowerspectrumfigure.Wecouldgetthemessagewewantfromthefrequencyanalyzer.
Theinterfaceisthat:
2.1Interface
3.DesignPrinciples
Thetaskistodesignthefrequencyanalyzerwhichcanrecord,openwavfileandplayit,generatorsomekindsofwaveforms.EachwaveformcoulddoFFTanalysisanddrawitsfrequencyspectrumfigureandpowerspectrumfigure.
3.1signalinput
3.1.1choosesignalinput
Whenwestartusingthefrequencyanalyzer,weshouldfirstsetthesamplingfrequency,samplingnumbersandthemodelofinputtingsignal.Thefrequencyanalyzerhasthreemodelofinputting:
it’stherecord,openandplaywavfile,signalgenerator.Theprogramis(justtherecord):
val=get(handles.model,'Value');
switchval
case1
h=findobj('Tag','recordtime');
set(h,'enable','on');
h=findobj('Tag','startrecord');
set(h,'enable','on');
h=findobj('Tag','filename');
set(h,'enable','off');
h=findobj('Tag','openfile');
set(h,'enable','off');
h=findobj('Tag','wave');
set(h,'enable','off');
h=findobj('Tag','amplitude');
set(h,'enable','off');
h=findobj('Tag','frequency');
set(h,'enable','off');
h=findobj('Tag','phase');
set(h,'enable','off');
h=findobj('Tag','add');
set(h,'enable','off');
h=findobj('Tag','generatorwave');
set(h,'enable','off');
Whenwechooseonemodel,theotherscouldn’twork.
3.1.2Therecord
Wecouldinputthesoundsignalbyusingthemicrophone.Matlabprovidesthewavecordfunction,whichcanbeusedtogetthesignalofmicrophone.
Theprogramofrecordis:
Fs=str2double(get(handles.samplefrequency,'String'));
N=str2double(get(handles.recordtime,'String'))*Fs;
handles.y=wavrecord(N,Fs,'double');
handles.inputtype=1;
guidata(hObject,handles);
plot(handles.axes1,handles.y);
ysize=size(handles.y);
set(handles.samplenumber,'String',num2str(ysize
(1)));
3.1.3Readthewavfile
Weusethefunctionofwavreadtoopenthewavfileandplayit.Theprogramis:
[fname,filepath]=uigetfile('*.wav','wav');
set(handles.filename,'string',fname);
[handles.y,Fs,bit]=wavread(fname);
temp=wavread(get(findobj('Tag','filename'),'String'));
handles.inputtype=2;
guidata(hObject,handles);
plot(handles.axes1,(1:
length(handles.y))/Fs,handles.y);
ysize=size(handles.y);
set(handles.samplenumber,'String',num2str(ysize
(1)));
set(handles.samplefrequency,'string',Fs);
wavplay(temp,Fs);
3.1.4Signalgenerator
Matlabhasthegeneralfunctionswhichcangeneratorthegeneralwaveformdirectly.Wejudgethesignalsshouldaddornot.Theprogramis:
Fs=str2double(get(handles.samplefrequency,'String'));
N=str2double(get(handles.samplenumber,'String'));
x=linspace(0,N/Fs,N);
t=get(handles.wave,'Value');
f=str2double(get(handles.frequency,'String'));
a=str2double(get(handles.amplitude,'String'));
p=str2double(get(handles.phase,'String'));
switcht
case1
y=a*sin(2*pi*x*f+p);
case2
y=a*square(sin(2*pi*x*f+p));
case3
y=a*sawtooth(2*pi*x*f+p,0.5);
case4
y=a*sawtooth(2*pi*x*f+p);
case5
y=a*(2*rand(size(x))-1);
end
ifget(handles.add,'Value')==0.0
handles.y=y;
else
handles.y=handles.y+y;
end
handles.inputtype=3;
guidata(hObject,handles);
plot(handles.axes1,handles.y);
xlim([0200]);
3.2Timedomainanalysis
Matlabprovidesthefunctionsofmeanandstd,whichcaneasilycalculatethemeanandvariance.Theprogramis:
Fs=str2double(get(handles.samplefrequency,'String'));
N=str2double(get(handles.samplenumber,'String'));
set(handles.vpp,'String',(max(handles.y)-min(handles.y)));
set(handles.average,'String',mean(handles.y));
set(handles.variance,'String',std(handles.y)^2);
3.3Frequencydomainanalysis
MatlabprovidethefunctionofFFT,whichcaneasilyachievethefastFouriertransformalgorithm.Theprogramis:
Fs=str2double(get(handles.samplefrequency,'String'));
N=str2double(get(handles.samplenumber,'String'));
temple=handles.y;
f=linspace(0,Fs/2,N/2);
P=2*fft(temple,N)/N;
Pyy=sqrt(P.*conj(P));
plot(handles.axes2,f,Pyy(1:
N/2));
plot(handles.axes3,f,abs(P(1:
N/2)).^2);
3.4Simulation
3.4.1Therecord
Weselecttherecord,settherecordtimeandsamplingfrequency,pushthestartrecordbuttontobeginrecording.Wecangetthewaveformofthesoundinthegraphicareaaxes1.Ifwepushthetimeanalysisbutton,wecouldgettheparameterofvpp,averagevariance.Ifwepushthefftbutton,wecouldgetthefrequencyspectrumfigureandpowerspectrumfigureinthegraphicareaaxes2andaxes3.Theresultisshown:
3.1Imageofrecord
3.4.2Readthewavfile
Theresultisshown:
3.2wavfileamplitude-frequencycharacteristic
3.4.3Signalgenerator
Wesetthewaveform,amplitude,frequency,phaseandotherinformationtogeneratethewaveform.Thetimedomainanalysisandfrequencydomainanalysisisshown:
3.3amplitude-frequencycharacteristicofsinwave
3.4amplitude-frequencycharacteristicofsquarewave
Wecanaddsomewavesandanalysis
3.5phasefrequencycharacteristicsofSuperpositionsignal
Otherwaveformanalysis:
3.6amplitude-frequencycharacteristicofnoise
4.Existproblem
Whenusingthesignalgeneratortogeneratorthewave,thepictureofaxes3(powerspectrum)wouldchange.Ican’tsolvethisproblem.AndIfailtobuildthewindowfunction.
5.Conclusion
Inthefuturestudy,IwilllearnMATLABthispowerfulengineeringsoftwaremoreharderandtrytosolvesomecommonengineeringproblems.
References
[1]薛山.MATLAB基础教程.[M]北京:
清华大学出版社,2011.3
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 matlab 频谱 分析 设计