VOOZH about

URL: https://www.geeksforgeeks.org/dsa/circular-convolution-using-matrix-method/

⇱ Circular Convolution using Matrix Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Circular Convolution using Matrix Method

Last Updated : 26 Nov, 2021

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: 
 

Input: X[] = {1, 2, 4, 2}, H[] = {1, 1, 1} 
Output: 7 5 7 8
Input: X[] = {5, 7, 3, 2}, H[] = {1, 5} 
Output: 15 32 38 17 
 


Explanation: 
 

  • 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)
 

Comment
Article Tags: