# How to get dominent frequency from intensity along a curve in an image?

7 views (last 30 days)
Steven on 27 Jan 2014
Edited: Steven on 26 Apr 2016
I want to find the dominant frequency. I used fft in this way
yf3 = fftshift(fft2(intensity_profile));
and I got, again for example, this:
First, is it correct? I do not know hot to get the dominant frequency? For now I have plotted the intensity distribution along the circle points. How can I plot it against the frequency?
What I want finally is the main frequency and then wavelength of the profile.
Thanks so much.
Steven

Walter Roberson on 27 Jan 2014
It appears to be plausible. Your dominant frequency is 0, the DC component.
To get a better idea, you might want to subtract off the mean from the data before fft'ing it.
Note: I would have expected fft() instead of fft2(). Perhaps I am misreading the profile.

Show 1 older comment
Walter Roberson on 27 Jan 2014
See the example in http://www.mathworks.com/help/matlab/ref/fft.html for converting timepoints to frequency. Notice that you need to know the sampling frequency (or, alternately, the angular frequency) -- the distance between samples. The distance between samples must be consistent for fft() or fft2() to be meaningful -- if they are not equally spaced then you would need to use a NFFT, Non-Uniform FFT; see http://www.mathworks.com/matlabcentral/answers/104858
Note: if you are finding your points by converting cartesian coordinates for pixels, then you will not have equidistant points.
Steven on 28 Jan 2014
Thanks! I am using cartesian coordinates for pixels, But what do you mean by converting cartesian coordinates?
Sorry for such a trivial question, but how do I get the frequency from x or y values? I do not have time scales here, right? I have just x and y values of the pixels and their corresponding gray scale.
Thanks!
Steven
Walter Roberson on 29 Jan 2014
cart2pol() converts (x,y) to (theta, r). If you get the ordering wrong, you can sort() the two based upon theta. Then if you diff() the theta you will see that they have not been uniformly sampled. You should be using a Non-Uniform FFT to handle that situation.
But... instead you can cheat some.
Suppose you have the N x 3 array xyv where the first column is x, the second y, the third the associated value. Then
[theta, r] = cart2pol(xyv(:,1), xyv(:,2));
min_theta = min(theta);
max_theta = max(theta);
even_theta = linspace(min(theta), max(theta), length(theta));
[sort_theta, sortidx] = sort(theta);
ordered_v = xyv(sortidx, 3);
even_v = interp1(sort_theta, ordered_v, even_theta);
centered_even_v = evan_v = mean(evan_v);
Now you can
v_fft = fft(centered_even_v);
In this, the (linear) interpolation of (hopefully nearby) points should fudge for the theta not originally being evenly distributed. The subtraction of the mean is to avoid the big spike in the first bin of the fft.
The first output bin would be the DC component, the mean times the number of points -- which should be 0 if you used centered_even_v as the mean was already subtracted off.
The second output bin would be one cycle per period (2*Pi radians), the third output bin would be two cycles per period, the fourth would be three cycles per period, and so on to the centre, the N'th bin being (N-1) cycles per period.