## 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

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:

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

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));

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)|');

%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

> 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

- Steve

LinkedIn

## RE: FFT implementation for harmonics

--

Dr Michael F Platten

## RE: FFT implementation for harmonics

## RE: FFT implementation for harmonics

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

=====================================

(2B)+(2B)' ?