%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLOTS THE MAGNITUDE OF THE COMPLEX SPECTRUM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function PlotSpectrumMagnitude(x, N)

% fft(X,N) is the N-point fft, padded with zeros if X has less
% than N points and truncated if it has more. (From the manual).
y = fft(x,N);   % compute the FFT of x

% Shuffle the frequencies returned by the FFT
% to order them from negative to positive.
% The function swaps the left and the right part of the vector, e.g.,
% fftshift([0,1,2,3,4,5,6,7])  ->>  [4 5 6 7 0 1 2 3]
Y=fftshift(y);

% Plot only the magnitude of the spectrum
figure; 
n = 0:N-1;              % index
bar(n-N/2,abs(Y)/N);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude of the spectrum');

