In this tutorial, I will show you how to get Fast Fourier transform of a signal and then correctly display the signal. Link to the code in my Github repository.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
%% Creating signal Fs=1000; %Sampling fresquncy T_inc=1/Fs; %Time increament T_measure=1.5; %Duration of measurment time=0:T_inc:T_measure - T_inc; %Vector contains sampling time L=length(time); %Lenght of signal %% Sum of a 60Hz and 120 Hz sinusoidal f1=120; f2=60; phi1=1.5; phi2=2.4; amplitude1=1.5; amplitude2=2.2; y=amplitude1*sin(2.*pi.*f1*time+phi1) + amplitude2*sin(2.*pi.*f2*time+phi2); |
Getting Fourier transform of the signal:
1 |
signal_FFT=fft(y,L); |
1 2 3 |
signal_FFT=fft(y,L)/L; amplitude=2*abs( signal_FFT(1: floor(L/2) +1) ); frequency=Fs/2*linspace(0,1, floor(L/2) +1); |