2

From the question: How do I obtain the frequencies of each value in an FFT?

I have a similar question. I understand the answers to the previous question, but I would like further clarification on frequency. Is frequency the same as the index?

Let's go for an example: let's assume we have an array (1X200) of data in MATLAB. When you apply 'abs(fft)' for that array it gives the same size array as the result (1X200). So, does this mean this array contains magnitude? Does this mean the indices of these magnitudes are the frequencies? Like 1, 2, 3, 4...200? Or, if this assumption is wrong, please tell me how to find the frequency from the magnitude.

Community
  • 1
  • 1
Naga sandeep
  • 102
  • 1
  • 1
  • 8

1 Answers1

1

Instead of using the FFT directly you can use MATLAB's periodogram function, which takes care of a lot of the housekeeping for you, and which will plot the X (frequency axis) correctly if you supply the sample rate. See e.g. this answer.

For clarification though, the index of the FFT corresponds to frequency, and the magnitude of the complex value at each frequency (index) tells you the amplitude of the signal at that frequency.

Community
  • 1
  • 1
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • hi Paul. i have one more doubt.i don`t know my sampling frequency. because i got this(1X200) array from image. its pixel 'y' coordinate values. my task is to find the the wavelength for this data through frequency. so, i did fft for that array i got magnitude values. and for wavelengths i need to inverse the frequencies.so, it means is i need to inverse the index values?? if indexes are the frequencies then what is its unit (Hz, or KHz). please help me, i got strucked here. Thankyou. if u not understand my question please tell me, so that i can explain u clearly. – Naga sandeep Jan 12 '12 at 14:29
  • @nagasandeep: you can't calculate frequencies unless you know the sample rate - you can get relative frequencies only (relative to the reciprocal of the length of the sample window) but without kmowing the sample rate you can not calculate absolute frequencies. Don't you know the scale of the X axis ? – Paul R Jan 12 '12 at 14:45
  • hi, bro.i am really sorry, yes i am understanding what u are saying. normally its Hz only. but i want to clarify it perfectly. because when we go to wavelength plot i have to show the length in units. so that's why i asked about it. and one more thing is, as said here [1](http://stackoverflow.com/questions/4364823/how-to-get-frequency-from-fft-result) second bin (first bin is dc value) of fft data will give **FS/N**, so by using this can we find anything. i just know the number of samples only. – Naga sandeep Jan 12 '12 at 15:01
  • You need both Fs (the sample rate) and N (the number of FFT bins). If you don't know Fs then you can't calculate the absolute frequency. What is the scale of your X axis ? Is it measured in time ? If so then you can calculate the sample rate. – Paul R Jan 12 '12 at 15:05
  • my X axis is just index of that array(1X200). because my data is not from time domain. its from a image(pixels 'y' coordinate data). bro, i feel u are the only one person can help. please help me. Thankyou. or can we assume sampling rate(Fs). – Naga sandeep Jan 12 '12 at 15:56
  • Can you explain more about this image - you say it is 1x200 - what sort of image is this ? – Paul R Jan 12 '12 at 16:43
  • i have a binary image with two lines. here in this the upper line varies for each frame. ![This is the image][1] i was taken distance between these two lines(difference of 'Y coordinates'). so, now i got an array of (196X1). in this array we have difference of each pixel in upper line and lower line 'y' coordinate value. my task is to find the wavelengths of this array through frequency domain. so, i did 'abs(fft)' for this array. i got magnitude values. then their index are relative frequencies as you said. – Naga sandeep Jan 12 '12 at 17:09
  • but my doubt is with out absolute frequencies i can`t get their wavelength. but i need Fs as you said before. here i struck. image link [http://imageshack.us/photo/my-images/707/offsetimg46.png/] – Naga sandeep Jan 12 '12 at 17:10
  • OK - I guess we need to back a step and ask where these two lines came from, i.e. what is their physical significance ? It looks like there's a fundamental component which is approximately equal to the length of the diagonal, which would be a *spatial* frequency of 1 / 200, but to convert this to anything with physical significance we need to know more about how the lines were generated. – Paul R Jan 12 '12 at 17:26
  • in that two line upper one is the edge of a paper and second one is the line we created for making difference(second line is common for all frames but upper one varies). yes you are right we need to analyse spatial wavelengths. so for that we need spatial frequencies. i am on doing this way....so, what this spacial frequencies how we can get them ..can you please tell me. i know theatrically, but when i come to find them in matlab, i am facing problems like this. – Naga sandeep Jan 12 '12 at 17:31
  • OK - in that case you can just say that the spatial frequency of the first bin is 1 / N, where N = 200, i.e. 0.05, and the second bin is 2 / N = 2 / 200 = 0.1, etc. – Paul R Jan 12 '12 at 17:33
  • hey, i am sorry, last time i mentioned wrongly the rows and columns....so now the array size is 196X1. so it means spatial frequency for first bin is 1/196. is it right ??? – Naga sandeep Jan 12 '12 at 17:36
  • Spatial wavelength is the reciprocal of spatial frequency – Paul R Jan 12 '12 at 17:37
  • yes...yes...you are right. but i am confused a bit...about ur above comment, ie, u already did inverse and you said its spatial frequency. can you please clarify that.?? – Naga sandeep Jan 12 '12 at 17:41
  • Dividing by N is to get the spatial frequency from the FFT bins (0, 1/N, 2/N, 3/N, etc). To get wavelength from frequency you need to take the reciprocal of the frequency (INF, N, N/2, N/3, etc). – Paul R Jan 12 '12 at 17:47
  • 1
    bro.......u did it....awesome... i got it. thank you bro. you helped me aloooot. i ll never forgot u bro. u rocks. tnq tnq bro. tnq – Naga sandeep Jan 12 '12 at 17:54