Getting Close with Matlab FFT for Fourier Transform Table Reconstruction

Click For Summary

Discussion Overview

The discussion revolves around using Matlab's FFT functionality to reconstruct Fourier transform tables, specifically addressing issues related to frequency resolution, normalization of amplitudes, and the relationship between discrete Fourier transforms (DFT) and continuous Fourier transforms (FT).

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant shares code for taking the Fourier transform of a cosine function but encounters issues with the frequency domain representation and amplitude scaling.
  • Another participant points out that the frequency resolution is determined by the length of the original signal and the sample rate, suggesting adjustments to the frequency range calculation.
  • Some participants emphasize the importance of not hard-coding values and using intuitive variable names for clarity in coding.
  • There is a discussion about the expected amplitude of the impulses in the Fourier transform, with one participant noting that they expect the amplitudes to be 1/2, while they are obtaining 5 instead.
  • Normalization of the FFT output is debated, with participants suggesting that it should be normalized by the length of the signal and discussing different conventions for normalization.
  • Some participants express uncertainty about the internal workings of the FFT and the implications of different normalization approaches, indicating that there is no single convention for this process.
  • One participant suggests that understanding the physics behind the FFT is crucial for proper implementation and normalization.
  • A later reply discusses the relationship between DFT and FT, noting that the DFT should scale by the sampling interval T to match the FT.

Areas of Agreement / Disagreement

Participants generally agree on the need for proper normalization and the importance of understanding the relationship between DFT and FT. However, there are multiple competing views regarding the normalization conventions and the implications of different approaches to implementing the FFT.

Contextual Notes

There are unresolved questions regarding the specific normalization methods and their dependence on the definitions used in different contexts. The discussion also highlights the need for clarity in variable definitions and the implications of sampling rates on frequency resolution.

PhDorBust
Messages
141
Reaction score
0
I'm attempting to use Matlab fft functionality to reconstruct Fourier transform tables in my textbook (brigham), but to little success.

Here is code to take the Fourier transform of cos(2*\pi*x*f_0), which should be \frac{\delta (f + f_0) + \delta (f - f_0)}{2}

I can *almost* get it, but not quite. See spikes at +/- .001, when should be at +/- .1 Any help would be appreciated.

Code:
 x = 0:.1:9.9;
%N=100, T=10
 y = cos(x*2*pi/10);
 Y = fft(y);

X = (0:99)/1000 - 50/1000;
Y = fftshift(Y);
plot(X,real(Y));

Using H \left( \frac{n}{NT} \right) = \sum_{k=0}^{N-1} h(kT) e^{-i2\pi n k / N} for n = 0, ..., N - 1.
 
Physics news on Phys.org
you defined X arbitrarily. Your frequency resolution is set by the length of your original signal (x), and your sample rate (fs), which is of course, 1/dx (dx being the "period" of each sample).

Your frequency range is set by the nyquist frequency, which is half the sampling rate.

So try this:

Code:
dx = .1;
 x = 0:dx:9.9;

fs = 1/dx;

 y = cos(x*2*pi/10);
 Y = fft(y);

X = -fs/2 : fs/length(x)  : fs/2 - fs/length(x)
Y = fftshift(Y);
plot(X,real(Y));
 
You're correct, I wasn't setting the frequency domain properly. I.e. T is .1, not 10.. Thank you.

Also, that is nicer notation.
 
Ah, yes, I see your range vector was actually quite intended for something.

A good sci/eng coding philosophy is to try to not hard-code numbers; try to use lots of intuitive, explanatory variable names so you can keep track of what's going on.
 
Question 2: The amplitudes of the impulses should be 1/2.

For band-limited, periodic functions such as cosine, the exact Fourier transform should be given by multiplying the DFT by T (the sampling interval). But I always get 5 for amplitudes, when I want .5...
 
