How do I compute impulse response?

조회 수: 8 (최근 30일)
mustafa mutlu
mustafa mutlu 2016년 1월 9일
댓글: Walter Roberson 2025년 2월 16일
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일

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.
  댓글 수: 1
mustafa mutlu
mustafa mutlu 2016년 1월 10일
thank you for your contribution

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Akkinapalli
Akkinapalli 2025년 1월 6일
편집: Walter Roberson 2025년 2월 16일
Xt=2sin5t
x^2=5sin10t
X^3=10sin20t
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 2월 16일
This is not valid MATLAB syntax. There is no implied multiplication in MATLAB, so 2sin5t is not permitted syntax. Also, sin needs to be called as a function, such as sin(5*t)
It is also not valid to have an expression on the left hand side of an = statement.
The closest to those statements that you could get in MATLAB would be
syms t Xt x X
Xt == 2*sin(5*t)
ans = 
x^2 == 5*sin(10*t)
ans = 
X^3 == 10*sin(20*t)
ans = 
This will not have much effect, as it is a series of equations and it is not assigning the equations to variables.

댓글을 달려면 로그인하십시오.


Ali
Ali 2025년 2월 15일
a=5; , x=2; , y=8;
y=exp(1)*sin(x)+10*sqrt(x)
  댓글 수: 1
Walter Roberson
Walter Roberson 2025년 2월 16일
This does not appear to have anything to do with the Question.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Single-Rate Filters에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by