import numpy as np import matplotlib.pyplot as plt
- Define the system equation y[n] = -5*X[n] + 2*X[n-1] - 5*X[n-2] + 2*X[n-3]
- Define the length of the signal (let's take a range from n=0 to n=10) n = np.arange(0, 11)
- Create the impulse response using numpy's delta function delta = np.zeros_like(n, dtype=float) delta[n == 0] = 1 # Impulse signal at n=0
- Initialize the output y[n] for the impulse response h = np.zeros_like(n, dtype=float)
- Compute the impulse response for i in range(len(n)): h[i] = -5 * delta[i] + 2 * delta[i-1] - 5 * delta[i-2] + 2 * delta[i-3]
- Print the impulse response print("Impulse Response h[n]:") for i in range(len(n)): print(f"h[{n[i]}] = {h[i]}")
- Plot the impulse response plt.stem(n, h, use_line_collection=True) plt.title('Impulse Response h[n]') plt.xlabel('n') plt.ylabel('h[n]') plt.grid(True) plt.show()