Given two array X[] and H[] of length N and M respectively, the task is to find the circular convolution of the given arrays using Matrix method. Multiplication of the Circularly Shifted Matrix and the column-vector is the Circular-Convolution of the arrays. Examples:
Create a circularly shifted Matrix circular_shift_mat of K * K using the elements of array whose length is maximum(Xn in this case) where K is MAX(N, M).
👁 Image Circularly shifted matrix of the array Xn.
Create a column-vector col_vec of length K
Insert the elements of the array Hm into the col_vec in positions [0, m).
As K = max(N, M), here N; M < K. Therefore fill the rest of the positions of col_vec [m, K) with 0.Therefore the col_vec will be
col_vec = { 1, 1, 1, 0 }
Multiply the circular_shift_mat and the col_vec
Multiplication of the Circularly Shifted Matrix (circular_shift_mat) and the column-vector (col_vec) is the Circular-Convolution of the arrays.
Approach:
Create a Circularly shifted Matrix of N * N using the elements of array of the maximum length.
Create a column-vector of length N using elements of another array and fill up rest of the positions by 0.
Multiplication of Matrix and the column-vector is the Circular-Convolution of arrays.
Below is the implementation of the above approach.
Output:
15 32 38 17
Time Complexity: O(MAX_SIZE * MAX_SIZE) Auxiliary Space: O(MAX_SIZE * MAX_SIZE)