yeah, we should normalize by the length of the signal from which the fft is taken (which should be the length of fft too, as long as you don't designate that. It's best not too, you can pad with zeros yourself (and always should to make your vectors of length 2^n for efficiency.)

Code:
dx = .1;
 x = 0:dx:9.9;

fs = 1/dx;
F1 = .1;
F2 = .2;
 y = cos(x*2*pi*F1);
 Y = fft(y);

X = -fs/2 : fs/length(y)  : fs/2 - fs/length(y)
Y = fftshift(Y);
[B]plot(X,real(Y)/length(y));[/B]
 
Pythagorean said:
yeah, we should normalize by the length of the signal from which the fft is taken (which should be the length of fft too, as long as you don't designate that. It's best not too, you can pad with zeros yourself (and always should to make your vectors of length 2^n for efficiency.)

Code:
dx = .1;
 x = 0:dx:9.9;

fs = 1/dx;
F1 = .1;
F2 = .2;
 y = cos(x*2*pi*F1);
 Y = fft(y);

X = -fs/2 : fs/length(y)  : fs/2 - fs/length(y)
Y = fftshift(Y);
[B]plot(X,real(Y)/length(y));[/B]

The way you are doing it appears to be correct. But my textbook (brigham) says "If we desire to compute the Fourier transform by means of the discrete Fourier transform, it is necessary to multiply the discrete time function by the factor T", where T is the sampling interval (dx in your code). This is true for band-limited periodic functions.

See http://en.wikipedia.org/wiki/Relati...eries#DFT_versus_continuous_Fourier_transform
 
Last edited:
depending how you do the transform internally, you have to normalize it externally. There's not really a single convention for how to do this.

Your book is probably correct in their treatment, but that's a different treatment than matlab's.
 
Pythagorean said:
depending how you do the transform internally, you have to normalize it externally. There's not really a single convention for how to do this.

Your book is probably correct in their treatment, but that's a different treatment than matlab's.

Not sure what you mean by internally. My text, matlab, and wikipedia all use DFT convention H_n = \sum_{k=0}^{N-1} h(kT) e^{-i 2 \pi n k / N}. Where T is sampling interval and N is number of points sampled.
 
  • #10
Not sure what you mean by internally.

If you're just starting programming, then you probably can't appreciate that going form theory to code isn't always as straightforward as you'd think. There's lots of different ways to do things and a lot of different things that customers want out of a function/program.

If you want to be sure how your fft works, write one yourself. Don't use matlab's.

If you want a more in-depth discussion on fft normalization conventions:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/152029

Remember that the fft is NOT inherently physical. YOU have to implement the physics. It can be normalized differently depending on the question you're asking. But in order to do that, you have to know what the results mean when they come out of the function that you're using so that you can normalize to your physical system.
 
  • #11
Pythagorean said:
If you're just starting programming, then you probably can't appreciate that going form theory to code isn't always as straightforward as you'd think. There's lots of different ways to do things and a lot of different things that customers want out of a function/program.

If you want to be sure how your fft works, write one yourself. Don't use matlab's.

If you want a more in-depth discussion on fft normalization conventions:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/152029

Remember that the fft is NOT inherently physical. YOU have to implement the physics. It can be normalized differently depending on the question you're asking. But in order to do that, you have to know what the results mean when they come out of the function that you're using so that you can normalize to your physical system.

If you say so, but all the Cooley-Tukey in FFT does is evaluate the sum I wrote out in a speedy way. I'm not really normalizing... just want to match the DFT result to FT which should be scaling by T (see wiki link I posted).
 
  • #12
See attached picture.

When taking the DFT, why do we have to take the time waveform to be (b) rather than (a)?
 

Attachments

  • question.png
    question.png
    4.9 KB · Views: 586
  • #13
just want to match the DFT result to FT which should be scaling by T (see wiki link I posted).

Your wiki link says that DFT = (1/T)*FT. You want DFT to look like FT, so you solve for FT:

FT = T*DFT

For a discrete n sec. signal, the sampling rate T is inversely proportional to the N, the number of samples. (n = T*N)

so T ~ 1/N
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 0 ·
Replies
0
Views
2K