%% Resolve Tones by Varying Window Leakage
% You can adjust the spectral leakage of the analysis window to resolve sinusoids in Signal Analyzer.
% Generate a two-channel signal sampled at 100 Hz for 2 seconds.
% The first channel consists of a 20 Hz tone and a 21 Hz tone. Both tones have unit amplitude.
% The second channel also has two tones. One tone has unit amplitude and a frequency of 20 Hz. The other tone has an amplitude of 1/100 and a frequency of 30 Hz.

fs = 100;

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

x = sin(2*pi*[20 20].*t)+[1 1/100].*sin(2*pi*[21 30].*t);

% Embed the signal in white noise. Specify a signal-to-noise ratio of 40 dB. Open Signal Analyzer and plot the signal using the sample rate fs.

x = x + randn(size(x)).*std(x)/db2mag(40);

% Click Spectrum to add spectral plots to the display. Click the Spectrum tab that appears.
%
%
% The slider that controls the spectral leakage is in the middle position, corresponding to a resolution bandwidth of about 1.29 Hz. The two tones in the first channel are not resolved. The 30 Hz tone in the second channel is visible, despite being much weaker than the other one.
% Increase the leakage so that the resolution bandwidth is approximately 0.84 Hz. The weak tone in the second channel is clearly resolved.
%
%
% Move the slider to the maximum value. The resolution bandwidth is approximately 0.5 Hz. The two tones in the first channel are resolved. The weak tone in the second channel is masked by the large window sidelobes.
%
%
% Click the Display tab. Use the horizontal zoom to magnify the frequency axis. Add frequency-domain cursors to estimate the frequencies of the tones.
%
% Copyright 2018 The MathWorks, Inc.