[英]Convolution of two fft function
For convolution theorem F(xy) = F(x)*F(y) 对于卷积定理F(xy)= F(x)* F(y)
However after implement it on python 但是在python上实现它之后
x = np.array([0,0,0,0,1, 2, 3, 4, 0 ,0,0,0])
y = np.array([0,0,0,0,-3, 5, -4, 0, 0, 0,0,0])
xy = x*y
inverse_fft_xy = np.fft.ifft(np.convolve(np.fft.fft(x),np.fft.fft(y)))
Will yield 会屈服
xy
array([ 0, 0, 0, 0, -3, 10, -12, 0, 0, 0, 0, 0])
inverse_fft_xy
array([ 0.00000000e+00, -8.70383905e-01, 1.65925305e-02,
-8.90888514e-01, 7.07822398e-02, -8.80447879e-01,
1.19687210e-01, 3.09247006e+00, -9.54481834e+00,
-5.81203213e+00, 2.15726342e+01, -1.47366137e+01,
-1.03012447e+01, 2.76823117e+00, -1.42560168e+00,
4.98000293e-01, -1.18537317e+00, 2.02675981e-01,
-9.98770784e-01, 7.43392335e-02, -9.11516399e-01,
1.67799168e-02, -8.74501632e-01])
and it is the same for matlab 与Matlab相同
I know that there should be zeros padded to avoid linear convolution. 我知道应该填充零以避免线性卷积。 Also, the other way of theorem F(x*y) = F(x).F(y) can be done.
同样,可以完成定理F(x * y)= F(x).F(y)的另一种方法。 I just want to know why it cannot be done this way.
我只想知道为什么不能以这种方式完成。
The time-domain multiplication is actually in terms of a circular convolution in the frequency domain, as given on wikipedia : 时域乘法实际上是在频域中进行循环卷积,如Wikipedia所述 :
Following @ Ami tavory 's trick to compute the circular convolution, you could implement this using: 遵循@ Ami tavory的技巧来计算圆形卷积,您可以使用以下方法实现此目的:
Xf = np.fft.fft(x)
Yf = np.fft.fft(y)
N = Xf.size # or Yf.size since they must have the same size
conv = np.convolve(Xf, np.concatenate((Yf,Yf)))
conv = conv[N:2*N]
inverse_fft_xy = np.fft.ifft(conv) / N
such that 这样
x = np.array([1, 2, 3, 4])
y = np.array([-3, 5, -4, 0])
(without any more zero padding than is necessary to have both arrays the same size) would yield the expected: (没有比使两个数组具有相同大小所需的零填充更多)将产生预期的结果:
xy
array([ -3, 10, -12, 0 ])
inverse_fft_xy
array([ -3.+0.j, 10.+0.j, -12.+0.j, 0.+0.j])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.