Professional Documents
Culture Documents
Testdirectionfft
Testdirectionfft
clear all
clc
sum_previous=0;
final_sum=0;
freq=50;
%sampling time
% Ts=1/Fs;
Ts= 10e-6;
Fs=1/Ts;
t=0:Ts:1.0;
%t=test.current.time;
sin1=sin(2*pi*50*t);
sin2=0.25*sin(2*pi*5*50*t);
sin3=0.1*sin(2*pi*7*50*t);
sin4=0.01*sin(2*pi*20*50*t);
sin=sin1+sin2+sin3+sin4;
plot(t,sin)
THD1=sqrt(.25^2+.1^2+.01^2)*100
nfft2=2^nextpow2(nfft)
%normalization of frequency
f=(0:nfft2/2-1)*Fs/nfft2;
figure(1)
subplot(2,1,1);
plot(t,sin,'r');
title('Signal');
xlabel('Time');
ylabel('Amplitude');
ft=fft(sin,nfft2);
%normalization of amplitude
ft=ft/max(ft);
ffft=ft(1:nfft2/2);
amp_fft=abs(ffft);
del_f=f(end)-f(end-1)
f_50=50/del_f
amp_50=amp_fft(ceil(f_50)+1)
amp_250=amp_fft(ceil(5*f_50)+1)
amp_350=amp_fft(ceil(7*f_50)+1)
amp_1000=amp_fft(ceil(20*f_50)+1)
plot(f,amp_fft,'r');
title('FFT Plot');
xlabel('frequency');
ylabel('Amplitude');
figure(2)
plot(f(1:1:1000),amp_fft(1:1:1000));
THD2= sqrt(sum(amp_fft(75:1000).^2))/amp_50