%% Log Spectrum Data
% While a spectrum analyzer is running, save the spectrum data to a table.
% The spectrum analyzer does not update at every time step. To avoid saving
% that redundant spectrum data, use the |isNewDataReady| function.

%% 
wave = dsp.SineWave('Frequency',100,'SampleRate',1000);
wave.SamplesPerFrame = 1000;
scope = dsp.SpectrumAnalyzer('SampleRate',wave.SampleRate,...
    'ReducePlotRate',false,...
    'ViewType','Spectrum and spectrogram');
data = [];

for ii = 1:250
    x = wave() + 0.05*randn(1000,1);
    scope(x);
    if scope.isNewDataReady
        data = [data;getSpectrumData(scope)];
    end
end

release(scope);
%%
% In the |data| table, you can see gaps in the simulation time.  These
% missing rows indicate times where the spectrum analyzer was waiting for
% additional samples to update the spectrum. The |isNewDataReady| function
% prevented the script from saving that redundant data.
data(1:5,:)

%% 
% Copyright 2012 The MathWorks, Inc.