2023-07-28

2023-07-28  本文已影响0人  芜青子
import numpy as np
import matplotlib.pyplot as plt

# Define the magnitudes and frequencies of the sinusoids
A1 = 1
A2 = 1
freq1 = 500  # Hz
freq2 = 3250  # Hz

# Define the sampling rate and sampling period
sampling_rate = 2000  # Hz
T = 1 / sampling_rate

# Define the time range for plotting the discrete-time signal x[n]
n = np.arange(0, 100)  # We'll consider 100 samples

# Calculate the discrete-time signal x[n]
x_n = A1 * np.cos(2 * np.pi * freq1 * n * T) + A2 * np.cos(2 * np.pi * freq2 * n * T)

# Define the impulse response h[n]
# The impulse response h[n] is a band-limited function that is 1 when |n| <= N and 0 otherwise.
N = int(np.pi / (2 * np.pi * T))  # N = π / (2π/T) = π / (2π * 1/2000) = 1000 samples
h_n = np.zeros_like(n)
h_n[:N+1] = 1

# Convolve x[n] with h[n] to get the output sequence y[n]
y_n = np.convolve(x_n, h_n)[:len(n)]

# Plot the output sequence y[n]
plt.stem(n, y_n, use_line_collection=True)
plt.xlabel('n')
plt.ylabel('y[n]')
plt.title('Output Sequence y[n] of the LTI System')
plt.grid()
plt.show()

上一篇 下一篇

猜你喜欢

热点阅读