The fft of a real valued sequence gives complex conjugate values apart from a real value corresponding to the DC component. Every pair of complex conjugate values are associated with respective pairs of a positive and negative frequency. For example if a typical pair of complex conjugates at a frequency w1 are of the form
a+jb (=R exp(jw1)) and a-jb (=R exp(-jw1)),
The total component at any instant of time is
R exp(jw1)+ R exp(-jw1)= 2RCos(w1t)
Thus the basis function for fft is a Cosine function and gives the angle associated with the cosine function. The phase plot for fft (2RCos(w1t)) gives zero phase for a frequency of w1.
The phase plot for fft (2RCos(w1t-pi/3)) gives –pi/3 for a frequency of w1 and so on.
If we want to consider a sequence as consisting of sinusoids with different phase, the fft gives a phase spectrum considering equivalent cosinusoids replacing the sinusoids. For example
2Sin(w1t+pi/3)=2Cos(w1t+pi/3-pi/2)= 2Cos(w1t-pi/6) so that the phase spectrum shows an angle –pi/6 and NOT pi/3.
The following programme takes the fft of a signal with two sinusoids and illustrates the above principle.
On running, the programme displays magnitude spectrum and waits 5 seconds before displaying the phase spectrum.
clc
clear all
%To find the fft of a signal with two sinusoids with different amplitudes
%and phase and verify magnitude and phase relations
f1=100;%frequency in hertz of one of the sinusoids
f2=300;%frequency in hertz of the second sinusoid
fs=1024;%sampling frequency, chosen as a power of 2 and also more than
% 2 times the highest frequency.
t=0:1/fs:2-(1/fs);%analysis time duration of 2 secs
x1=5*sin(2*pi*f1*t+pi/6);%sinusoid with amplitude 5 and phase pi/6 rad.
x2=2*sin(2*pi*f2*t-pi/3);%sinusoid with amplitude 2 and phase -pi/3 rad.
%x1,x2,expressed as EQUIVALENT COSINE FUNCTIONS
%are given by:-
%x1=5*cos(2*pi*f1*t+pi/6-pi/2);
%x2=2*cos(2*pi*f2*t-pi/3-pi/2);
%simplifying x1 and x2,
x1=5*cos(2*pi*f1*t-pi/3);%cosinusoid with amplitude 5 and phase -pi/3 rad.
x2=2*cos(2*pi*f2*t-5*pi/6);%cosinusoid with amplitude 2 and phase 5pi/6 rad.
z=x1+x2;%waveform containg both cosinusoids
n=1024;% fft size
zft=fft(z,n);%fft of z
zft2=zft;%zft2 is same as zft
freq_resolution=fs/n;% frequency resolution = sampling freq/fft size;
stem((0:n/2)*fs/n,2/n*abs(zft(1:n/2+1)));%magnitude plot for +ve frequencies
xlabel('Frequency, in Hertz');
ylabel('Amplitude')
title('MAGNITUDE SPECTRUM');
grid
pause(5)
threshold = max(abs(zft))/10000; %tolerance to eliminate tiny magnitude
components
zft2(abs(zft)<threshold) = 0;%sets tiny magnutude components to zero
zftg=(angle(zft2)*180/pi);%computes phase angles of fft in degrees
stem((0:n/2)*fs/n,zftg(1:n/2+1));%plots phase spectrum for +ve frequencies
title('PHASE SPECTRUM');
xlabel('Frequency, in Hertz');
ylabel('Phase Angle in Degrees')
grid