Confusion about convolution theorem in matlab
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Felix Wong
el 16 de Sept. de 2017
Editada: Arkaprabho Pal
el 21 de Abr. de 2020
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 comentario
Arkaprabho Pal
el 21 de Abr. de 2020
Editada: Arkaprabho Pal
el 21 de Abr. de 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)
Respuesta aceptada
Matt J
el 16 de Sept. de 2017
Editada: Matt J
el 16 de Sept. de 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 comentarios
Image Analyst
el 18 de Sept. de 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.
Más respuestas (1)
Image Analyst
el 16 de Sept. de 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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!