18 lines
No EOL
508 B
Python
18 lines
No EOL
508 B
Python
# codebook.py
|
|
import numpy as np
|
|
|
|
def generate_Br(r):
|
|
if r == 0:
|
|
return np.array([[1]])
|
|
M = generate_Br(r - 1)
|
|
top = np.hstack((M, M))
|
|
bottom = np.hstack((M, -M))
|
|
return np.vstack((top, bottom))
|
|
|
|
def construct_codebook(r, Eb):
|
|
Br = generate_Br(r)
|
|
n = 2 * Br.shape[1] # Since codeword is [Br | Br]
|
|
m = Br.shape[0] # Number of messages
|
|
alpha = Eb * 2 / ((1 + 10) * n) # G=10
|
|
codebook = np.sqrt(alpha) * np.hstack((Br, Br))
|
|
return codebook, n, m, alpha |