108 views (last 30 days)

Hi,

I have a signal contains fundamental + second harmonic + third + .. up to eighth harmonics. But all harmonics have same amplitude. After fft transformation, matlab shows each harmonics in different amplitudes. I was expecting them to have same amplitude. What is the reason behind it?

I want to calculate THD of the signal. But first I have to get correct amplitudes after FFT. How can I compensate the difference?

Code like that:

N = 1024; %%we need 1024 point fft

fs = 976; %%sampling frequency of the system

fb = 50; %%fundamental frequency 50 Hz

t = linspace(0,N/fs,N);

x = 0.3*cos(2*pi*fb*t)+ ...

0.3*cos(2*pi*2*fb*t)+ ...

0.3*cos(2*pi*3*fb*t)+ ...

0.3*cos(2*pi*4*fb*t)+ ...

0.3*cos(2*pi*5*fb*t)+ ...

0.3*cos(2*pi*6*fb*t)+ ...

0.3*cos(2*pi*7*fb*t)+ ...

0.3*cos(2*pi*8*fb*t);

fft_x = fft(x);

plot((0:N-1)*fs/N, abs(fft_x));

axis([0 N/2 min(abs(fft_x)) max(abs(fft_x))]);

Thanks.

Wayne King
on 21 Aug 2011

Did you change the t vector?

Fs = 976;

N = 976;

fb = 50;

t = 0:1/Fs:1-(1/Fs);

x = cos(2*pi*50*t)+cos(4*pi*50*t)+cos(6*pi*50*t);

xdft = fft(x,N);

plot(abs(xdft));

Sign in to comment.

Wayne King
on 21 Aug 2011

Hi, Your problem is that your frequencies are not falling directly on DFT bins. The DFT bins are multiples of Fs/N.

Also, your original time vector did not reflect your sampling rate of 976 Hz. You do not incorporate zero-padding in the time vector. The way you have done it, you changed the sampling rate of the signal.

N = 976; fs = 976; %% sampling frequency of the system fb = 50; %% fundamental frequency 50 Hz t = 0:1/fs:1-(1/fs); x = 0.3*cos(2*pi*fb*t)+ ... 0.3*cos(2*pi*2*fb*t)+ ... 0.3*cos(2*pi*3*fb*t)+ ... 0.3*cos(2*pi*4*fb*t)+ ... 0.3*cos(2*pi*5*fb*t)+ ... 0.3*cos(2*pi*6*fb*t)+ ... 0.3*cos(2*pi*7*fb*t)+ ... 0.3*cos(2*pi*8*fb*t); fft_x = fft(x,N); plot((0:N-1)*fs/N, abs(fft_x));

Wayne

Sign in to comment.

zohar
on 21 Aug 2011

Hi

When you are using

t = linspace(0,N/fs ,N);

your fs is not as you assumed it's

1/(t(2)-t(1))

just change the lines

fs = N; %%sampling frequency of the system

t = linspace(0,N/fs - 1/fs,N);

and it's ok

And that is because of you are using linspace, for next time use

t = [0:N-1]/fs;

Have fun

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.