%----------------------------------------------------------------------------------------------
% Amine Faridi (29061780)
% EE416- Project 2
% Monday, October 29th, 2001
%----------------------------------------------------------------------------------------------
x=wavread('sample.wav');% wavread is the command used to read wave files
z=x'; % The transpose was taken to have a row matrix instead of column matrix
z1=z(1:256); % The number of samples chosen were 256 out of 341 because it is the nearest 2^n
% samples to 341
f=fft(z1);% fft (fats fourier transform) is used to get the spectrum of z1
% from 256 samples
fmag=abs(f);% the magnitude is obtained by using abs command
inc=2*pi/length(f);
w=-pi:inc:(pi-inc);
subplot(2,2,1);
plot(w*pi*length(f),fftshift(fmag)); % This is used to have f centered in the plot
title('graph (1)')
fang=angle(f);% This is to get the phase of f
subplot(2,2,2);
plot(w*pi*length(f),fftshift(fang/pi)); % similarly, this to center the phase
title ('graph (2)')
z2=[z1,zeros(1,256)]; % z2 is the zero-padding chosing the length of the zeros functio
% to be 256 in order to have z2 + z1 = 512, which is the nearest 2^n to 341
f1=fft(z2);% following the same steps as before to obtain the magnitude and phase.
f1mag=abs(f1);
inc1=2*pi/length(f1);
w1=-pi:inc1:(pi-inc1);
subplot(2,2,3);
plot(w1*pi*length(f1),fftshift(f1mag));
title('graph(3)')
f1ang=angle(f1);
subplot(2,2,4);
plot(w1*pi*length(f1),fftshift(f1ang/pi));
title('graph(4)')
%-------------------------------------------------------------------------------------------------
% The resolution is represented by the intervals dW and dT. dW/(2*pi)=1/(N*dT)
% where N is the number of samples. It is easy to observe from graph(2) that
% the frequency was improved, which means that the resolution was improved.
% That is the role of Zero-Padding.Since no change in the spectral was notice then the 
% density resolution has improved. 


