This repository was archived by the owner on Mar 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtests.py
69 lines (50 loc) · 2.71 KB
/
tests.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
import unittest
import numpy as np
from ModulationPy.ModulationPy import QAMModem, PSKModem
class TestThing(unittest.TestCase):
def test_QAMModem(self):
""" QAM modem modulation and demodulation tests"""
Ms = [4, 16, 64] # modulation orders
for M in Ms:
print("Modulation order: "+str(M))
# Hard decision, Gray mapping, binary IO
mlpr = int(np.log2(M)) #multiplier
size = mlpr*int(1e4)
msg = np.random.randint(2, size=size)
Modem = QAMModem(M, gray_map=True, bin_input=True, soft_decision = False, bin_output = True)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
# Hard decision, binary mapping, binary IO
Modem = QAMModem(M, gray_map=False, bin_input=True, soft_decision = False, bin_output = True)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
# Hard decision, Gray mapping, non-binary IO
size = int(1e5)
msg = np.random.randint(2, size=size)
Modem = QAMModem(M, gray_map=True, bin_input=False, soft_decision = False, bin_output = False)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
# Hard decision, binary mapping, non-binary IO
Modem = QAMModem(M, gray_map=False, bin_input=False, soft_decision = False, bin_output = False)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
def test_PSKModem(self):
""" PSK modem modulation and demodulation tests"""
Ms = [2, 4, 8, 16, 32] # modulation order
for M in Ms:
print("Modulation order: "+str(M))
# Hard decision, Gray mapping, binary IO
mlpr = int(np.log2(M)) #multiplier
size = mlpr*int(1e4)
msg = np.random.randint(2, size=size)
Modem = PSKModem(M, gray_map=True, bin_input=True, soft_decision = False, bin_output = True)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
# Hard decision, binary mapping, binary IO
Modem = PSKModem(M, gray_map=False, bin_input=True, soft_decision = False, bin_output = True)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
# Hard decision, Gray mapping, non-binary IO
size = int(1e5)
msg = np.random.randint(2, size=size)
Modem = PSKModem(M, gray_map=True, bin_input=False, soft_decision = False, bin_output = False)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
# Hard decision, binary mapping, non-binary IO
Modem = PSKModem(M, gray_map=False, bin_input=False, soft_decision = False, bin_output = False)
np.testing.assert_array_equal(msg, Modem.demodulate(Modem.modulate(msg)))
if __name__ == '__main__':
unittest.main()