I have a rectangular pulse:

w = 20; pln = 10;
v =[zeros(1, pln), ones(1, w),zeros(1, pln)];
figure(); plot(v,'-o');

by perform fft and fftshift the pulse center to zero to get its frequency domain representation:

yf = fftshift(fft(v));
xf = [-0.5000   -0.4750   -0.4500   -0.4250   -0.4000   -0.3750   -0.3500   -0.3250...
-0.3000   -0.2750   -0.2500   -0.2250   -0.2000   -0.1750   -0.1500   -0.1250...
-0.1000   -0.0750   -0.0500   -0.0250         0    0.0250    0.0500    0.0750...
0.1000    0.1250    0.1500    0.1750    0.2000    0.2250    0.2500    0.2750...
0.3000    0.3250    0.3500    0.3750    0.4000    0.4250    0.4500    0.4750];
yf = yf.*exp(-2j*pi*xf*(pln+w/2)); % this shifts the time domain signal to zero

yf is close to the sinc function - the Fourier transform of a rectangular function - but not exactly the same, it has imaginary part while sinc is is purely real:

yf_sinc = w*sinc(w*xf);

Why is the difference and why ifft of samples taken from a sinc function will not produce an exact rectangular pulse but with ripples close to the edge while ifft(fft(v)) will exactly reproduce the original rectangular pulse:

% has ripples around the edges
figure(); plot(fftshift(ifft(fftshift(yf_sinc)))); 
% reproduces the exact rectangular pulse  
figure(); plot(fftshift(ifft(fftshift(yf)))); 

herer yf, if we assume it was directly sampled form a underlying function, that is ingoring the fact that it is produced by fft of a rectangular pulse (it's just some numbers anyway), what function would it be? Is it possible by sampling a function in the frequency domain (not need to be the sinc function) and take the ifft will produce an exact rectangular pulse?

rectangular pulse and fft compared to a sinc function sampes

  • 3
    $\begingroup$ To get a purely real output, your signal needs to be "DFT-even" symmetrical, which basically means it has one extra sample at the beginning. [0, 1, 2, 3, 2, 1] is DFT-even symmetrical, for instance. (and the DFT bins are symmetrical in the same way, starting at DC: [DC, 1, 2, fs/2, 2, 1]) $\endgroup$
    – endolith
    Jul 28 '17 at 15:41
  • 1
    $\begingroup$ The answer to a question that is nearly identical to your question is: dsp.stackexchange.com/questions/32216/… $\endgroup$
    – user28715
    Jul 28 '17 at 19:22

The even part of a real signal transforms to the real part of the DFT. The odd part of a real signal transforms to the imaginary part of the DFT. For example, the DFT of cosine, an even function, is strictly real, while the DFT of a sine, an odd function, is strictly imaginary.


To get a purely real output, your signal needs to be "DFT-even" symmetrical, which basically means it has one extra sample at the beginning. For instance:

  • [0, 1, 2, 2, 1, 0] is "normal" even symmetrical
  • [0, 1, 2, 3, 2, 1] is DFT-even symmetrical

So this rectangular pulse FFT has an imaginary part:

fft([0, 1, 1, 1, 1, 0])
array([ 4.0+0.j   , -1.5-0.866j, -0.5-0.866j,  0.0-0.j   , -0.5+0.866j,

but this rectangular pulse FFT does not:

fft([0, 0, 1, 1, 1, 0])
Out[8]: array([ 3.+0.j, -2.+0.j,  0.+0.j,  1.-0.j,  0.+0.j, -2.+0.j])

As you can see, the DFT output is also DFT-even symmetrical

[3, -2, 0, 1, 0, -2]
     │  └─────┘   │

as are the frequency bins themselves:

[DC, fs/6, fs/3, -fs/2, -fs/3, -fs/6]
      │     └─────────────┘      │

That is not symmetrical around index 0 (supposedly the first index). You probably need to apply fftshift before the transform as well as afterwards in order to get the representation you expect both in time and frequency domain.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.