ifftshift is to correct the bug in fftshift when dealing with the sequence with odd length (that is the number of elements in the sequence is odd). So it is safe to always use: fftshift(fft(ifftshift(sig))) or fftshift(ifft(ifftshift(spectrum))).
Thanks for the code and the discussion - nice and helpful.
A book I'm reading says it should be
I'm confused. Could you explain where to use ifftshift when N=odd?
(The book is "Numerical Simulation of Optical Wave Propagation with examples in Matlab")
You're welcome. ifftshift is the same as fftshift for even length sequence, but different for odd length. So if one uses fftshift(fft(ifftshift(...))) things work well. By the way, scaling by dt and df to correct for scaling introduced by FFT algorithm is neat trick.