0

I have a relatively clean sine signal (from thin-film interference) - two data vectors:X-axis (difference in optical path length) and Y-axis (illuminate). I want to find the sine's frequency using Fourier transform (in matlab). How do I do that?

thanks!

Gal
  • 1
  • 1
  • 1
  • 3
    I suggest that you read [this article](http://www.mathworks.com/help/matlab/math/fast-fourier-transform-fft.html) and look at [these examples](http://www.mathworks.com/help/matlab/examples/using-fft.html) from The MathWorks, as well as the documentation for [`fft`](http://www.mathworks.com/help/matlab/ref/fft.html). Then you might look at this StackOverflow question: [Understanding Matlab FFT example](http://stackoverflow.com/questions/10758315/understanding-matlab-fft-example). – horchler Oct 26 '13 at 20:37

1 Answers1

-1

Firts do you need to use one Window (hamming, hann) in your Signal and now all that you need is get the maximun value from first half Magnitude squared DATA, to find the Frequency calculate "sample rate * maximun index / length DATA:

t  = [ 0 : 1 : 100000];          
f  = 200;        % F0 here           
Fs = 44100;                    
data = sin(2*pi*f/Fs*t)';  
data = data .* hanning(length(data));    
Y = fft(data);    
Mag=abs(Y(1:length(data)/2)).^2;    
[a,b]=max(Mag);    
% Result    
Fs*b/length(data)
ederwander
  • 3,410
  • 1
  • 18
  • 23
  • Note, this will present a frequency of accuracy `\pm Fs/length(data)`, which can suck if `Fs` isn't very large – Anti Earth Jul 11 '16 at 05:02
  • how large is window processed by the FFT better, everyone knows that this method is not accurate, the question does not say how accurate the algorithm needs to be – ederwander Jul 11 '16 at 05:11
  • Do you have any insight on whether you'll need to subtract `1` from `b` in the result? I.e. the result is actually `Fs*(b-1)/length(data)`? I would have thought otherwise since you find the max index *after* you chop out the first point, but my own testing is showing `-1` is required. (see here: https://codeshare.io/q9wDH) – Anti Earth Jul 11 '16 at 05:28
  • 1
    yeah matlab indexes start in `1` and not `0` so the correct bin from FFT in matlab can be `max index-1` – ederwander Jul 11 '16 at 05:45