Introdutction
The Python numpy.convolve() function is used to return a discrete, linear convolution of two one-dimensional sequences. The NumPy method convolve() takes three arguments which are arr, arr1 and mode. The convolution operator is often used in signal processing, where it models the effect of a time-invariant linear system on a signal.
The convolution of two vector sequences can be implemented as a multiplication of two matrices. It is used in the channel degradation simulation of the time domain transmission sequence such as OFDM/OFDMA waveforms. For LTI (Linear Time Invariant) system, channel impulse response (say h[n]) and input sequence (say x[n]) can be convolved to get output sequence (say y[n]).
Python Script – Convolution
import numpy as np
import matplotlib.pyplot as plt
#Inputs as complex numbers
#x = np.random.normal(size=3) + 1j * np.random.normal(size=3) # normal random complex vectors
#h = np.random.normal(size=4) + 1j * np.random.normal(size=4) # normal random complex vectors
#Inputs as real numbers
x = [20,31,56] #Time domain sequence say in OFDM Transmitter
h = [10,2,5,8] #Time domain channel impulse response
L = len(x) + len(h) - 1 # length of convolution output
#Method-1 : Python convolution function from NumPy module
y3 = np.convolve(h, x)
print("y3=", y3)
#Method-2 : Convolution using Brute-force method
N = len(x)
M = len(h)
y = np.zeros(L) # array filled with zeros
for i in np.arange(0,N):
for j in np.arange(0,M):
y[i + j] = y[i + j] + x[i] * h[j]
print("y=",y)
#Difference between NumPy module and Brute-force method
y2 = y-y3
# Initialise the subplot function using number of rows and columns
figure, axis = plt.subplots(2, 2)
# For Built in convolution
axis[0,0].plot(y3)
axis[0,0].set_title("Method # 1 : np.convolve")
# For Our own function
axis[0,1].plot(y)
axis[0,1].set_title("Method # 2 : Brute-force method")
#Difference between two
axis[1, 0].plot(y2)
axis[1, 0].set_title("Difference between both methods")
plt.show()
Input – Real Numbers
x = [20,31,56] #Time domain sequence say in OFDM Transmitter
h = [10,2,5,8] #Time domain channel impulse response
Input – Complex Numbers
#x = np.random.normal(size=3) + 1j * np.random.normal(size=3) # normal random complex vectors
#h = np.random.normal(size=4) + 1j * np.random.normal(size=4) # normal random complex vectors
Output – Real Numbers
Output – Complex Numbers