Guest User

Untitled

a guest
Mar 25th, 2019
56
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pylab import *
  2.  
  3.  
  4. def quantize(val, possible_values):
  5. best_match = None
  6. best_match_difference = 0
  7. for bit_value in possible_values:
  8. difference = abs(bit_value-val)
  9. if best_match is None or difference < best_match_difference:
  10. best_match = bit_value
  11. best_match_difference = difference
  12. print(best_match)
  13. return best_match
  14.  
  15.  
  16. t = arange(0,1, 0.01)
  17. y = sin(2*pi*t)
  18. possible = [-2,-1,0,1]
  19.  
  20. y1 = []
  21. for t1 in y:
  22. y1.append(quantize(t1, possible))
  23.  
  24. subplot(2,1,1)
  25. plot(y)
  26. subplot(2,1,2)
  27. plot(y1)
  28.  
  29. show()
RAW Paste Data