How to quantize a 2Hz sine wave with 3-bit and plot the error as a graph

I am relatively new to Python and cannot figure out how to quantize a sine wave down to 3-bit with ±3 levels. The number of quantization steps should be adjustable by the parameter level and should be the same in the positive and negative range (level = 3 means 3 steps in the negative range and 3 steps in the negative range and 3 steps in the positive range). The amplitude has to be 1.

This is my code so far:

freq = 2
time = np.arange(0, 1, 0.001) #sample rate of 1000
y = np.sin(2 * np.pi * freq * time)
plt.plot(time, y)
plt.title('sine wave')
plt.grid()
plt.show()
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum