Reputation: 3
I am trying to compute the phase angle in the frequency domain (after computing fft) of the second component of the Fourier spectrum of a synthetic signal constructed by me in the workspace of Matlab. I am sure that the phase is equal to 0 (as you can see in the code), but the result I get is pi/2. The code is the following:
t = 0:pi / 128:(2 * pi - pi / 128);
V = sin(t);
L = length(V);
n = 2^nextpow2(L);
Y = fft(V, n);
threshold = max(abs(Y))/10000;
Y(abs(Y)<threshold) = 0;
mag = abs(Y/n);
angle = rad2deg(atan2(imag(Y),real(Y)));
I do not see where the error is.
Upvotes: 0
Views: 1352
Reputation: 487
You are mistaken that the phase of a real, periodic sine wave with a frequency that corresponds to the bin center frequency (and no phase offset) is zero. The basis functions representing the real part of the original sequence are cosine functions.
To represent a sine wave with a cosine wave a phase offset of pi/2 has to be subtracted:
sin(x) = cos(x - pi/2).
Therefore, the phase in bin 2 (corresponding to the frequency of the original sequence), is -pi/2.
(For a more thorough explanation see this question on DSP.SE.)
Upvotes: 1