# FFT, padding, IFFT and plot in time domain

I performed an FFT with some zero padding and would like to transform it back to time domain. When I plot the signal it looks wrong. Is it because of the padding used in the FFT? How can I make it right? here is my code for doing the IFFT:

NFFT=4301;
AvIFFT = ifft(FFTavg.dat,NFFT);
plot(real(AvIFFT))


And I get this plot:

Any help would be greatly appreciated! Thank you!

ps: I have asked this question on matworks but no success as yet.

EDIT:

As suggested in the comment and answer below, I tried fftshift:

NFFT = 4301;
FFTshifted = fftshift(FFTavg.dat);
AvIFFT  = ifftshift(FFTshifted,NFFT);
plot(real(AvIFFT))


Here is the plot:

• look up the MATLAB function fftshift(). – robert bristow-johnson Jan 2 '16 at 4:21
• have you tried fftshift() yet? – robert bristow-johnson Jan 2 '16 at 17:19
• what does it do to your time-domain plot? – robert bristow-johnson Jan 3 '16 at 4:31
• As I do ifft that should be the time-domain plot, right? – user3406207 Jan 3 '16 at 6:01
• apply to this: NFFT=4301; AvIFFT = ifft(FFTavg.dat,NFFT); before this: plot(real(AvIFFT)) – robert bristow-johnson Jan 3 '16 at 6:02

user3406207: I'm not sure what you're trying to do because I don't know the meaning of your words "wrong" and "right." But we can say, if you perform time-domain zero padding on an original unpadded $x1[n]$ input sequence you'll produce some longer-length $x2[n]$ sequence. The $X2[m]$ fft of your $x2[n]$ sequence will be an interpolated version of (more freq-domain samples than) the $X1[m]$ fft of your $x1[n]$ sequence. And, of course, the inverse fft of $X2[m]$ will be $x2[n]$ and the inverse FFT of $X1[m]$ will be $x1[n]$. I hope that helps. (By the way, you were smart to plot just the real part of your inverse fft.)

The plot is correct. You have to remember that with the DFT the time domain is also periodic, so the left side of the plot represents time $t=0$ and the far right side represents time $t<0$. If you use fftshift the plot will look as you'd expect except that the middle of your plot will reresent time $t=0$.

Saw the edits you made to your code - I think you be skipping the first fftshift. I always use fftshift - I can't recall the difference between fftshift and ifftshift. See example below. Actually I think there is an error in your new code - it should be ifft rather than ifftshift.

NFFT = 4301;
AvIFFT  = ifft(FFTavg.dat,NFFT);
plot(real(fftshift(AvIFFT)))

• Thank you. I tried to use fftshift() above. As this fft is the result of an average, I cannot check with initial signal. Is it normal that it is very symmetric like this? Or did I make an error in the code? – user3406207 Jan 3 '16 at 4:12
• Well, it depends on what your original time series is, so I can't say. You really need to show what the original time series is, even if it is averaged. You should look at the ifft of FFTavg.dat without any interpolation - your interpolated result should appear similar but interpolated i.e. a higher time sampling. – David Jan 4 '16 at 14:19
• Thanks for the advice. I will try to average the time series and compare. – user3406207 Jan 5 '16 at 3:37
• @user3406207 For your FFTavg.dat are the complex valued FFTs averaged or is it their magnitudes or something else? – David Jan 5 '16 at 16:06
• This is how I averaged the ffts of my time series: Y(:,i) = fft(dat1(i),Padding); avg = sum(abs(Y),2)/size(Y,2); FFTavg.dat = avg; – user3406207 Jan 6 '16 at 6:04