Scipy IFFT给出不同的结果,看似相同
为什么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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试给出
XCorr
和XCorr2
dtype = complex
。根据Scipy Docs的说法,FFT和IFFT的输出都是复杂的NDARRAY。
您可以使用np.zeros()创建
xcorr
xcorr2 xcorr2 ,因此它将具有float64
的默认dtype。将FFT输出到XCORR2中将导致
复杂
float64 的铸件导致假想零件被丢弃。当您将Xcorr2馈入ifft()时,它没有虚构的部分,因此您会得到不同的结果。
演员也是为什么您看不到Xcorr中的虚构部分的原因。
Try giving
xcorr
andxcorr2
dtype=complex
.According to scipy docs, the output from both fft and ifft is a complex ndarray.
You create
xcorr
andxcorr2
with np.zeros(), so it'll have a default dtype offloat64
.Putting the output from fft into the xcorr2 will result in a cast of
complex
tofloat64
, 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.