28 lines
485 B
Python
28 lines
485 B
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
n = np.arange(0,200)
|
|
|
|
a = 0.9
|
|
|
|
# x[n] = a^n u[n]
|
|
x = a**n * np.heaviside(n, 1)
|
|
|
|
asums = np.zeros(len(n))
|
|
|
|
for i in range(len(n)):
|
|
asums[i] = np.sum(x[0:i])
|
|
|
|
# Plot settings for $x[n]$
|
|
plt.subplot(121)
|
|
plt.plot(n, x)
|
|
plt.xlabel("$n$")
|
|
plt.ylabel("$x[n]$", rotation="horizontal")
|
|
|
|
# Plot settings for sum of $x[n]$
|
|
plt.subplot(122)
|
|
plt.plot(n, asums)
|
|
plt.xlabel("$n$")
|
|
plt.ylabel("$\sum_n x[n]$", rotation="horizontal")
|
|
plt.show()
|