-
Notifications
You must be signed in to change notification settings - Fork 2
/
diff_codec.py
46 lines (34 loc) · 1.01 KB
/
diff_codec.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
import numpy as np
def diff_encode(tx_bin, Nbits, Ndummy):
"""
Differential encoder
Parameters
----------
tx_bin : input binary array
Nbits : number of bits to be transmitted
Ndummy : number of dummy bits to cover any locking delay
Returns
-------
tx_diff : encoded binary array for transmission
"""
# Differential Encoding:
tx_diff = np.zeros(1, dtype=bool)
for i in range(Nbits + Ndummy):
tx_diff = np.append(tx_diff, tx_diff[i]^tx_bin[i])
return tx_diff
def diff_decode(rx_diff, Nbits):
"""
Differential decoder
Parameters
----------
rx_diff : received encoded binary array
Nbits : number of bits to be transmitted
Returns
-------
rx_bin : decoded binary array
"""
rx_bin = np.empty(0, dtype=bool)
Nbits = Nbits-1
for i in range(Nbits):
rx_bin = np.append(rx_bin, rx_diff[i]^rx_diff[i+1]).astype(bool)
return rx_bin