How do I compute impulse response?

14 次查看(过去 30 天)
How can I calculate the impulse response for the following equation:
y[n]=-5*X[n]+2*X[n-1]-5*X[n-2]+2*X[n-3]
  1 个评论
Arundhathi
Arundhathi 2024-11-5,1:16

import numpy as np import matplotlib.pyplot as plt

  1. Define the system equation y[n] = -5*X[n] + 2*X[n-1] - 5*X[n-2] + 2*X[n-3]
  1. Define the length of the signal (let's take a range from n=0 to n=10) n = np.arange(0, 11)
  1. 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
  1. Initialize the output y[n] for the impulse response h = np.zeros_like(n, dtype=float)
  1. 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]
  1. Print the impulse response print("Impulse Response h[n]:") for i in range(len(n)): print(f"h[{n[i]}] = {h[i]}")
  1. 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()

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-1-9
编辑:MathWorks Support Team 2019-5-22
You can use the filter function with the coefficients as an input argument.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Filter Design 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by