I am trying to understand the FTT and convolution (cross-correlation) theory and for that reason I have created the following code to understand it. The code is Matlab/Octave, however I could also do it in Python.
In 1D:
x = [5 6 8 2 5];
y = [6 -1 3 5 1];
x1 = [x zeros(1,4)];
y1 = [y zeros(1,4)];
c1 = ifft(fft(x1).*fft(y1));
c2 = conv(x,y);
c1 = 30 31 57 47 87 47 33 27 5
c2 = 30 31 57 47 87 47 33 27 5
In 2D:
X=[1 2 3;4 5 6; 7 8 9]
y=[-1 1];
conv1 = conv2(x,y)
conv1 =
24 53 89 29 21
96 140 197 65 42
168 227 305 101 63
Here is where I find the problem, padding a matrix and a vector? How should I do it? I could pad x
with zeros around? or just on one side? and what about y
? I know that the length of the convolution should be M+L-1
when x
and y
are vectors, but what about when they are matrices?
How could I continue my example here?