0
Discrete-Time Signal Representation
x1[n] is made of random 8 digits for -3 <= n <= 4 and zero is elsewhere. can anybody help me create this in python?
6 odpowiedzi
+ 2
import numpy as np
import matplotlib.pyplot as plt
# Define the discrete-time index range
n_min, n_max = -3, 4
n = np.arange(n_min, n_max + 1) # Generate discrete-time indices
# Generate random values for x1[n] within the given range
x1 = np.random.randint(0, 10, size=len(n)) # Random digits (0-9)
# Plot the discrete-time signal
# Remove 'use_line_collection=True' since it's not supported in older Matplotlib versions
plt.stem(n, x1)
plt.xlabel('n')
plt.ylabel('x1[n]')
plt.title('Discrete-Time Signal x1[n]')
plt.grid(True)
plt.show()
# Print the generated sequence
print("n values:", n)
print("x1[n] values:", x1)
n_min, n_max = -3, 4
n = np.arange(n_min, n_max + 1) # Generate discrete-time indices
# Generate random values for x1[n] within the given range
x1 = np.random.randint(0, 10, size=len(n)) # Random digits (0-9)
# Plot the discrete-time signal
# Remove 'use_line_collection=True' since it's not supported in older Matplotlib versions
+ 2
plt.stem(n, x1)
plt.xlabel('n')
plt.ylabel('x1[n]')
plt.title('Discrete-Time Signal x1[n]')
plt.grid(True)
plt.show()
# Print the generated sequence
print("n values:", n)
print("x1[n] values:", x1)
+ 2
Muhammad Abdul Wasea's code, modified for Sololearn.
https://sololearn.com/compiler-playground/c9e6183fwCj7/?ref=app
+ 2
Bob_Li good 👍
+ 1
It is tested in Google colabs
0
Thanks !