Understanding the FFT: Basic Question (MATLAB)

In summary: However, there is no trailing zeros in the code I linked. Thanks for the question!In summary, the FFT of 101 data points is doing the FFT of the periodic time series. The first lines of code define an array with length 101, and creates 101 data values with a 1 at both ends. Then it does the fft using 101 points. Up to that point, there isn't any padding.
  • #1
O.J.
199
0
Hello,

I have a very basic FFT question. Correct me if I am wrong, but the FFT is a fast implementation of the DFT (which is essentially the same as Discrete Time Fourier series). The DFT is periodic in time and frequency. Thus if you input a time domain made of 4 times samples for example to the FFT block, it will give u a frequency spectrum 4 point output. Both these, the input and output are considered periodic. Also, doesn't the FFT treat its input as periodic?
Shouldnt a cosine input to our FFT block (as long as its sampled above the nyquist) always give us two impulses (since its periodic)? Why can't we get those two impulses?

and if so, then why does this document (and my experiemental results) contradict this:
Read page 15.
http://www.ee.nmt.edu/~elosery/matlab/matlab.pdf
 
Physics news on Phys.org
  • #2
O.J. said:
Hello,

I have a very basic FFT question. Correct me if I am wrong, but the FFT is a fast implementation of the DFT (which is essentially the same as Discrete Time Fourier series). The DFT is periodic in time and frequency. Thus if you input a time domain made of 4 times samples for example to the FFT block, it will give u a frequency spectrum 4 point output. Both these, the input and output are considered periodic. Also, doesn't the FFT treat its input as periodic?
Shouldnt a cosine input to our FFT block (as long as its sampled above the nyquist) always give us two impulses (since its periodic)?

That is correct.

Why can't we get those two impulses?

and if so, then why does this document (and my experiemental results) contradict this:
Read page 15.
http://www.ee.nmt.edu/~elosery/matlab/matlab.pdf

Start at section 7.3 on page 13. The problem is that the code defines a sine wave with 100 samples per period, but it creates an array with 101 samples.

That looks nice plotted in the time domain (Fig 9), because the X axis goes from 0 to 1 exactly.

The FFT of 101 data points is doing the FFT of the periodic time series

1, [99 points defining the cosine wave], 1, 1, [99 points repeated], 1, 1, etc

But the correct time series to represent the cosine wave is

1 [99 points], 1, [99 points], 1, etc

If you do the FFT with 100 points you should get what you expected, i.e. all the FFT coefficients except two will be 0 (to within rounding error).

Note, for "real world" measured data, the signal frequencies will not usually be exact multiples of the sample length. The practical way to clean up the FFT is to use a windowing function on the data - but I think your reference is meant to be a cheat sheet on using Matlab, not a course on practical DSP.
 
  • #3
Thanks alpha zero. That cleared up many things. Can you tell me what it mathematically means to use an FFT with a length more than the time domain signal length?
 
  • #4
Also, can you elaborate more on the role of windowing? Does having an FFT with N greater than signal length count as effectively windowing?
 
  • #5
This tutorial might be useful as an introduction to the concepts - plenty of graphs, but not much math.

http://www.bores.com/courses/intro/freq/index.htm

Any textbook on DSP will have the math, if you need that as well, but if you are using Matlab then understanding how the pieces of the jigsaw fit together is arguably just as important as knowing the mathematical details of each individual piece.
 
  • #6
Also another question. You said: "The FFT of 101 data points is doing the FFT of the periodic time series

1, [99 points defining the cosine wave], 1, 1, [99 points repeated], 1, 1, etc"

But doesn't taking a larger point FFT mean padding the input with trailing zeros? Your input seems padded with 1's. Am I right?
 
  • #7
O.J. said:
Also another question. You said: "The FFT of 101 data points is doing the FFT of the periodic time series

1, [99 points defining the cosine wave], 1, 1, [99 points repeated], 1, 1, etc"

But doesn't taking a larger point FFT mean padding the input with trailing zeros? Your input seems padded with 1's. Am I right?

I was talking about the first lines of code in section 7.3 on page 13 of the PDF, which defines an array of length 101, and creates 101 data values with a 1 at both ends. Then it does the fft using 101 points. Up to that point, there isn't any padding.

(Disclaimer - I haven't actually run the code in Matlab, but that's what I think it does).

You are right that if an array is padded, then it is padded with zeros.
 

1. What is the FFT function in MATLAB?

The FFT function in MATLAB stands for Fast Fourier Transform, which is a mathematical algorithm used to convert a time-domain signal into its corresponding frequency-domain representation.

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 data in the time-domain. Then, you can simply use the command "fft(x)" where x is your signal, to obtain its frequency-domain representation.

3. What are the inputs and outputs of the FFT function in MATLAB?

The input of the FFT function in MATLAB is a time-domain signal, while the output is its corresponding frequency-domain representation. The output is also a complex array, with the first half representing the positive frequencies and the second half representing the negative frequencies.

4. Can I plot the FFT result in MATLAB?

Yes, you can plot the FFT result in MATLAB using the command "plot(abs(fft(x)))" where x is your signal. This will plot the magnitude of the FFT result against the frequency bins.

5. What are some applications of the FFT function in MATLAB?

The FFT function in MATLAB is commonly used in signal processing and analysis, such as in audio and image processing. It is also used in various scientific and engineering fields for data analysis and visualization.

Similar threads

Replies
6
Views
972
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Electrical Engineering
Replies
4
Views
820
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
13K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
4K
Back
Top