0

I want to extract phase difference between two cosine functions from FFT. The cosine functions are: x1(n)=cos(2*pifin) and x2(n)=cos(2*pifi(n-m)). Based on DFT properties we have:

DFT(x1(n))= X1(f);
DFT(x2(n))= exp( (-j*2*pi*m*fi)/N )X1(f)

Therefore, phase difference between DFT(x1(n)) and DFT(x2(n)) equals to (-2*pimfi)/N. However, the results obtained from my matlab code is quiet different! My codes are as follow

 clc
clear all
Fs = 250;                    % Sampling frequency
T = 1/Fs;                     % Sample time
iniPhase=pi/6;
fin=120;
t=0:(1/Fs):2;
xu = cos(2*pi*fin*(t)) ;
xd = cos(2*pi*fin*(t)+iniPhase) ;
NFFT=length(xu);
NFFT=256;

Xu = fftshift(xu);
FFTXu = 2*fft(Xu,NFFT);
SpecXu=2*abs(FFTXu(1:NFFT/2+1));

Xd = fftshift(xd) ;
FFTXd = 2*fft(Xd,NFFT);
SpecXd=2*abs(FFTXd(1:NFFT/2+1));


[tt ind]=max(SpecXd(1:NFFT/2+1));

Phased=(angle( FFTXd));
Phaseu=(angle( FFTXu));
theta=(Phased(ind))-(Phaseu(ind));
user51780
  • 139
  • 2
  • 5

1 Answers1

0

From the shift property of Fourier transform, you have given the spectra of x1(n) and x2(n)

DFT(x1(n))= X1(f);
DFT(x2(n))= exp( (-j*2*pi*m*fi)/N )X1(f);

Then, it's clear that the phase factor can be obtained from

DFT(x2)/DFT(x1), 

but not

angle(DFT(x2) - DFT(x1)).
lxg
  • 226
  • 3
  • 14