-
Notifications
You must be signed in to change notification settings - Fork 2
/
GD_Q.m
43 lines (35 loc) · 837 Bytes
/
GD_Q.m
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
function [quantized,number_of_bits_toSend]=GD_Q(current,prev,bitsToSend)
b=bitsToSend;
tau=1/(2^b-1);
if(b==1)
R=1E-12;
for i=1:length(current)
temp=abs(prev(i)-current(i));
if(temp > R)
R=temp;
end
end
R=R/2;
number_of_bits_toSend =32+32*length(current);
for i=1:length(current)
Q(i)=(current(i)-prev(i)+R)/(2*tau*R);
Q(i)=round(Q(i));
quantized(i)=2*tau*Q(i)*R-R;
number_of_bits_toSend = number_of_bits_toSend + b;
end
else
R=1E-12;
for i=1:length(current)
temp=abs(prev(i)-current(i));
if(temp > R)
R=temp;
end
end
number_of_bits_toSend =32+32*length(current);
for i=1:length(current)
Q(i)=(current(i)-prev(i)+R)/(2*tau*R);
Q(i)=round(Q(i));
quantized(i)=2*tau*Q(i)*R-R;
number_of_bits_toSend = number_of_bits_toSend + b;
end
end