Confusion about convolution theorem in matlab
Show older comments
Convolution theorem in fourier transform states:
Fourier transform of a convolution of two vectors A and B is pointwise product of Fourier transform of each vector. (Ref: https://en.wikipedia.org/wiki/Convolution_theorem)
Now let A=B=[0.7, 0.2, 0.1], pointwise product of A and B can be obtained through the code:
fft(A).*fft(A)
The result is [1.000000000000000 + 0.000000000000000i, 0.295000000000000 - 0.095262794416288i, 0.295000000000000 + 0.095262794416288i].
Convolution of A and B can be obtained by inverse Fourier transform:
ifft(fft(A).*fft(A))
The result is C=[0.530000000000000 0.290000000000000 0.180000000000000].
However, convolution of A and B can be calculated in the matlab code:
conv(A,A)
The result is C'=[0.490000000000000 0.280000000000000 0.180000000000000 0.040000000000000 0.010000000000000].
The result vectors C is not equal to C', contradictory to the convolution theorem. This example shows my confusion on Fourier tranform in matlab code and convolution theorem. Would anyone help me to understand this?
Thanks very much:)
1 Comment
Arkaprabho Pal
on 21 Apr 2020
Edited: Arkaprabho Pal
on 21 Apr 2020
The convolution theorem says, roughly, that convolving two sequences is the same as multiplying their Fourier transforms. In order to make this precise, it is necessary to pad the two vectors with zeros and ignore roundoff error. Also make sure to use 'full' keyword in conv function.
t = linspace(0,1,200)
x = sin(2*pi*t)
y = exp(-2*t)
X = fft([x zeros(1,length(y)-1)])
Y = fft([y zeros(1,length(x)-1)])
then conv(x,y,'full') = ifft(X.*Y)
Accepted Answer
More Answers (1)
Image Analyst
on 16 Sep 2017
Try this:
A = [0.7, 0.2, 0.1]
B = [0.7, 0.2, 0.1]
Cconv = conv(A, B)
% Now if C = A ** B
% Then fftC = fftA * fftB
fftA = fft(A)
fftB = fft(B)
fftC = fftA .* fftB
% If we inverse transform this to get C back:
% ifft(fftC) = C = ifft(fftA .* fftB)
C2 = ifft(fftC)
C3 = ifft(fftA .* fftB)
I think the difference you're seeing in Cconv and C2 or C3 is that CConv is the full convolution - 5 elements - while doing it the fft way, you are clipping to the same size as your input arrays - 3 elements - and so inherently you have a rect function in there multiplying your A and B. And the convolution of a rect is a triangle function, which, because your array is so small, wreaks havoc on your values. With much larger arrays, it won't be as noticeable.
1 Comment
Felix Wong
on 17 Sep 2017
Categories
Find more on 傅里叶分析和滤波 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!