Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. # Number 1
  5. def x(n):
  6.     return n * (np.heaviside(n + 4, 1) - np.heaviside(n - 5, 1))
  7.  
  8.  
  9. def delta(n):
  10.     if n.any == 0:  # Not right but whatever
  11.         return 1
  12.     else:
  13.         return 0
  14.  
  15.  
  16. # Set scale
  17. n = np.arange(-10, 11)
  18.  
  19. # Plot part a-d,g
  20. plt.stem(n, x(n) * delta(n), markerfmt="k.", linefmt="k", basefmt="k")
  21. plt.title("Signal x[n]$\delta$[n]")
  22. plt.xlabel(r"Index n where -10$\leq$n$\leq$10")
  23. plt.xticks([-10, -5, 0, 5, 10])
  24. plt.ylabel("Amplitude")
  25. plt.show()
  26.  
  27. # Number 1 part e
  28. f = x(n / 2) * ((n + 1) % 2)
  29. plt.stem(n, f, markerfmt="k.", linefmt="k", basefmt="k")
  30. plt.title("Signal x[n/2], if n/2 is an integer")
  31. plt.xlabel(r"Index n where -10$\leq$n$\leq$10")
  32. plt.xticks([-10, -5, 0, 5, 10])
  33. plt.ylabel("Amplitude")
  34. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement