Clear Filters
Clear Filters

I have a question on usage for fft to get fourier series back.

1 view (last 30 days)
My problem is
f = 1 + 2*sin(2.*pi*t/L) + 3.*sin(4*pi*t/L);
L = 1,
and I am dividing the peiod to 100 steps. Here is the program I use
L = 1;
Nsamples = 100;
t = linspace(0,L,Nsamples);
f = 1 + 2*sin(2.*pi*t/L)+ 3*sin(4*pi*t/L);
FF = fft(f);
NHarmonics = 3;
FFMag = abs(FF(1:NHarmonics))/Nsamples;
FFAngle = angle(FF(1:NHarmonics))*180/pi;
I expected FFMag to be 1, 2 and 3 the first three coefficients (a0, a1, and a2 of fourier series)
However, I am getting 1, 1, and 1.5 as the coefficients. they are half of the values of a1 and a2. a0 is correctly computed. I am sure i made a dumb error here but I can't figure it out. Please help and thanks in advance.

Accepted Answer

dpb
dpb on 22 Sep 2018
Edited: dpb on 22 Sep 2018
FFT returns the two-sided DFT so half the energy is in each of +ive and -ive frequencies. However, there is only one DC component so, therefore the a0 magnitude is as expected and a1, a2 are half.
...
FFMag = abs(FF(1:NHarmonics))/Nsamples;
FFMag(2:end)=2*FFMag(2:end); % magnitude for 1-sided transform

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!