Frequency AnalyzerYangXiao M2013705103HuaZhong University of Science and TechnologySchool of Mechanical Science and Engineering Abstract: Matlab Is a numerical analysis, matrix calculation, scientific data visualization and nonlinear dynamic state system modeling and simulation, and other functions of practical software engineering.It’s easy to use the windows environment and cast off a tradition on the interactive programming language (such as C, Fortran) Edit mode In large range.In this report,The task is to design a frequency analyzer by using matlab.Keyword:frequency analyzer;Matlab;time-domainanalysis;frequency-domain analysis;1.PrefaceMATLAB is called Matrix Laboratory,which is designed by the United States MathWorks company.It’s a commercial mathematical software. Matlab can be use for Matrix operations, mapping functions and data, algorithm, creating the user interface, connect to other programming languages procedures, mainly used in engineering calculations, control design, signal processing and communications, image processing, signal detection, design and financial modeling analysis and other fields. GUI (Graphical User Interface, referred to as GUI, known Graphical User Interface) is displayed using the graphical user interface of computer operations.. Matlab has a powerful GUl tool. In this report, by using matlab GUI tool we could design a frequency analyzer.Frequency analyzer is the instrument which could be used to study the structure of the electrical signal spectrum, and used to measure the signal parameters of signal distortion, modulation, frequency stability and spectral purity.Frequency analyzer could be used to measure some parameters of amplifier and filter circuit system , and it is a kind of multipurpose electronic measuring instrument.FFT (Fast Fourier Transformation) is the fast algorithm of DFT(discrete Fourier transformtion), which is based on discrete Fourier transform.By using FFT we could get the answer faster than DFT.2.IntroduceThe frequency analyzer which is designed by using matlab have three models:record,play wav file and generator some waves .Every model could make three kinds of waveforms:the time domain figure,the frequency spectrum domain figure and the power spectrum figure.We could get the message we want from the frequency analyzer.The interface is that:2.1 Interface3. Design PrinciplesThe task is to design the frequency analyzer which can record,open wav file and play it,generator some kinds of waveforms . Each waveform could do FFT analysis and draw its frequency spectrum figure and power spectrum figure.3.1 signal input3.1.1 choose signal inputWhen we start using the frequency analyzer,we should first set the sampling frequency,sampling numbers and the model of inputting signal.The frequency analyzer has three model of inputting:it’s the record,open and play wav file,signal generator.The program is(just the record):val=get(handles.model,'Value');switch valcase 1h=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');When we choose one model ,the others couldn’t work.3.1.2 The recordWe could input the sound signal by using the microphone.Matlab provides the wavecord function,which can be used to get the signal of microphone.The program of record is :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.3 Read the wav fileWe use the function of wavread to open the wav file and play it. Theprogram is:[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.4 Signal generatorMatlab has the general functions which can generator the general waveform directly.We judge the signals should add or not.The program is: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')); switch tcase 1y=a*sin(2*pi*x*f+p);case 2y=a*square(sin(2*pi*x*f+p));case 3y=a*sawtooth(2*pi*x*f+p,0.5);case 4y=a*sawtooth(2*pi*x*f+p);case 5y=a*(2*rand(size(x))-1);endif get(handles.add,'Value')==0.0handles.y=y;elsehandles.y=handles.y+y;endhandles.inputtype=3;guidata(hObject,handles);plot(handles.axes1,handles.y);xlim([0 200]);3.2 Time domain analysisMatlab provides the functions of mean and std,which can easily calculate the mean and variance.The program is :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.3 Frequency domain analysisMatlab provide the function of FFT,which can easily achieve the fast Fourier transform algorithm.The program is: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.4 Simulation3.4.1 The recordWe select the record ,set the record time and sampling frequency,pushthe start record button to begin recording.We can get the waveform of the sound in the graphic area axes1.If we push the time analysis button ,we could get the parameter of vpp,average variance.If we push the fft button,we could get the frequency spectrum figure and power spectrum figure in the graphic area axes2 and axes3.The result is shown:3.1 Image of record3.4.2 Read the wav fileThe result is shown:3.2 wav file amplitude-frequency characteristic3.4.3 Signal generatorWe set the waveform, amplitude, frequency, phase and other information to generate the waveform.The time domain analysis and frequency domain analysis is shown:3.3 amplitude-frequency characteristic of sin wave3.4 amplitude-frequency characteristic of square waveWe can add some waves and analysis3.5 phase frequency characteristics of Superposition signalOther waveform analysis:3.6 amplitude-frequency characteristic of noise4 .Exist problemWhen using the signal generator to generator the wave,the picture ofaxes3 (power spectrum)would change.I can’t solve this problem.And Ifail to build the window function.5.ConclusionIn the future study, I will learn MATLAB this powerful engineering software more harder and try to solve some common engineering problems.References[1] 薛山. MATLAB基础教程. [M] 北京:清华大学出版社,2011.3。