I know how to change the phase of a complex number by multiplying by $\cos \theta + i \sin \theta$. And I understand that the phase of a sine wave is reflected in its Fourier transform. So, I am trying to phase-shift a signal by changing the phase of its Fourier transform..
This works for "synthetic" Fourier transforms, but when I try to FFT a signal, apply the phase change, and invert the FFT, I don't get the expected result. I am using MATLAB in the examples below.
Fs = 1000; Tmax = 2; L = Tmax * Fs;
For example, I'll build a synthetic Fourier sequence. The frequency intervals are 0.5 Hz, so a 10Hz component is at the 20th position after DC. (I'm just spitballing here; I know there's better ways to pick frequency bins than hand-jamming
Ysynth = zeros(1, L); Ysynth(21) = 1000;
And rotate it by 45°:
Ysynth = Ysynth * exp(j * pi/4);
It has a 45° phase on the 10-Hz component:
Now take its inverse FFT:
Xsynth = ifft(Ysynth);
So far so good. The generated signal has a phase shift of 45°. MATLAB does complain about the presence of an imaginary part when I plot it; I think this is because I didn't bother with the negative frequency component.
t = (0:L-1)/Fs; plot(t, Xsynth)
Now, I would expect the same principle to apply to a frequency spectrum taken from an actual signal. But I do not get similar results. Quickly:
X = cos(2*pi * 10 * t); Y = fft(X); Yshift = Y * exp(j * pi/4); Xshift = ifft(Yshift);
There is an imaginary component in Xshift, which I do not expect, and again MATLAB complains about.
plot(t, [Xshift; X])
There is no phase shift here, and the amplitude (of the real part) is different.
I must be misunderstanding something about phase representation in FFTs. Why doesn't my transformation produce a phase-shifted version of the original?