Confusion about convolution theorem in matlab

12 views (last 30 days)
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
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)

Sign in to comment.

Accepted Answer

Matt J
Matt J on 16 Sep 2017
Edited: Matt J on 16 Sep 2017
There are differences between the continuous-domain convolution theorem and the discrete one. In particular, the discrete domain theorem says that ifft(fft(A).*fft(B)) gives the circulant convolution of A with B. You can get obtain a linear convolution result from a circulant convolution if you do sufficient zero-padding:
>> ifft(fft(A,5).*fft(A,5),5)
ans =
0.4900 0.2800 0.1800 0.0400 0.0100
  5 Comments
Image Analyst
Image Analyst on 18 Sep 2017
Every time you convolve A with something, it adds a length of A to the something. So A**A is twice as long A**(A**A) is 3 times as long, etc. Don't do the padding yourself or else it will be even longer. Just specify the 'full' option in conv() or conv2() and it will enlarge the array by the correct amount for you.
Felix Wong
Felix Wong on 19 Sep 2017
Edited: Felix Wong on 19 Sep 2017
Thanks @Image Analyst. I have tried that, and using default 'full' option.
I believe it is related to FFT in the synax 'fft(A,n)'. An improperly n will result some misleading result for ifft(fft(A,n).*fft(A,n),n).
Since B=conv(A,A) has a length 2L-1 (given length of A is L), I guess n should be set to no less than 2L-1. I am not sure if it is correct?

Sign in to comment.

More Answers (1)

Image Analyst
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
Felix Wong on 17 Sep 2017
Thank you for the answer.
Actually, I am trying to calculate N times convolution of an input vector A of length L, by using FFT algorithm. The length L is relatively small. I am not sure if your suggestions can work for my situation, since discrete FFT method will truncate vectors.

Sign in to comment.

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!