Py 3
Py 3
Unsolved Problem
Problem 4: Compute the convolution of the following discrete time
sequences x1[n]=[0,1,0,1,0,1] x2[n]=[1,0,0,0]
import numpy as np
import matplotlib.pyplot as plt
x1 = [0, 1, 0, 1, 0, 1]
x2 = [1, 0, 0, 0]
result = np.convolve(x1, x2)
l1 = np.size(x1)
l2 = np.size(x2)
n = np.arange(0, l1 + l2 - 1, 1)
plt.stem(n, result, linefmt='g-',markerfmt='ro', use_line_collection=True)
plt.xlabel('n')
plt.ylabel('x1[n] * x2[n]')
plt.title('Convolution of x1 and x2__22102088')
plt.show()
PostLab
Exercise Problem 1: Compute the convolution of x1[n]=u[n]-u[n-3] and
x2[n]=u[n]-u[n-2].
def u(n):
return np.where(n >= 0, 1, 0)
n = np.arange(-5, 10)
x1 = u(n) - u(n - 3)
x2 = u(n) - u(n - 2)
result = np.convolve(x1, x2)
n_result = np.arange(n[0] + n[0], n[-1] + n[-1] + 1)
plt.stem(n_result, result,linefmt='g--', markerfmt='rx',
use_line_collection=True)
plt.xlabel('n')
plt.ylabel('x1[n] * x2[n]')
plt.title('Convolution Result__22102088')
plt.show()
Result :