Make ifft2 to give real output

조회 수: 10 (최근 30일)
Mona Mahboob Kanafi
Mona Mahboob Kanafi 2015년 5월 20일
댓글: Ralf Mackenbach 2019년 4월 10일
I'm trying to generate a randomly rough surface(isotropic surface). Suppose I have the absolute values of fourier components of the surface in "H" and H has symmetry with respect to center of the array. Now, I need to define some random phase for the fourier series which are between -pi to pi (due to fftshift) as in:
phi = -pi + (pi+pi)*rand(n); % random phase
Now, I don't know what to do to make the output of my surface real..
Here is the gist of the code I used so far:
[a,b] = pol2cart(phi,H);
H_complex = complex(a,b); % the complex fourier transform composed of H & phi
z = ifft2(ifftshift((H_complex)));
If I need to apply conjugate symmetry to the fourier components, how should I do it? The output is complex and I need a real surface.
Please help! Thanks a lot.

채택된 답변

Mona Mahboob Kanafi
Mona Mahboob Kanafi 2015년 5월 21일
편집: Mona Mahboob Kanafi 2015년 5월 21일
I found my answer, so maybe useful for someone else as well. I need to apply conjugate symmetry condition for 2D fourier transform, both in magnitude values and phase components. I applied it as below for a n*m matrix:
"H" is the magnitude:
H(1,1) = 0;
H(1,m/2+1) = 0;
H(n/2+1,m/2+1) = 0;
H(n/2+1,1) = 0;
H(2:end,2:m/2) = rot90(H(2:end,m/2+2:end),2);
H(1,2:m/2) = rot90(H(1,m/2+2:end),2);
H(n/2+2:end,1) = rot90(H(2:n/2,1),2);
H(n/2+2:end,m/2+1) = rot90(H(2:n/2,m/2+1),2);
Similar operation but with negative sign applies to "phi" (phase):
phi(1,1) = 0;
phi(1,m/2+1) = 0;
phi(n/2+1,m/2+1) = 0;
phi(n/2+1,1) = 0;
phi(2:end,2:m/2) = -rot90(phi(2:end,m/2+2:end),2);
phi(1,2:m/2) = -rot90(phi(1,m/2+2:end),2);
phi(n/2+2:end,1) = -rot90(phi(2:n/2,1),2);
phi(n/2+2:end,m/2+1) = -rot90(phi(2:n/2,m/2+1),2);
You can refer to this link for a good example of 2D fourier transform on a matrix and how the results should look like: http://fourier.eng.hmc.edu/e101/lectures/image_processing/node6.html
  댓글 수: 1
Ralf Mackenbach
Ralf Mackenbach 2019년 4월 10일
Small correction to this. The condition that
H(1,1) = 0;
H(1,m/2+1) = 0;
H(n/2+1,m/2+1) = 0;
H(n/2+1,1) = 0;
Does not need to hold necessarily. So a better (examplary) version would be
% Choose even m and n
m = 100 ;
n = 100 ;
% Choose average value of surface
z0 = 1 ;
% Fill random examplary matrices
H = rand(n,m) ;
phi = 2*pi*rand(n,m) ;
% Apply symmetry to matrices
H(1,1) = z0*m*n ;
H(2:end,2:m/2) = rot90(H(2:end,m/2+2:end),2);
H(1,2:m/2) = rot90(H(1,m/2+2:end),2);
H(n/2+2:end,1) = rot90(H(2:n/2,1),2);
H(n/2+2:end,m/2+1) = rot90(H(2:n/2,m/2+1),2);
phi(1,1) = 0;
phi(1,m/2+1) = 0;
phi(n/2+1,m/2+1) = 0;
phi(n/2+1,1) = 0;
phi(2:end,2:m/2) = -rot90(phi(2:end,m/2+2:end),2);
phi(1,2:m/2) = -rot90(phi(1,m/2+2:end),2);
phi(n/2+2:end,1) = -rot90(phi(2:n/2,1),2);
phi(n/2+2:end,m/2+1)= -rot90(phi(2:n/2,m/2+1),2);
% Convert to polar
[a,b] = pol2cart(phi,H);
H_complex = complex(a,b);
% Inverse and plot
S = ifft2(H_complex, 'symmetric') ;
surf(S)

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

추가 답변 (1개)

Thomas Koelen
Thomas Koelen 2015년 5월 20일
use abs() or real()? depending on if you want only the real number or the absolute value.
  댓글 수: 1
Mona Mahboob Kanafi
Mona Mahboob Kanafi 2015년 5월 20일
편집: Mona Mahboob Kanafi 2015년 5월 20일
Thanks Thomas, I need the output to be real based on a solid theory. Since, from the beginning, I have to define the absolute values of the fft so that it gives a surface with specified standard deviation (root mean square roughness). Real values, don't have the same std and absolute values have the same std, but not a correct shape! Absolute values are only positive while my surface must have a zero mean. This is not an option for me at the moment.

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

Community Treasure Hunt

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

Start Hunting!

Translated by