%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Read from a WAV file and plot the Spectrogram
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[Y,fs]=audioread('touch-tone-515.wav'); % read the WAV file
figure;
plot(1:1000,Y(1:1000), 'b.')     % plot the first 1000 samples 
xlabel('Sample number (only the first 1000)');
ylabel('Y');
title('Discrete Audio Samples');

% Replot it as a continuous function
figure;
plot(1:1000,Y(1:1000), 'b')     % plot the first 1000 samples 
xlabel('Sample number (only the first 1000)');
ylabel('Y');
title('Interpolation of the Audio Samples');

% Y   - audio data samples
% 512 - window size  (in samples)
% 256 - overlap      (in samples)
% 512 - FFT size     (in samples)
% fs  - sampling frequency (in Hz)
% 'yaxis' - put the frequencies along the y axis
figure; spectrogram(Y, 512, 256, 512, fs, 'yaxis'); 
title('Spectrogram for Area Code 515');

% store the spectrogram data in the complex matrix S
S=spectrogram(Y, 512, 256, 512, fs, 'yaxis');

% play it
sound(Y, fs)