DK'
DK'
1)Check whether these signals are linear or not y[n]=2x[n]+5 ; x1[n]=[1,-2,1,3]; x2[n]=[2,3,4,5] and
the constants for weighted sum are a=2;b=3.
Program:
import numpy as np
import matplotlib.pyplot as plt
#CB.EN.U4CCE24015
def system(x):
return 2 * x + 5
a, b = 2, 3
x_sum = x1 + x2
y_sum_combined = system(x_sum)
y_sum_individual = system(x1) + system(x2)
x_scaled = a * x1
y_scaled_combined = system(x_scaled)
y_scaled_individual = a * system(x1)
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.plot(y_sum_combined, label="System(x1 + x2)", marker='o')
plt.plot(y_sum_individual, label="System(x1) + System(x2)", marker='x')
plt.title("Additivity Test CB.EN.U4CCE24015")
plt.xlabel("n")
plt.ylabel("y[n]")
plt.legend()
plt.grid()
plt.subplot(1, 2, 2)
plt.plot(y_scaled_combined, label="System(a * x1)", marker='o')
plt.plot(y_scaled_individual, label="a * System(x1)", marker='x')
plt.title("Homogeneity Test CB.EN.U4CCE24015")
plt.xlabel("n")
plt.ylabel("y[n]")
plt.legend()
plt.grid()
plt.tight_layout()
plt.show()
23CCE183 Signal Processing Laboratory
Inference:
Output:
2)Check Time-Invariance for the given signal y[n]=n*[n];x=[1,-2,1,3], use the constant k=10 to check
for time-shift.
Program:
import numpy as np
import matplotlib.pyplot as plt
#CB.EN.U4CCE24015
def system_time_variant(x, n):
return n * x
x = np.array([1, -2, 1, 3])
n = np.arange(len(x))
k=2
original_response = system_time_variant(x, n)
x_shifted = np.roll(x, k)
n_shifted = n + k
shifted_response = system_time_variant(x_shifted, n_shifted)
system_response_shifted = np.roll(original_response, k)
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.stem(n, x, linefmt='b-', markerfmt='bo', basefmt=" ", label="Original Input")
plt.stem(n, np.roll(x, k), linefmt='r--', markerfmt='rx', basefmt=" ", label=f"Shifted Input (k={k})")
plt.title("Input Signals CB.EN.U4CCE24015")
plt.xlabel("n")
23CCE183 Signal Processing Laboratory
plt.ylabel("x[n]")
plt.legend()
plt.grid()
plt.subplot(1, 2, 2)
plt.stem(n, original_response, linefmt='b-', markerfmt='bo', basefmt=" ", label="Original Response")
plt.stem(n, shifted_response, linefmt='r--', markerfmt='rx', basefmt=" ", label="Response to Shifted
Input")
plt.stem(n, system_response_shifted, linefmt='g-.', markerfmt='gx', basefmt=" ", label="Shifted
System Response")
plt.title("System Responses CB.EN.U4CCE24015")
plt.xlabel("n")
plt.ylabel("y[n]")
plt.legend()
plt.grid()
plt.tight_layout()
plt.show()
Inference:
Output: