Created
July 26, 2017 03:27
-
-
Save stephenHartzell/8641b948bf0e1650b1f0ea1ca0fdece3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% The 3D function | |
z = zeros(16,32); z(2:3,2:3) = ones(2); | |
Nx = size(z,2); | |
Ny = size(z,1); | |
% Plot surface | |
figure | |
subplot(2,1,1), surf(z) | |
view(0,90), title('Unshifted Signal') | |
xlabel('x') | |
ylabel('y') | |
% Frequency domain samples | |
fx = 0:Nx-1; | |
fy = 0:Ny-1; | |
% The shifts | |
kx = 10; | |
ky = 4; | |
% The exponentials | |
shft_x = exp((-2*pi*i/Nx)*kx*fx); | |
shft_y = exp((-2*pi*i/Ny)*ky*fy); | |
% The shift matrix | |
shft = shft_y.'*shft_x; | |
% The shifting operation (notice that fft2 is used for a 2D FFT) | |
Z = fft2(z); | |
Zshft = Z.*shft; | |
zshft = real(ifft2(Zshft)); | |
subplot(2,1,2), surf(zshft) | |
view(0,90), title('Unshifted Signal') | |
xlabel('x') | |
ylabel('y') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment