Rowan-Classes/6th-Semester-Spring-2024/DSP/Labs/Lab-02/lab-02-5.py
2024-02-22 14:22:36 -05:00

24 lines
410 B
Python

import numpy as np
import matplotlib.pyplot as plt
def x(n):
return (1/n) * np.heaviside(n, 0.5)
n = np.arange(1,100)
y = x(n)
E_x_total = 0
E_x = np.zeros(len(y))
for i in range(len(y)):
E_x_total += abs(y[i])**2
E_x[i] = E_x_total
fig, ax = plt.subplots()
ax.scatter(n,y, label="x[n]")
ax.scatter(n, E_x, c='red', label="E_x")
ax.axhline(np.pi**2 / 6, linestyle='-')
ax.legend()
plt.show()