complex output of the inverse fourier transform

10 views (last 30 days)
Hello, I have written a simple algorithm that applies a fourier transform on an image X to get F as a result. Then I have inversed F and I got a complex output Y. I did not use the predefined functions fft and ifft. Is it logical to get complex output? could you help me to fix the problem in this code
X=imread('test.png');
[N,N]=size(I);
F=zeros(N,N);
for k=1:N,
for n=1:N
F(:,k)=F(:,k)+X(:,n)*exp(2*pi*(1i)*(n-1)*(k-1)/N);
end
end
y=zeros(N,N);
for n=1:N,
for k=1:N,
y(:,n)=y(:,n)+F(:,k)*exp(-2*pi*(1i)*(n-1)*(k-1)/N);
end
end
y=y/N;
  1 Comment
Pragya singh
Pragya singh on 26 Aug 2019
if x is real then you should get back real output.
Maybe the problem lies in calling positive and negative frequency.
x=\summation X(k+) +\summation X(k-)
so if you look into this then all you need for real value is that the complex part of positive and negative frequencies cancel each other (which might not be happening in your case)

Sign in to comment.

Answers (1)

Matt J
Matt J on 9 Dec 2013
If the imaginary components are small, it's probably just floating point noise. Use real() to discard it.
  6 Comments
ines
ines on 22 Dec 2013
I want to use fft because it is faster and the inversion is more precise. The reconstructed image is approximative to the original image.
Matt J
Matt J on 22 Dec 2013
Edited: Matt J on 22 Dec 2013
If X is real, then conj(fft(X)) is also equivalent to flipping the exponential sign. If X is not real, then conj(fft(conj(X))) is needed.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!