%% Shift 1-D Signal
% When analyzing the frequency components of signals, it can be helpful to shift the zero-frequency components to the center.
% Create a signal S, compute its Fourier transform, and plot the power.

fs = 100;               % sampling frequency
t = 0:(1/fs):(10-1/fs); % time vector
S = cos(2*pi*15*t);
n = length(S);
X = fft(S);
f = (0:n-1)*(fs/n);     %frequency range
power = abs(X).^2/n;    %power
plot(f,power)

%
% Shift the zero-frequency components and plot the zero-centered power.

Y = fftshift(X);
fshift = (-n/2:n/2-1)*(fs/n); % zero-centered frequency range
powershift = abs(Y).^2/n;     % zero-centered power
plot(fshift,powershift)

% Copyright 2012 The MathWorks, Inc.