%% Generate Spectrogram with dsp.MatrixViewer
% This example shows how to create a spectrogram of a quadratic chirp with the dsp.MatrixViewer System object.
% Set up the sample rate and a chirp signal.

Fs = 233e3;
frameSize = 20e3;
chirp = dsp.Chirp("SampleRate",Fs,"SamplesPerFrame",frameSize,...
  "InitialFrequency",11e3,"TargetFrequency",11e3+55e3,...
  "Type","Quadratic");

%
% Create a dsp.MatrixViewer scope. Set the axis labels, select a colormap, and set the limits of the colormap.

scope = dsp.MatrixViewer(...
    "ColorBarLabel","Power/Frequency (dB/Hz)",...
    "XLabel","Frequency (Hz)",...
    "YLabel","Time (secs)",...
    "Colormap","hsv",...
    "ColorLimits",[-100,-30]);

%
% Visualize the spectrogram of the chirp signal in the scope.

for idx = 1:50
    y = chirp() + 0.05*randn(frameSize,1);
    [~,~,~,Ps] = spectrogram(y,128,120,128,1e3);
    val = 10*log10(abs(Ps)'+eps);
    scope(val);
end

% Copyright 2018 The MathWorks, Inc.