FFT not working on periodic data!?!?!?
Show older comments
Hello,
I have data which, when visualized,, displays some very periodic behavior (picture a 2D sine wave). However, when I call the fft2() function on my matrix I only get the zero-frequency bin to be non-zero. I would have expected the very clear periodicity in my data to become clear in the FFT, but it seems that somewhere something's going wrong!
Any ideas, including common mistakes or misunderstandings with fft2 or FFTs in general?
Actually, it's quite weird that, regardless of my data, I only get the zero-frequency bin lighting up in the fft!!
code: (msum2 is my real data)
zMapT2=fftshift(fft2(msum2));
zMapAbs=abs(zMapT2);
imagesc(zMapAbs);
so I'd expect to see some bins lighting up away from the origin, but everything's blue except for the red at the center.
3 Comments
Rick Rosson
on 13 Sep 2014
Please post your code.
Rick Rosson
on 13 Sep 2014
Edited: Rick Rosson
on 13 Sep 2014
Please type the following at the command prompt:
mean(msum2(:))
min(msum2(:))
max(msum2(:))
size(msum2)
class(msum2)
What is the value of each of these expressions?
Bruce
on 13 Sep 2014
mean:23.4562
min:21.5823
max:27.5662
size:256 256
class:double
Answers (2)
Image Analyst
on 13 Sep 2014
0 votes
See my attached demo.
Can't really say much about your code since you didn't post it all. It might be that you have the signal on a big offset, like the signal is all positive, so that there is a huge DC (zero frequency) term which is so much bigger than your spikes due to your periodic component that you can't see the spikes due to the periodic part. You might try taking the log of your data before you pass it to imshow() or imagesc().
3 Comments
Image Analyst
on 13 Sep 2014
It could also be that your colormap is such that it hides your spikes. Try using
colormap(gray(256));
instead of the weird colormap that imagesc() uses.
Bruce
on 13 Sep 2014
Thanks for your ideas. I tried changing the figure colormap as instructed, but now I just get one white center dot in a sea of black. I also tried doing decibel scaling, to no avail!
msum3=10*log10(max(1,msum2));
proceeded as before, still one lone dot!
See my comment to Rick above - my data doesn't seem that wildly varied, and it doesn't have a huge spike somewhere (right?). So confused - seems so straightforward, can't think of why this particular data set is having issues.
Image Analyst
on 14 Sep 2014
Unless you post your actual data I don't know how much more help we can give.
Rick Rosson
on 14 Sep 2014
Please try converting the source data to zero mean before taking the FFT:
mu = mean(msum2(:));
msum2 = msum2 - mu;
That will eliminate the DC component, and it should reveal the periodic components in the Fourier domain.
5 Comments
Bruce
on 16 Sep 2014
This did it! Thank you Rick! I'll have to do more research to understand why this worked.
Bruce
on 16 Sep 2014
Can't find a way to accept your answer though...
Image Analyst
on 16 Sep 2014
It looks like you didn't take the log correctly when you tried to take my suggestion. You took the log of the time or spatial domain instead of the Fourier/spectral domain. Anyway, done correctly, taking the log before plotting/displaying will compress the DC spike and give the little spikes a chance to be seen. Of course if you don't want the complete spectrum and want only the little periodic spikes, then just get rid of the DC spike by subtracting the mean like Rick suggested.
Bruce
on 16 Sep 2014
I see. I'll try what you said again, thank Analyst!
Categories
Find more on Discrete Fourier and Cosine Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!