fft的点积 [英] Point-product with fft
问题描述
根据卷积定理,时域中的卷积是fft域中的乘积.使用正确的零填充,它可以工作:
According to the convolution theorem, a convolution in the time domain is a product in the fft domain. With correct zero-padding, it works:
% convolution in time domain
a = [1 2 3];
b = [4 5 6];
c = conv(a,b);
a_padded=[a 0 0]; b_padded=[b 0 0];
c_bis=ifft(fft(a_padded).*fft(b_padded));
% we do find c_bis=c
但是,该定理也应该以相反的方式工作,时域中的乘积是fft域中的卷积.我没有得到这一部分:
However, this theorem is suposed to work the other way around as well, a product in the time domain is a convolution in the fft domain. I dont get this part:
d = a.*b;
D=conv(fft(a_padded),fft(b_padded));
d_bis=ifft(D);
给出d_bis的复数向量. 如何利用频域中的卷积逆变换时域中的逐点乘积?
Which gives a complex vector for d_bis. How could one inverse a point-wise product made in the time domain using a convolution in the frequency domain ?
推荐答案
有趣的问题!
错误(尽管是一个细微的错误)是当你说
The mistake (although a subtle one) is when you say
时域中的乘积是FFT域中的卷积
A product in the time domain is a convolution in the FFT domain
傅里叶变换就是如此.使用 离散傅里叶变换 (DFT或FFT),正确的公式是
时域中的乘积是FFT域中的循环卷积,除以序列长度
因此您必须在d_bis
计算中对此进行更改:
So you have to change this in your d_bis
computation:
- 使用圆形卷积,而不是卷积;
- 除以序列长度;
- 不应用填充.
如果您拥有信号处理工具箱,则可以使用 cconv
计算圆形卷积:
If you have the Signal Processing toolbox you can use cconv
to compute the circular convolution:
N = length(a);
D = cconv(fft(a),fft(b), N)/N;
d_bis=ifft(D); %// now this equals d
请确保在第一种情况下正确的公式(时域在频域中给出乘积)还涉及 circular 卷积:
To make sure, the correct formulation in the first case (convolution in time domain gives product in frequency domain) also involves circular convolution:
时域中的循环卷积是FFT域中的乘积
A circular convolution in the time domain is a product in the FFT domain
(在这种情况下,不除以序列长度)
(no dividing by sequence length in this case)
但是由于您在时域中填充了零,所以正常卷积和圆形卷积之间的差异消失了,并且您得到了正确的结果.如果没有填充,它将是:
But since you padded with zeros in the time domain, the difference between normal and circular convolution disappears and you get the correct result. Without padding, it would be:
c = cconv(a, b, N);
c_bis=ifft(fft(a).*fft(b)); %// this equals c
这篇关于fft的点积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!