Check spectrum analyzer for new data
flag = isNewDataReady(scope)
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
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);
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.
ans = 5x4 table SimulationTime Spectrum Spectrogram FrequencyVector ______________ _______________ _________________ _______________  [1536x1 double] [100x1536 double] [1536x1 double]  [1536x1 double] [100x1536 double] [1536x1 double]  [1536x1 double] [100x1536 double] [1536x1 double]  [1536x1 double] [100x1536 double] [1536x1 double]  [1536x1 double] [100x1536 double] [1536x1 double]
scope— Spectrum analyzer
Spectrum analyzer that you want to save data from.
flag— New data flag
The spectrum analyzer shows new data.
The spectrum analyzer shows the same spectrum as the last time the scope was called.