FFT not matching with Continuous FT
31 views (last 30 days)
The fourier transform of a unit amplitude cosine with period T is two delta functions, at -1/T and +1/T with amplitude 1/2.
dx = .1;
x = 0:dx:9.9;
fs = 1/dx;
y = cos(x*2*pi/10);
Y = dx*fft(y); %Continous FT and DFT differ by scale dx
X = -fs/2 : fs/length(x) : fs/2 - fs/length(x)
Y = fftshift(Y);
The amplitudes of my deltas is 5 and not .5. Why? I've scaled by the appropriate constant..
Again, using dx as the scale factor is perfectly valid and correct. The results you are seeing in practice do in fact match the theory. Remember, the theory says you should see an impulse of size 1/2 at +Fc and -Fc. What is the height of an impulse of size 1/2? It is not 1/2. The height of an impulse is infinite. The area of the impulse is 1/2, not the height of the impulse.
What you are seeing is two discrete impulses of height 5. What is the width of those impulses? I would argue that the width (the frequency increment or distance between each of the discrete frequencies) of each impulse is 0.1 hertz, so that the area of the impulses is 1/2, as expected.
Does that make sense?
More Answers (5)
You have scaled by the appropriate constant for the Continuous Time Fourier Transform (CTFT), but the fft function computes the Discrete Fourier Transform (DFT). The appropriate scaling factor for the DFT is the number of samples N, not the time increment dx.
N = size(y,2);
Y = fftshift(fft(y))/N;
Technically speaking, it is not a question of whether one scale factor is "correct" and the other "incorrect". The issue is really that both scaling factors are correct, but they are providing two different ways of looking at the same result. In effect, each of two scaling factors provides in the same exact Fourier spectrum, but in different units of measure. It is really a question of what you want to see and for what purpose. The choice of scaling factor is just that: a choice. You need to choose the right scaling factor for the right reason.
BTW, these two scaling factors are not the only ones. You can also choose not to scale the result at all, or you can convert the spectrum from an linear scale to a logarithmic scale (in the form of decibels). And there are still others as well.
Ultimately, the scaling factor of the spectrum is really quite unimportant for most applications. In general, it is the overall shape of the spectrum that matters, not the absolute scale.
One other thing I noticed in the code you posted: When you plot the spectrum, you should plot the magnitude of the Fourier coefficients, not the real-part of the coefficients.
So, instead of
In this particular example, it may not make any difference, but in general, it will.