0% found this document useful (0 votes)
12 views

Py 3

Uploaded by

priyamnandi900
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Py 3

Uploaded by

priyamnandi900
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 3

Aim: DT Convolution To calculate the convolution sum of two discrete


time signals. [C310.2]

Theory: Convolution is a mathematical operation used to express the


relation between input and output of an LTI system. It relates input,
output and impulse response of an LTI system. The discrete time
convolution of two sequences can be defined as x[n] ∗ h[n]= ∑∞ x[k]h[n
− k]

Problem 1: Compute the convolution of the following discrete time


sequences x1=([1.0, 2.0, 3.0]) x2=([0.0, 1.0, 0.5,1.0])

import matplotlib.pyplot as plt


import numpy as np
x1=([1.0, 5.0, 3.0])
x2=([0.0, -2.0, 0.5,1.0])
convolution =np.convolve(x1,x2)
plt.stem( convolution, linefmt='g--', markerfmt='rx',
use_line_collection=True)
plt.xlabel('n')
plt.ylabel('x1[n]*x2[n]')
plt.title('DT Convolution__22102088')
plt.show()

Problem 2: Compute the convolution of the following discrete time


sequences x1=([-1.0, 2.0, -3.0]) x2=([0.0, -1.0, 0.5,1.0])

x1=([-2.0, 2.0, -4.0])


x2=([0.0, -1.0, 1, 2.0, 3.0])
convolution =np.convolve(x1,x2 )
l1 = np.size(x1)
l2 = np.size(x2)
n=np.arange(0,l1+l2-1,1)
plt.stem(n,convolution, linefmt='g-
',markerfmt='yo',use_line_collection = True)
plt.xlabel('n')
plt.ylabel('x1[n]*x2[n]')
# Title to plot
plt.title('DT Convolution__22102088')
plt.show()

Problem 3: Compute the convolution of the following discrete time


sequences x1[n1]=([-1.0, 2.0, -3.0]), n1 =-1 to 1 x2[n2]=([0.0, -1.0,
0.5,1.0]), n2 = ([-2, -1, 0, 1])

x1=([-1.0, 2.0, -3.0])


x2=([0.0, -1.0, 0.5])
n1=([-1,0,1])
n2=([-2,-1,0,1])
c=np.convolve(x1,x2 )
l1 = np.size(x1)
l2 = np.size(x2)
n=np.arange(n1[0]+n2[0],n1[-1]+n2[-1],1)
plt.stem(n, c, linefmt='g--', markerfmt='rx',
use_line_collection=True)
plt.xlabel('n')
plt.ylabel('x1[n]*x2[n]')
plt.title('DT Convolution__22102088')
plt.show()

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

Learning Outcome : Develop proficiency in calculating the convolution sum of


discrete-time signals using Python or MATLAB.

Result :

• The study illustrated the convolution operation applied to discrete-time


sequences and analyzed its effect on the resultant signal.
• Different input sequences were used to showcase how the convolution
operation alters the resulting signal, with visual plots provided to detail the
variations in the output.

You might also like