-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.py
More file actions
55 lines (40 loc) · 1.42 KB
/
example.py
File metadata and controls
55 lines (40 loc) · 1.42 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
import math
import MIMO_GrayCode_Modulation as mgm
import numpy as np
def main():
# Simulation parameters
complex_model = True # True: complex baseband model; False: real-valued equivalent model (I/Q stacked)
M = 16 # Number of transmit/receive antennas
Q = 64 # Modulation level per antenna
K = 1024 # Symbol length
SNR_dB = 20 # SNR [dB]
nloops = 100 # Number of loops
# Create modulator instance
mod = mgm.Modulator(Q, complex_model)
# Calculate noise level
SNR = 10.0 ** (SNR_dB / 10.0)
N0 = 1.0 / SNR
sigma_noise = math.sqrt(N0 / 2.0)
BE = 0
for _ in range(nloops):
# Generate transmitted bit sequence
bits = mod.gen_bits(M, K)
# Modulate
X = mod.modulate(bits)
# AWGN channel
if complex_model:
# Complex model
Z = (np.random.normal(0.0, sigma_noise, size=[M, K])
+ 1j * np.random.normal(0.0, sigma_noise, size=[M, K])) # fmt: skip
else:
# Real number equivalent model
Z = np.random.normal(0.0, sigma_noise, size=[2 * M, K])
Y = X + Z
# Demodulate
bits_hat = mod.demodulate(Y)
# Count bit errors for this iteration
BE += (bits != bits_hat).sum()
BER = BE / (nloops * K * M * math.log2(Q))
print("BER =", BER)
if __name__ == "__main__":
main()