How do I compute impulse response?

13 Ansichten (letzte 30 Tage)
mustafa mutlu
mustafa mutlu am 9 Jan. 2016
Beantwortet: Sheela am 29 Nov. 2024 um 5:07
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 Kommentar
Arundhathi
Arundhathi am 5 Nov. 2024

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()

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 9 Jan. 2016
Bearbeitet: MathWorks Support Team am 22 Mai 2019
You can use the filter function with the coefficients as an input argument.

Weitere Antworten (3)

Lachhmi
Lachhmi am 29 Nov. 2024 um 5:05

% Define the range of x values x = linspace(-10, 10, 1000);

% Compute the corresponding y values for 2x + 8 y = abs(2*x + 8);

% Plot the graph figure; plot(x, y); xlabel('x'); ylabel('|2x + 8|'); title('Plot of y = 2x + 8'); grid on;


Lachhmi
Lachhmi am 29 Nov. 2024 um 5:06

% Define the range of x values x = linspace(-10, 10, 1000);

% Compute the corresponding y values for 2x + 8 y = abs(2*x + 8);

% Plot the graph figure; plot(x, y); xlabel('x'); ylabel('|2x + 8|'); title('Plot of y = 2x + 8'); grid on;


Sheela
Sheela am 29 Nov. 2024 um 5:07

% Define the range of x values x = linspace(-10, 10, 1000);

% Compute the corresponding y values for 2x + 8 y = abs(2*x + 8);

% Plot the graph figure; plot(x, y); xlabel('x'); ylabel('|2x + 8|'); title('Plot of y = 2x + 8'); grid on;

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by