Scipy IFFT给出不同的结果,看似相同

发布于 2025-01-24 12:21:15 字数 547 浏览 2 评论 0原文

为什么XCorr和Xcorr2在这里会大不相同? M1和M2是Numpy矩阵。 m1.形[0] = m2。形状[0]。 Xcorr是我期望的,但是XCORR2是完全不同的,并且具有虚构的数字。 Xcorr没有虚构数字。

from scipy.fft import fft, ifft

xcorr = np.zeros((M1.shape[0],M1.shape[1],M2.shape[1]))  
xcorr2 = xcorr.copy()

N = M1.shape[1]
for i in range(N):
    V = M1[:,i][:,None]
    xcorr[:,:,i] = ifft(fft(M2,axis = 0) * fft(np.flipud(V), axis = 0) ,axis = 0)

for i in range(N):
    V = M1[:,i][:,None]
    xcorr2[:,:,i] = fft(M2,axis = 0) * fft(np.flipud(V), axis = 0)        
xcorr2 = ifft(xcorr2, axis = 0)

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.

from scipy.fft import fft, ifft

xcorr = np.zeros((M1.shape[0],M1.shape[1],M2.shape[1]))  
xcorr2 = xcorr.copy()

N = M1.shape[1]
for i in range(N):
    V = M1[:,i][:,None]
    xcorr[:,:,i] = ifft(fft(M2,axis = 0) * fft(np.flipud(V), axis = 0) ,axis = 0)

for i in range(N):
    V = M1[:,i][:,None]
    xcorr2[:,:,i] = fft(M2,axis = 0) * fft(np.flipud(V), axis = 0)        
xcorr2 = ifft(xcorr2, axis = 0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终陌 2025-01-31 12:21:15

尝试给出XCorrXCorr2 dtype = complex

xcorr = np.zeros((M1.shape[0],M1.shape[1],M2.shape[1]), dtype=complex)  
xcorr2 = xcorr.copy()

根据Scipy Docs的说法,FFT和IFFT的输出都是复杂的NDARRAY。

您可以使用np.zeros()创建xcorr xcorr2 xcorr2 ,因此它将具有float64的默认dtype。

将FFT输出到XCORR2中将导致复杂 float64 的铸件导致假想零件被丢弃。

当您将Xcorr2馈入ifft()时,它没有虚构的部分,因此您会得到不同的结果。

演员也是为什么您看不到Xcorr中的虚构部分的原因。

Try giving xcorr and xcorr2 dtype=complex.

xcorr = np.zeros((M1.shape[0],M1.shape[1],M2.shape[1]), dtype=complex)  
xcorr2 = xcorr.copy()

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文