Lab Activity 5
Lab Activity 5
I. Objective
a. To explore the Time Scaling Property and Area Property of convolution using
Python for Linear Time-Invariant (LTI) systems..
II. Lab Activity Procedures
A. Necessary libraries
Familiarity with Python and libraries like NumPy and Matplotlib.
a. This part will focus on verifying this property by convolving two signals and scaling
one of them.:
i. X1(t) = u(t), rectangular function
ii. X2(t) = rect (t), rectangular pulse
iii. Code 1: Convolution of Unit Step and Scaled Rectangular Pulse
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import convolve
# Time vector
t = np.linspace(-5, 5, 1000)
# Original signals
x1 = unit_step(t)
x2 = rect(t)
# Scaled signals
x2_scaled = rect(t / a)
# Plotting
plt.figure(figsize=(12, 8))
plt.subplot(3, 1, 1)
plt.plot(t, x1, label='x1(t) = u(t)')
plt.plot(t, x2_scaled, label='x2(t) = rect(t/a)')
plt.title('Original and Scaled Signals')
plt.legend()
plt.subplot(3, 1, 2)
plt.plot(t, conv_original, label='Convolution: x1(t) * rect(t)')
plt.title('Convolution of Original Signals')
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(t, conv_scaled_adjusted, label='Scaled Convolution (1/a *
Convolution)')
plt.plot(t, conv_scaled, label='Convolution of Scaled Signals',
linestyle='dashed')
plt.title('Verification of Time Scaling Property')
plt.legend()
plt.tight_layout()
plt.show()
Conditions of Code:
1. Signal Definition define a unit step function u(t) and a rectangular pulse rect(t).
2. Time Scaling scale the time of the signals by a factor of a=2.
3. Convolution perform the convolution of the original signals and compare it with the
convolution of the time-scaled signals, verifying the time scaling property.
4. In the section where you are adjusting the convolution for the time scaling property, check if
you're correctly applying the scaling factor. Remember, the time scaling factor 𝑎 plays a
specific role in adjusting the output.
iv. Code 2: Convolution of Unit Step and Scaled Exponential
# Exponential function
def exp_decay(t, a):
return np.where(t >= 0, np.exp(-a * t), 0)
# Original signals
x1 = unit_step(t)
x2 = exp_decay(t, 1)
# Plotting
plt.figure(figsize=(12, 8))
plt.subplot(3, 1, 1)
plt.plot(t, x1, label='x1(t) = u(t)')
plt.plot(t, x2_scaled, label='x2(t) = exp(-at) u(t)')
plt.title('Original and Scaled Signals')
plt.legend()
plt.subplot(3, 1, 2)
plt.plot(t, conv_original, label='Convolution: x1(t) * exp(-t)')
plt.title('Convolution of Original Signals')
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(t, conv_scaled_adjusted, label='Scaled Convolution (1/a *
Convolution)')
plt.plot(t, conv_scaled, label='Convolution of Scaled Signals',
linestyle='dashed')
plt.title('Verification of Time Scaling Property')
plt.legend()
plt.tight_layout()
plt.show()
Conditions:
1. Take a close look at the time scaling factor when generating the scaled exponential signal.
The exponent should reflect the correct time-scaling factor 𝑎. The scaling of the signal
itself should be consistent with the original definition of the exponential.
# Convolution of x1 and x2
conv_area = convolve(x1_area, x2_area, mode='same') * (t[1] - t[0])
# Plotting
plt.figure(figsize=(12, 6))
plt.subplot(3, 1, 1)
plt.plot(t, x1_area, label='x1(t) = rect(t)')
plt.title('First Rectangular Pulse')
plt.legend()
plt.subplot(3, 1, 2)
plt.plot(t, x2_area, label='x2(t) = rect(t)')
plt.title('Second Rectangular Pulse')
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(t, conv_area, label='Convolution: x1(t) * x2(t)')
plt.title('Convolution of Two Rectangular Pulses')
plt.legend()
plt.tight_layout()
plt.show()
Conditions:
1. We define a triangular pulse tri(t) and a rectangular pulse rect(t).
2. The areas of the individual signals are computed using numerical integration (np.trapz),
and we check if the area of the convolution equals the product of these areas.
3. When calculating the area of a function using numerical integration (np.trapz), ensure
you’re accounting for the sign of the values. Areas should always be positive unless
there's a specific reason to expect a negative result. Consider whether taking the absolute
value of the areas might be necessary for a more accurate result.
# Convolution of x1 and x2
conv_area = convolve(x1_area, x2_area, mode='same') * (t[1] - t[0])
# Plotting
plt.figure(figsize=(12, 6))
plt.subplot(3, 1, 1)
plt.plot(t, x1_area, label='x1(t) = tri(t)')
plt.title('Triangular Pulse')
plt.legend()
plt.subplot(3, 1, 2)
plt.plot(t, x2_area, label='x2(t) = rect(t)')
plt.title('Rectangular Pulse')
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(t, conv_area, label='Convolution: x1(t) * x2(t)')
plt.title('Convolution of Triangular and Rectangular Pulse')
plt.legend()
plt.tight_layout()
plt.show()
Conditions:
1. When calculating the area of the convolution result, are you using the right function to
compute the integral? You should be using a method that approximates the area under a
curve. Summing the values directly isn’t always an accurate way to compute the area, so
consider using an integration function that accounts for the continuous nature of the signal.
III. Reminders:
a. Progress Report Hierarchy (Code 1, Code 2, Code 3, Code 4)
i. TS Property
1. Plots Code 1
2. Plots Code 2
3. Correction made for 1
4. Correction made for 2
5. Explanation if the property is fulfilled by the corrected codes.
6. Code (softcopy)
Note: Accomplish item 1-5 in handwriting. On BB, attach your checked output then include the
code -on the last part in one PDD File only for your progress report.