# Taking an FFT of a signal that wraps around

I have an embedded application that does some phase modulation and streams back the phase offsets it's applying over UDP. I now want to take the FFT to see the spectrum of the applied modulation. Since it's phase data, it wraps around $$0$$ and $$2 \, \pi$$, which gives me some spurs in my FFT.

What's the best way of doing this?

• Unwrap the phase first? Commented May 3 at 21:16

The best solution is to unwrap the phase data before computing the fft.

Matlab's unwrap function works as follows: Whenever the jump between consecutive angles is greater than or equal to π radians, unwrap shifts the angles by adding multiples of ±2π until the jump is less than π.

Another sleazy way to unwrap phase is:

phase = cumsum([angle(X(1)); angle( X(2:N/2) ./ X(1:N/2-1) ) ]);


You still have to discern the phase at DC. Which is polarity. So it's either $$\pm \pi$$ (if the polarity is inverted at DC) or $$0$$.

I should not state it solely in MATLAB language. Their indices in the FFT are off-by-one.

$$X[k] = \big| X[k] \big| \, e^{j \phi[k]}$$

$$\phi[k] = \arg\big\{ X[k] \big\}$$

so

$$\phi[k] - \phi[k-1] = \arg\left\{ \frac{X[k]}{X[k-1]} \right\}$$

or

$$\phi[k] = \phi[0]+\sum\limits_{i=1}^{k} \arg\left\{ \frac{X[i]}{X[i-1]} \right\}$$