×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

FFT implementation for harmonics

FFT implementation for harmonics

FFT implementation for harmonics

(OP)
Hi I am trying to run the fft command on my matlab waveform that I generated.

I created a superimposed waveform of to generate harmonics.  The fundamental frequency is 60 Hz and the high frequency is 900 Hz.  I want to be able to show each of the harmonics in the FFT spectrum

CODE

a = 1; % alitude
fHz = 60;%*i; % Hz
fRads = 2*pi*fHz; % freq rad/sec
 t = 0:0.0005:1 ; % sampling time
y = (a * sin(fRads * t))...
       + (0.65*a * sin(3*fRads * t)) ...
       + (0.55*a * sin(5*fRads * t))...
        + (0.45*a * sin(7*fRads * t))...
        + (0.35*a * sin(9*fRads * t))...
        + (0.25*a * sin(11*fRads * t))...
       + (0.15*a * sin(13*fRads * t))...
        + (0.05*a * sin(15*fRads * t));

The sampling frequency used here is 2000 Hz since high frequency is 15*60 Hz = 900 Hz.  Ideally the amplitude of the spectrum should decrease as the frequency increases after doing fft.  

This is the FFT code that i created:

CODE

 Y = abs(fft(y,2001));
    %Y = fft(y,NFFT)/L;
    %f = 128/2*linspace(0,1,NFFT/2+1);
      f = 0:2000;
      plot(f,y,'-x'),title('N =2000'),axis([0 900 0 20]);
   
    % Plot single-sided amplitude spectrum.
    %plot(f,2*abs(Y(1:NFFT/2+1))) ;
    
   title('Amplitude Spectrum of y(t)');
    xlabel('Frequency (Hz)');
ylabel('|Y(f)|');

I am not getting the correct amplitude spectrum.  I am pretty sure I am doing something wrong with the fft code.  Plz help!

RE: FFT implementation for harmonics

But, how far off is it?

> Your sampling rate is too low to guarantee spectral purity.  It's barely a factor of 2 higher than the highest frequency.  You should sample at something like 50x the max frequency to ensure no pathological sampling artifacts.


> Every FFT implementation is slight different.  You need to verify and account for the scaling factor.

TTFN

FAQ731-376: Eng-Tips.com Forum Policies
Chinese prisoner wins Nobel Peace Prize

RE: FFT implementation for harmonics

Perhaps the expected amplitude is out by a factor of 2, since you're dividing the spectrum by L instead of (L/2)?

- Steve

LinkedIn
 

RE: FFT implementation for harmonics

Also there will be some leakage because there are not a whole number of cycles in your time range.

--
Dr Michael F Platten

RE: FFT implementation for harmonics

(OP)
I divided by L/2 and worked fine..the harmonic amplitude lowers as frequency increases.  However, the harmonics are not displaying on the correct frequencies.  I tried increasing the sampling to more than 2000 ( 10000) but increasing doesnt seem to improve it.  Any suggestions?

RE: FFT implementation for harmonics

I always work from first principles for the frequency axis.  The first point is zero.  The second is 1/T, where T is the sample length.  And then all subsequennt frequencies are multiples of 1/T.  I forget "magic" formulae for things like this that involve Fs and nfft, etc.

Beware that the DC and Nyquist frequency bins need only be divided by L, not L/2. (If they are important to you).

- Steve

LinkedIn
 

RE: FFT implementation for harmonics

CODE

f = 0:2000;
This needs to be tied to your bin width as stated by SomptingGuy.

=====================================
(2B)+(2B)'  ?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close