-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
68 lines (49 loc) · 1.77 KB
/
example.py
File metadata and controls
68 lines (49 loc) · 1.77 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
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
import numpy as np
from pyadess import AdEss
num_data_bits = 15
sequence_length = 10
distribution = [ # Probabilities for the amplitudes 1, 3, 5, 7
0.1, # P(1)
0.2, # P(3)
0.3, # P(5)
0.4 # P(7)
]
res_factor = 5 # Resolution factor for calculating the weights from the distribution
adess = AdEss.new_for_distribution_num_bits(
num_data_bits,
sequence_length,
distribution,
res_factor
)
print()
print(f'Created a new AdESS instance which maps {adess.num_data_bits()} bits to {sequence_length} amplitudes.')
print(f'Shaping rate: {num_data_bits/sequence_length:.2f} bit/amplitude')
print(f'Average sequence energy: {adess.average_energy()}')
print(f'AD-ESS amplitude distribution: {np.round(adess.amplitude_distribution(), 2)}')
print()
rng = np.random.default_rng(0)
print('# Testing encoding / decoding')
tx_bits = rng.integers(0, 1, size=num_data_bits, endpoint=True)
print('Sent bits:', tx_bits)
tx_sequence = adess.encode(tx_bits)
print('Encoded into amplitudes:', tx_sequence)
rx_sequence = tx_sequence # no noise
rx_bits = adess.decode(rx_sequence)
print('Decoded into bits:', rx_bits)
if np.all(rx_bits == tx_bits):
print('Encode / decode successfull!')
else:
# This should never happen as the channel has no noise
print('Encode / decode failure!')
print()
print('# Testing bulk encoding / decoding')
num_transmissions = 1000
tx_bits = rng.integers(0, 1, size=(num_transmissions, num_data_bits), endpoint=True)
tx_sequence = adess.multi_encode(tx_bits)
rx_sequence = tx_sequence # no noise
rx_bits = adess.multi_decode(rx_sequence)
if np.all(rx_bits == tx_bits):
print(f'Encode / decode of {num_transmissions} transmissions successfull!')
else:
# This should never happen as the channel has no noise
print('Encode / decode failure!')