-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsimple.py
More file actions
43 lines (33 loc) Β· 1.4 KB
/
simple.py
File metadata and controls
43 lines (33 loc) Β· 1.4 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
import numba
import numpy as np
class SimpleBPSKModem:
"""Simple model of BPSK-modem.
Implemented for the comparison with the SC decoder proposed by H. Vangala,
E. Viterbo, and Yi Hong (See `PlotPC and PlotPCSystematic`):
https://ecse.monash.edu/staff/eviterbo/polarcodes.html.
"""
noise_power = 2.0
def __init__(self, fec_rate: float, snr_db: float):
self.fec_rate = fec_rate
self.symbol_energy = self._compute_symbol_energy(snr_db, self.fec_rate)
def modulate(self, message: np.array) -> np.array:
"""BPSK modulation."""
return self._modulate(message, self.symbol_energy)
def demodulate(self, transmitted: np.array) -> np.array:
"""BPSK demodulation."""
return self._llr_detect(transmitted, self.symbol_energy, self.noise_power) # noqa
@staticmethod
@numba.njit
def _compute_symbol_energy(snr_db, fec_rate):
snr = np.power(10, snr_db / 10)
return snr * 2 * fec_rate
@staticmethod
@numba.njit
def _modulate(message: np.array, symbol_energy: float) -> np.array:
"""BPSK modulation."""
return (2 * message - 1) * np.sqrt(symbol_energy)
@staticmethod
@numba.njit
def _llr_detect(signal: np.array, symbol_energy: float, noise_power: float) -> np.array:
"""LLR detection of BPSK signal with AWGN."""
return -(4 * np.sqrt(symbol_energy) / noise_power) * signal