-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-dead-zone-quantification-reconstruction.py
72 lines (59 loc) · 1.26 KB
/
no-dead-zone-quantification-reconstruction.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python3
import random
import matplotlib.pyplot as plt
import numpy as np
samples = 5000
display = 0
figure_number = 1
def plot_fig (x : list ,y: list ):
#plotting
global figure_number
plt.figure(figure_number )
plt.plot(x,y,'+')
figure_number += 1
def main():
Xm = 4
R = 2
M = 2**R
vector =[]
for x in range(0,samples):
#vector.append(random.gauss(0,1/3*Xm*Xm)/Xm)
vector.append(random.uniform(-Xm,Xm))
N =np.linspace(0,samples,samples)
if display:
plot_fig (N,vector)
delta = 2*Xm/M
intervals = [-Xm + i*delta for i in range(0,M+1) ]
vector.sort()
qx =[]
for x in vector :
if x < -Xm :
qx.append(0)
elif x > Xm :
qx.append(M-1)
else :
for i in range(1,len(intervals)) :
if x >= (intervals[i]- delta) and x <= intervals[i] :
qx.append(i-1)
if display:
N =np.linspace(-Xm,Xm,samples)
plot_fig(N,qx)
Qx =[]
for value in qx :
Qx.append(value*1/2*Xm +(-3/4*Xm))
if display:
plot_fig(N,sorted(Qx))
distance =[]
for i in range(0,len(Qx)):
distance.append(vector[i]-Qx[i])
if display:
plot_fig(N,distance)
varianceX = 1/3*Xm**Xm
distortion =[]
for i in range(0,10):
distortion.append(varianceX*(2**(-2*i)))
if display :
plot_fig(range(0,10),distortion);
if display :
plt.show()
main()