Multiplication in time domain using 2D circular convolution in frequency domain

4 views (last 30 days)
Hi everyone
I'm trying to do a time domain multiplication using 2D circular convolution in frequency domain. Actually I know how it works in 1D cases. like:
x = [1 2 3 4 5];
y = [4 5 6 7 8];
xy = 1/5*ifft( cconv(fft(x), fft(y), 5));
xy0 = x.*y; both xy and xy0 are the same and this is what I want. However, for a 2D case, cconv is not defined in matlab and I don't know how to perform a multiplication between 2 matrices of the same size using convolution in frequency domain.
Suppose we have the following matrices:
x = [3 5 4; 7 6 1; -1 2 0];
y = [2 7 1; 2 -3 2; 5 6 9];
for sure the command 1/9*ifft2( conv2(fft2(x), fft2(y), 'same')) does not give the same results as x.*y
Can anyone please help me with this problem?
Many thanks in advance

Answers (1)

Vishal Neelagiri
Vishal Neelagiri on 5 Dec 2016
The ability to apply CONV2 by methods other than zero-padding is not available in MATLAB.
However, you can make use of CONV2 with PADARRAY to manually apply 2D convolution with circular repetition, repeating border elements, or mirror reflections of itself.
For example, if you want to convolve the following two matrices:
A = [1:2; 2:3;];
B = [4:6; 5:7; 6:8;];
A =
1 2
2 3
B =
4 5 6
5 6 7
6 7 8
Firstly, expand one of the two matrices with either circular repetition of elements within the dimension, repeating border elements, or mirror reflections of itself using the PADARRAY function.
xLayer = 2;
B_x = padarray(B,[xLayer xLayer],'circular'); % B is expanded with an extra 2 layers of mirror values
B_x =
6 5 5 6 7 7 6
5 4 4 5 6 6 5
5 4 4 5 6 6 5
6 5 5 6 7 7 6
7 6 6 7 8 8 7
7 6 6 7 8 8 7
6 5 5 6 7 7 6
Next, convolve the matrices A and B_x together with CONV2:
C_x = conv2(A,B_x) % CONV2 on replicated mirror values
C_x =
6 17 15 16 19 21 20 12
17 42 37 40 48 53 50 28
15 37 32 35 43 48 45 25
16 40 35 38 46 51 48 27
19 48 43 46 54 59 56 32
21 53 48 51 59 64 61 35
20 50 45 48 56 61 58 33
12 28 25 27 32 35 33 18
Lastly, choose the correct answers:
C_correct = C_x(xLayer+1:end-xLayer, xLayer+1:end-xLayer)
C_correct =
32 35 43 48
35 38 46 51
43 46 54 59
48 51 59 64
  1 Comment
bazrafshan88@gmail.com
bazrafshan88@gmail.com on 6 Dec 2016
Thank you for your response
Actually this is not what I want. I want to do the element by element multiplication of two matrices of the same size through convolution in frequency domain. Say:
x = [3 5 4; 7 6 1; -1 2 0];
y = [2 7 1; 2 -3 2; 5 6 9];
when x and y are both vectors of the same size, it reads:
xy = 1/length(x)*ifft( cconv(fft(x), fft(y), length(x)));
and it gives the same results as x.*y.

Sign in to comment.

Categories

Find more on Get Started with Signal Processing Toolbox 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!