Skip to content

Instantly share code, notes, and snippets.

@linnil1
Last active September 26, 2017 13:48
Show Gist options
  • Save linnil1/98b26746c01685720e7e026274a43fc3 to your computer and use it in GitHub Desktop.
Save linnil1/98b26746c01685720e7e026274a43fc3 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
f = 5 # frequence
A = 10 # amplitude
sf = 50 // f # sampling frequence
t = np.linspace(0, 1/f, 10 * sf)
fun = A * np.sin(f * 2 * np.pi * t)
bit = 12 # bits for coding
Q = A * 2 / ( 2 ** bit - 1) # quantization interval
ADCout = []
for i in range(sf):
code = np.floor((fun[i * 10]) / Q) * Q
ADCout.extend([code] * 10)
plt.rc('text', usetex=True)
plt.plot(t, fun, label=r"10\sin(10\pi t)")
plt.plot(t, ADCout, label="ADCoutput(250Hz)")
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment