Recovering signal from magnitude and phase of FFT
I tried running the same code, and it works fine, except for 2 minor points:


It's preferable to use exp(1i*phase) instead of exp(sqrt(-1)*phase)
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