2.71 Circular convolution of two sequences

2.71.1 example 1. The sequences are of equal length
2.71.2 example 2. The sequences are of unequal length

Problem: Given 2 sequences \(x_{1}[n]\) and \(x_{2}[m]\), determine the circular convolution of the 2 sequences.

2.71.1 example 1. The sequences are of equal length

Mathematica

x1 = {2, 1, 2, 1}; 
x2 = {1, 2, 3, 4}; 
X1 = Chop[Fourier[x1, FourierParameters -> {1, -1} ]]; 
X2 = Chop[Fourier[x2, FourierParameters -> {1, -1}]]; 
Re[InverseFourier[X1*X2, FourierParameters -> {1, -1}]]
 

{14., 16., 14., 16.}
 

 

Matlab

clear all; close all; 
x1=[2 1 2 1]; 
x2=[1 2 3 4]; 
X1=fft(x1); 
X2=fft(x2); 
y=real(ifft(X1.*X2))
 

y = 
    14    16    14    16
 

 

Maple

Note: had to figure the correct normalization to get same answer as Matlab. Also, the input has to be type Array. list is not accepted.

x1 := Array([2, 1, 2, 1]); 
x2 := Array([1,2,3,4]); 
X1:=SignalProcessing:-FFT(x1,'normalization'='none'); 
X2:=SignalProcessing:-FFT(x2,'normalization'='none'); 
SignalProcessing:-InverseFFT(X1.X2,'normalization'='full'); 
Re(%)
 

\[ \left [\begin {array}{cccc} 14.0 & 16.0 & 14.0 & 16.0 \end {array}\right ] \]

 

2.71.2 example 2. The sequences are of unequal length

Mathematica

Clear["Global`*"] 
x1 = {1, 2, 3, 4, 5}; 
x2 = {4, 5, 6}; 
x2 = Append[x2, {0, 0}] // Flatten; 
X1 = Chop[Fourier[x1, FourierParameters -> {1, -1} ]]; 
X2 = Chop[Fourier[x2, FourierParameters -> {1, -1}]]; 
Re[InverseFourier[X1*X2, FourierParameters -> {1, -1}]]
 

{53., 43., 28., 43., 58.}
 

 

Matlab

x1=[1 2 3 4 5]; 
x2=[4 5 6]; 
N=max(length(x1),length(x2)); 
X1=fft(x1,N); 
X2=fft(x2,N); 
y=real(ifft(X1.*X2))
 

y = 
53    43    28    43    58
 

 

Maple

Padding zeros to make the two list same was a little tricky. Find if there is a better way.

x1 := [1,2,3,4,5]; 
x2 := [4,5,6]; 
 
#find max length, and padd the smaller one with zero, so that 
#both lists have same length 
N:= max(numelems(x1),numelems(x2)); 
x1:=`if`(numelems(x1)<N,[op(x1),op([0$(N-numelems(x1))])],x1); 
x2:=`if`(numelems(x2)<N,[op(x2),op([0$(N-numelems(x2))])],x2); 
 
X1:=SignalProcessing:-FFT(convert(x1,Array),'normalization'='none'); 
X2:=SignalProcessing:-FFT(convert(x2,Array),'normalization'='none'); 
SignalProcessing:-InverseFFT(X1.X2,'normalization'='full'); 
Re(%)
 

\[ \left [\begin {array}{ccccc} 53.0 & 43.0 & 28.0 & 43.0 & 58.0 \end {array}\right ] \]