akaballa
Computer
- May 29, 2011
- 7
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));
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!