Skip to content
Advertisement

Scipy ifft gives different results with seemingly identical input

Why would xcorr and xcorr2 be quite different here? M1 and M2 are numpy matrices. M1.shape[0] = M2.shape[0]. xcorr is what I would expect with this operation, but xcorr2 is something totally different and has imaginary numbers. xcorr does not have imaginary numbers.

JavaScript

Advertisement

Answer

Try giving xcorr and xcorr2 dtype=complex.

JavaScript

According to scipy docs, the output from both fft and ifft is a complex ndarray.

You create xcorr and xcorr2 with np.zeros(), so it’ll have a default dtype of float64.

Putting the output from fft into the xcorr2 will result in a cast of complex to float64, that results in the imaginary part being discarded.

When you feed xcorr2 into ifft() it has no imaginary part, so you get a different result.

The cast is also why you don’t see the imaginary part in xcorr.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement