forked from vicente-gonzalez-ruiz/scalar_quantization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
43 lines (37 loc) · 1.13 KB
/
common.py
File metadata and controls
43 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''Common stuff.'''
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.axes as ax
def plot_quantizer(x_plot, y_plot, title):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title(title)
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
ax.xaxis.set_label_coords(1,0.40)
ax.xaxis.set_label_text('Input')
ax.yaxis.set_label_coords(0.45,.9)
ax.yaxis.set_label_text('Output')
ticks = np.arange(-8, 9, 1)
ax.set_xticks(ticks)
ax.set_yticks(ticks)
ax.grid()
ax.plot(x_plot, y_plot)
def plot(x, y, xlabel='', ylabel='', title=''):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_title(title)
ax.grid()
ax.xaxis.set_label_text(xlabel)
ax.yaxis.set_label_text(ylabel)
ax.plot(x, y)
plt.show(block=False)
def print_center(x, y, z, n):
offset = (len(x)-n)//2
for i in range(n):
input = int(x[i+offset])
output = int(y[i+offset])
recons = int(z[i+offset])
print(f"{input:>6d} {output:>6d} {recons:>6d}")