Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- # Number 1
- def x(n):
- return n * (np.heaviside(n + 4, 1) - np.heaviside(n - 5, 1))
- def delta(n):
- if n.any == 0: # Not right but whatever
- return 1
- else:
- return 0
- # Set scale
- n = np.arange(-10, 11)
- # Plot part a-d,g
- plt.stem(n, x(n) * delta(n), markerfmt="k.", linefmt="k", basefmt="k")
- plt.title("Signal x[n]$\delta$[n]")
- plt.xlabel(r"Index n where -10$\leq$n$\leq$10")
- plt.xticks([-10, -5, 0, 5, 10])
- plt.ylabel("Amplitude")
- plt.show()
- # Number 1 part e
- f = x(n / 2) * ((n + 1) % 2)
- plt.stem(n, f, markerfmt="k.", linefmt="k", basefmt="k")
- plt.title("Signal x[n/2], if n/2 is an integer")
- plt.xlabel(r"Index n where -10$\leq$n$\leq$10")
- plt.xticks([-10, -5, 0, 5, 10])
- plt.ylabel("Amplitude")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement