www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ComputeThePowerSpectrumOfANoisySineWaveExample.m
%% Power and Max-Hold Spectra of Noisy Sine Wave %% % *Note*: This example runs only in R2016b or later. If you are using an % earlier release, replace each call to the function with the equivalent % |step| syntax. For example, myObject(x) becomes step(myObject,x). %% % Generate a sine wave. %% SINE = dsp.SineWave('Frequency',100,'SampleRate',1000, ... 'SamplesPerFrame',1000); %% % Use the Spectrum Estimator to compute the power spectrum and the max-hold % spectrum of the sine wave. Use the Array Plot to display the spectra. SE = dsp.SpectrumEstimator('SampleRate',SINE.SampleRate, ... 'SpectrumType','Power','PowerUnits','dBm', ... 'FrequencyRange','centered','OutputMaxHoldSpectrum',true); PLOTTER = dsp.ArrayPlot('PlotType','Line','XOffset',-500, ... 'YLimits',[-60 30], 'Title','Power Spectrum of 100 Hz Sine Wave', ... 'YLabel','Power Spectrum (dBm)','XLabel','Frequency (Hz)'); %% % Add random noise to the sine wave. Stream in the data, and plot the % power spectrum of the signal. for ii = 1:10 x = SINE() + 0.05*randn(1000,1); [Pxx,Pmax] = SE(x); PLOTTER([Pxx Pmax]); end