How to obtain sine wave back after fft

fftMATLABsine

I performed fft in matlab on y=sin(2*pi*t), with a time period of T=0.015. Now I want to get the original function back in the time domain, but I'm not sure how I can use ifft to do that. It gives me the wrong answer each time. Could someone please explain to me how to go about this?

Best Answer

Well, here's a bit of MATLAB code that does work (16,384 point FFT on a 240 second sample, padded with zeros).

dt = 0.015;
tmax = 240;
x = 0:dt:tmax;
y = sin(2*pi*x);
N = 2^14;
transformed_y = fft(y,N)*dt;
ft = 1/dt;
f = (0:(N-1)/2)/N*ft;
recovered_y = ifft(transformed_y,N,'symmetric')/dt;
x_recovered = 0:1/ft:(length(recovered_y)-1)*1/ft;
plot(x_recovered, recovered_y,'g')

enter image description here

(and zoom in to the beginning of the plot)

enter image description here