Hi guy's I'm working on simple signals and I want to calculate the Fourier transform of a signal, get the magnitude and phases, then reconstruct the original signal from that.

I'm basing my code on [this](https://stackoverflow.com/questions/6393257/getting-fourier-transform-from-phase-and-magnitude-matlab) thread.

Code:

```
>> n=0:99;
>> N=length(n);
>> x = sin((2*pi/N).*n).*cos((pi/N).*n);
>> F = fft(x);
>> mag =  sqrt(real(F).^2 + imag(F).^2);
>> phase = atan2(imag(F),real(F));
>> re = mag .* cos(phase);
>> im = mag .* sin(phase);
>> F_i = re + 1i*im;
>> x_i = ifft(F_i);
>> figure;stem(x);figure;stem(x_i);

```

I completely get different graphs. 

EDIT: I'm actually doing this to test what would happen to a signal if the phase changes. So with this I will need the phase angle to construct the signal again.

I'm still new to both Fourier + Matlab so I apologize if I'm making some random stupid mistake. I'll appreciate it if you guys can point me in the right direction. Thank you.