# Recovering signal from magnitude and phase of FFT

I'm trying to code the basics of an analysis-synthesis system on MATLAB, but I'm getting incorrect results. From the Wikipedia page:

$$X_k=\lvert X_k\rvert e^{i\angle X_k}$$

Here's a simple MATLAB code:

y = speech(10:10+127);

yfft = fft(y,128);

spec = abs(yfft);
phase = unwrap(angle(yfft));

Y = spec .* exp(sqrt(-1)*phase);

yinv = ifft(Y,128);


yet y and yinv do not match. What's the issue here?

• what's your sample rate? 128 samples worth of DFT surely doesn't sound like a "recognizable" sound. – Marcus Müller Aug 19 '16 at 9:11

1. It's preferable to use exp(1i*phase) instead of exp(sqrt(-1)*phase)
2. The final result will deviate from the original signal due to rounding noise (typically around 1e-16). Also, some of this noise will appear in the imaginary part of the result (so, even if y was real, yinv will be complex, due to the small imaginary component). This will be particularly apparent if you try: plot(yinv), because Matlab will see that yinv is complex, and plot it on the real/imag axis