y-axis are still inverted despite using fftshift

조회 수: 3(최근 30일)
Nishant Pathak
Nishant Pathak 2021년 11월 20일
댓글: Dave B 2021년 11월 20일
I have used the Matlab codes for simulating a phase screen. However, as you can see in the figure, y-axis are still inverted despite using fftshift. Please resolve this issue.
M = 3001;
a=3;
d = (M-1)/2; fx = (-d:d);
kx = (ones(2*d+1,1)*fx).^2; K = sqrt(kx+transpose(kx));
D = K.^(-a);
D(d+1,d+1) = 0;
R = randn(2*d+1)+1i*randn(2*d+1);
PS = (fft2(fftshift(sqrt(D).*R)));
figure(1); imagesc(abs(PS)); colormap(gray);title('Phase screen');

답변(2개)

Dave B
Dave B 2021년 11월 20일
편집: Dave B 2021년 11월 20일
Your code doesn't run and you didn't include an image, but in general, when you call imagesc it will plot in ij coordinates, meaning that 0,0 is at the top left corner of the axes. To switch to traditional xy coordinates, simple use:
axis xy
(after calling image)
Alternatively, you can control the YDir property on the axes:
set(gca,'YDir','normal')
  댓글 수: 2
Dave B
Dave B 2021년 11월 20일
I just added my answer to the bottom of your code, is this not what you're looking for?
M = 3001;
a=3;
d = (M-1)/2;
fx = (-d:d);
kx = (ones(2*d+1,1)*fx).^2;
K = sqrt(kx+transpose(kx));
D = K.^(-a);
D(d+1,d+1) = 0;
R = randn(2*d+1)+1i*randn(2*d+1);
PS = (fft2(fftshift(sqrt(D).*R)));
figure(1); imagesc(abs(PS));
colormap(gray);
title('Phase screen');
axis xy

댓글을 달려면 로그인하십시오.


VBBV
VBBV 2021년 11월 20일
편집: VBBV 2021년 11월 20일
M = 3001;sz = 4;cx = 6;
d = (M-1)/2; fx = (-d:d);
kx = (ones(2*sz+1,1)*cx).^2; K = sqrt(kx+transpose(kx));a = 2;
D = K.^(-a);
D(d+1,d+1) = 0;
R = randn(d+1)+1i*randn(d+1);
PS = fft2(fftshift(sqrt(D).*R));
figure(1); imagesc(abs(PS)); colormap(gray);title('Phase screen');
ax = gca; ax.YDir = 'Normal'
You could also use handle to current axes and set the direction as Normal

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by