HEMS HEMS - 5 months ago 32
Python Question

How do you quantize a simple input using python

I am using the below codes to quantise the input signal for quantisation interval of 0.5 and this should give me staircase signal.The algorithm used here is same as used in Simulink.Could any one help me plot the quantised signal.

import numpy as np
import matplotlib.pyplot as plt

for i in range(0,10):
q=0.5;
x=q*np.round(i/q);
plt.plot(i,x)
plt.xlim([0,10])
plt.ylim([0,10])
plt.hold()
plt.grid()
plt.show()

Answer

Do you mean something like this?

import numpy as np
import matplotlib.pyplot as plt

q = 0.5
x = np.linspace(0, 10, 1000)
y = q * np.round(x/q)
plt.plot(x,y)

Quantized signal