Skip to content

Instantly share code, notes, and snippets.

@stephenHartzell
Created July 26, 2017 03:23
Show Gist options
  • Save stephenHartzell/be6676a4c231d864387980aa099c1b63 to your computer and use it in GitHub Desktop.
Save stephenHartzell/be6676a4c231d864387980aa099c1b63 to your computer and use it in GitHub Desktop.
% The 2D signal
y = [ 1 -1 4 8 zeros(1,12)];
N = length(y);
% Plot unshifted signal
figure
subplot(2,1,1), stem(y), title('Unshifted Signal')
% Frequency domain samples
f = 0:N-1;
% The shift
k = 6;
% The exponential
shft = exp((-2*pi*i/N)*k*f);
% The shifting operation
Y = fft(y);
Yshft = Y.*shft;
yshft = real(ifft(Yshft));
% The real part of the ifft must be selected because sometimes due to
% computational errors on the part of the computer there will be a very
% small imaginary residual
subplot(2,1,2), stem(yshft), title('Shifted Signal')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment