%% Example: Audio Signal
% Load an audio file containing a fragment of Handel's "Hallelujah Chorus" sampled at 8192 Hz.

load handel

% Design a root-Hann window of length 512. Set analysis overlap length as 192 and synthesis overlap length as 166.

wlen = 1024;
win = blackmanharris(wlen);
noverlapA = 50;

% Compute the short-time Fourier transform using an overlap length equal to 192 and the periodic root-Hann window designed earlier.Visualize the result using the stft function with no output arguments.

stft(y,Fs,'Window',win,'OverlapLength',noverlapA)
ylim([0 4])

% Perform the CQT of the same signal using 96 bins per octave and a Blackman-Harris window. Visualize the result using the cqt function with no output arguments.

minFreq = Fs/length(y);
maxFreq = 4000;
figure
cqt(y,'SamplingFrequency',Fs,'BinsPerOctave',96,'FrequencyLimits',[minFreq maxFreq],'Window','blackmanharris')

% Calculate the spectrogram of the same signal using a 40% overlap, leakage equal to 0.2 and a frequency resolution of 20 Hz. Visualize the result using the pspectrum function with no output arguments.

pspectrum(y,Fs,'spectrogram','OverlapPercent',40,'Leakage',0.2,'FrequencyResolution',20)

% Copyright 2019 The MathWorks, Inc.