how to evaluate a convolution integral by fast fourier transform

7 views (last 30 days)
I need to evaluate a convolution integral by fft. Therefore, I have read somewhere in a paper to first zero-pad two multiplying functions and wrap around one of them. Then, an element-by-element multiplication and inverse transforming back to the spacial domain and then removing the elements corresponding to the added zeros will solve the problem. To give it a try, I started with a simple example. Consider f(x)=1 (for -1<x<1) and 0 (elsewhere). Also, g(x)=1-x.^2 (for -1<x<1) and 0 (elsewhere). I have calculated the convolution integral analytically to compare with my code results. However, my code does not provide acceptable results especially on boundaries. Also, I don't think I know and understand zero-padding and wrapping around order. Can anyone help me with this, please? Here is the simple code I have written:
clc
clear all
% the analytical result
d=[...
-0.6667
-0.2678
0.0868
0.3970
0.6630
0.8846
1.0619
1.1948
1.2835
1.3278
1.3278
1.2835
1.1948
1.0619
0.8846
0.6630
0.3970
0.0868
-0.2678
-0.6667];
hold on
plot(linspace(-1,1,20)',d,'o')
N=pow2(10);
dx=2/N;
x=linspace(-1,1,N);
x=x';
f=[1-x.^2;zeros(N,1)];
Ff=fft(f);
g=[ones(N,1);zeros(N,1)];
Fg=fft(g);
FG=Ff.*Fg;
fg=2/N*ifft(FG);
plot(x,fg(N/2+1:3/2*N))

Accepted Answer

David Young
David Young on 3 Jul 2015
Correct zero-padding to use the FFT for 1-D or 2-D convolutions is implemented in my FEX submission 2-D convolution using the FFT.
  1 Comment
bazrafshan88@gmail.com
bazrafshan88@gmail.com on 6 Jul 2015
Thank you David
But your code doesn't provide the accurate results, either. If you perform your conv_fft2 command in my simple example, you will see the difference.

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering 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!