Hi,
I have two signals. I am acquiring them through the ADC channels. I could successfully compute the FFT using inbuilt functions in the ROM of c5515.
To check if the FFT computations are correct, if gave a 1Hz signal and back calculated the frequency from the peak of the FFT_magnitude array.
Now, I want to calculate the phase shift between the two signals. So , I computed the peak in the FFT_magnitude and then find the phase differnce between the principal components. but unfortunately, I am not getting the expected answer. Could you please have a look, if the way i am computing phase is wrong or not ?
Length of the FFT -----------------------------> INPUT_BUFFER
Computed FFT is stored in a pointer ---> *result
j=0;
for(i=0;i<INPUT_BUFFER/2;i++) //I am just tranversing only half of INPUT_BUFFER since FFT are mirrored halves
{
real_part[j] = *(result++);
imaginary_part[j] = *(result++);
magnitude[j] = sqrt(pow(real_part[j],2) + pow(imaginary_part[j],2));
phase[j] = atan(imaginary_part[j] / real_part[j]);
j = j+1;
}
Using this algorithm, I found magnitude and phase information in both the signals. I am using same frequency signals but shifted by theta degrees.
Signal_1 -- > magnitude_1 and phase_1
Signal_2 -- > magnitude_2 and phase_2
I compute the maximum index in the magnitude_1 and magnitude_2 array. Since , both the signals are of same frequency, peaks in magnitude_1 and magnitude_2
occur at the same index = peak_index
Now, to calculate phase shift = ( phase_2[peak_index] - phase_1[peak_index] ) * 180 / pi;
This should have given me theta. But, the answer is coming, bit random.
Can someone tell me how to tackle this ???