Basic question on the FFT in matlab

In summary, you can use the FFT to plot the frequency contributions of a function in time. However, if the ends of your samples don't match up, discontinuities will appear as high-frequency garbage on your plot. To window your samples so they go to zero at both ends, you can look up the Hamming window.
  • #1
O.J.
199
0

Homework Statement



From what I understand, the array output of the FFT of a function in time represents the frequency contributions of different frequencies with the first output coming from 0 freqeuncy, 2nf from the 1st fundamental frequency and so on.. if so, then why does this code(which is for plotting the fft against frequency) give contributions from various frequencies to the cosine function when we learned in Fourier theory that the only frequency contributiong to a sinusoid are those of its own frequency:
t = -20:20;
x= cos (6*pi*t/13+pi/3);
y = fft(x);
tn = (-length(y)+1)/2 : (length(y)-1)/2;
stem (tn, y);


Homework Equations





The Attempt at a Solution

 
Physics news on Phys.org
  • #2
O.J. said:

Homework Statement



From what I understand, the array output of the FFT of a function in time represents the frequency contributions of different frequencies with the first output coming from 0 freqeuncy, 2nf from the 1st fundamental frequency and so on.. if so, then why does this code(which is for plotting the fft against frequency) give contributions from various frequencies to the cosine function when we learned in Fourier theory that the only frequency contributiong to a sinusoid are those of its own frequency:
t = -20:20;
x= cos (6*pi*t/13+pi/3);
y = fft(x);
tn = (-length(y)+1)/2 : (length(y)-1)/2;
stem (tn, y);


Homework Equations





The Attempt at a Solution


Howdy!

How many cycles does a regular sinusoid have? In contrast, how long is yours?
 
  • #3
sup!
well, a regular sinusoid has... infinitely many cycles. and mine has almost 3 cycles in that range of t.
 
  • #4
Ok, after playing with it, I see what you're saying, the larger the range of t, the closer it is to the real thing (although I don't see why). but, how to relate the values on the x-axis to frequency?
 
  • #5
O.J. said:
Ok, after playing with it, I see what you're saying, the larger the range of t, the closer it is to the real thing (although I don't see why). but, how to relate the values on the x-axis to frequency?

Precisely! When you're doing a Fourier Transform, you're breaking down your function and trying to represent it using sinusoids of infinite duration. Since you only have a small snippet of a sinusoid, you need a bunch of sinusoids to add together so that you get the sinusoid segment, and 0 everywhere else. And of course, the longer your snippet, the closer it is to an infinite-duration sinusoid, and the higher its frequency purity (i.e. the power of the signal comes almost entirely from its fundamental frequency, and none of the higher ones).

Regarding your second question, if you know the period T (which you can read off of the graph), then you just take 1/T as the frequency (this assumes that you're not working in degrees, or radian frequency):
http://en.wikipedia.org/wiki/Frequency

What blew my mind--this finite duration of sinusoid snippets and their spectral purity--is that this seemingly mathematical quirk actually has ramifications in physics, especially in regards to the coherence length of light, and why there's always some spectral width in any light source.
 
  • #6
Any one could help me with , numerical Fourier transform of bessel's function using FFT in C language
 
  • #7
also anyone could help me with,invistigate of bessel'e equation using runge-kutta
 
  • #8
Welcome to Physicsforums, Nada!

In the future, please make a new thread for a topic unrelated to the one at hand. I'm not a computer modeling guy, but you might be able to find something in the book Numerical Recipes in C, probably available in your library (you can also probably find a cheap used copy):
http://www.nr.com/
 
  • #9
OJ,

Making your sample size bigger increases your resolution. In other words, with more samples, you can resolve smaller details on the plot.

The real problem you're having is that your sample is a non-integer number of wavelengths. The FFT acts on your input as if it were copied end-to-end for all time, so its beginning and end better match up. If the ends do not match up, the discontinuity will appear as high-frequency garbage, which will ruin your plot.

What you need to do is window your samples, so that they go to zero at both ends. Then you can safely use the FFT. Look up the Hamming window, for example:

http://en.wikipedia.org/wiki/Hamming_window#Hamming_window_.5Bnote_1.5D]Hamming window

- Warren
 
  • #10
hello

--------------------------------------------------------------------------------

could you please help me with
numerical solution by runge-kutta for bessel's equation with C
Also
how i can write programme to compute the series(bessel function) Jn(x) for n=0.1,4 for range of x with C
also numerical Fourier transfom of bessel function using FFT with C too

I would be so grateful if you could if not how can I ask by this website
 

1. What is the FFT in Matlab?

The FFT (Fast Fourier Transform) in Matlab is a mathematical algorithm used to quickly calculate the discrete Fourier transform of a sequence or signal. It is commonly used in signal processing and data analysis to convert a signal from its original domain (usually time or space) to a representation in the frequency domain.

2. How do I use the FFT function in Matlab?

To use the FFT function in Matlab, you first need to have a signal or sequence stored in a vector. Then, you can simply call the fft() function and pass in the vector as an argument. The function will return the discrete Fourier transform of the vector as a complex-valued vector.

3. What is the difference between FFT and DFT?

The FFT (Fast Fourier Transform) and DFT (Discrete Fourier Transform) are both mathematical algorithms used to calculate the discrete Fourier transform of a sequence or signal. The main difference between them is that the FFT is a more efficient version of the DFT, as it uses certain properties of the DFT to reduce the number of calculations needed.

4. Can I perform the FFT on non-numeric data in Matlab?

No, the FFT function in Matlab can only be applied to numeric data. If you have non-numeric data, you will need to convert it to a numeric format before using the FFT function.

5. How can I visualize the results of the FFT in Matlab?

To visualize the results of the FFT in Matlab, you can use the plot() function to plot the magnitude or phase of the complex-valued vector returned by the FFT function. You can also use the fftshift() function to shift the zero-frequency component to the center of the plot and make it easier to interpret the results.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
4K
  • Differential Equations
Replies
11
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top