Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pylab import *
- def quantize(val, possible_values):
- best_match = None
- best_match_difference = 0
- for bit_value in possible_values:
- difference = abs(bit_value-val)
- if best_match is None or difference < best_match_difference:
- best_match = bit_value
- best_match_difference = difference
- print(best_match)
- return best_match
- t = arange(0,1, 0.01)
- y = sin(2*pi*t)
- possible = [-2,-1,0,1]
- y1 = []
- for t1 in y:
- y1.append(quantize(t1, possible))
- subplot(2,1,1)
- plot(y)
- subplot(2,1,2)
- plot(y1)
- show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement