%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Read from a WAV file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[Y,fs]=audioread('note_440Hz.wav'); % read the WAV file
nSamples = size(Y,1)    % print the size of the data (in samples)
fs                      % print the sampling frequency (in Hz)    

N = 1000;               % focus on the first N samples only

% Plot the samples with a horizontal axis in samples 
figure;
plot(1:N, Y(1:N), 'b.');      % plot only the first N samples 
xlabel('Sample number');
ylabel('Y');
title('The wave for a 440 Hz sine, sampled at 44,100 Hz');

% Plot the samples with a horizontal axis in seconds 
figure;
time = 0: 1/fs : (N-1)/fs;    % construct the time vector
plot(time, Y(1:N), 'r.');     % plot the first N samples
xlabel('Time ( in seconds )');
ylabel('Y');
title('The wave for a 440 Hz sine, sampled at 44,100 Hz');

% Print the time of the N-th sample
format long
(N-1)/fs
format short

