%% Example: Label a Signal in Spectrogram View
% Generate a signal composed of a voltage-controlled oscillator and four Gaussian atoms. The signal is sampled at 1.4 kHz. Use Spectrogram in Signal Labeler to label the Gaussian atoms in the signal.

fs = 1400;
t = (0:1/fs:2)';

gaussFun = @(A,x,mu,f) exp(-(x-mu).^2/(2*0.01^2)).*sin(2*pi*f.*x)*A';
s = gaussFun([1 1 1 1],t,[0.2 0.5 1 1.75],[2 6 2 5]*100)/10;
x = vco(chirp(t+.1,0,t(end),3).*exp(-2*(t-1).^2),[0.1 0.4]*fs,fs);

s = s/10+x;

% Open Signal Labeler and import the signal:
% On the Labeler tab, click Import ▼, select From workspace in the Members list, and select the s variable in the dialog box that appears.
% Set the time information. Select Time from the Working in drop-down list, select Sample Rate, and specify the sample rate as 1.4 kHz.
% Click Import ▼ and close the dialog box.
% Select the check box next to the signal name in the Labeled Signal Set Browser to display the signal in the time plot.
% The oscillating chirp dominates the signal and obscures the atoms in the time plot.
%
% Create a signal label definition:
% Click Add Definition ▼ and select Add label definition.
% In the dialog box, specify Label Name as Atoms, Label Type as ROI, and Data Type as logical.
% Click OK.
% On the Display tab, click Spectrogram in the Views section to activate the spectrogram view of the signal. Adjust the spectrogram settings in the Spectrogram tab. In the Time Resolution section, Specify a Resolution of 120 ms and an Overlap of 99%.
% The locations of the atoms are visible in the spectrogram.
%
% Label the atoms:
% In the Labeler tab, select the label definition in the Label Definitions browser.
% Specify the label value as true in the Set Value section.
% Click the spectrogram plot to draw the label. Click and drag the animated dashed line to create a shaded region. Move and resize the active region until it encloses the first atom.
% Click the spectrogram plot again to draw the label for a different atom. The app automatically accepts the previous label.
% Repeat the procedure to label the other two atoms.
%
% Copyright 2020 The MathWorks, Inc.