1

I know the fundamental frequency of my signal and therefore I also know the other frequencies for the harmonics, I have used the FFT command to compute the first 5 harmonics (for which I know their frequencies). Is it possible for me to find the phase with this available information?

Please note I cant be sure my signal is only one period and therefore need to calculate the phase via the known frequency values.


Code seems to be working:

 L = length(te(1,:));               % Length of signal
 x = te(1,:); 
 NFFT = 2^nextpow2(L);              % Next power of 2 from length of y
 Y = fft(x,NFFT)/L;
 f = linspace(1,5,5);   
 Y(1) = [];                          % First Value is a sum of all harmonics
 figure(1);
 bar(f,2*abs(Y(1:5)), 'red') 
 title('Transmission Error Harmonics')
 xlabel('Harmonic')
 ylabel('|Y(f)|')
 figure(2);
 bar(f,(angle(Y(1:5))))
 title('Transmission Error Phase')
 xlabel('Harminic')
 ylabel('Angle (radians)')

2 Answers 2

3

Note that if your fundamental frequency is not exactly integer periodic in the fft length, then the resulting phase (atan2(xi,xr)) will be flipping signs between adjacent bins due to the discontinuity between the fft ends (or due to the rectangular window convolution), making phase interpolation interesting. So you may want to re-reference the FFT phase estimation to the center of the data window by doing an fftshift (pre, by shift/rotating elements, or post, by flipping signs in the fft result), making phase interpolation look more reasonable.

Sign up to request clarification or add additional context in comments.

Comments

1

In general your Fourier transformed is complex. So if you want to know the phase of a certain frequency you calculate it with tan(ImaginaryPart(Sample)/RealPart(Sample)). This can be done by using angle(). In your case you

1- calculate fft()

2- calculate angle() for all samples of the FFT or for the samples you are interested in (i.e. the sample at your fundamental frequency/harmonic)

EDIT: an example would be

t = [0 0 0 1 0 0 0];
f = fft(t);
phase = angle(f);
phase = angle(f(3)); % If you are interested in the phase of only one frequency

EDIT2: You should not mix up a real valued spectrum [which is basically abs(fft())] with a complex fourier transformed [which is only fft()]. But as you wrote that you calculated the fft yourself I guess you have the 'original' FFT with the complex numbers.

2 Comments

Thank you for your quick reply but how do you calculate the angle?
I edited my post above. Your FFT should contain complex numbers. Then you can calculate the angle for each complex number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.