OOK Devices
Use this module to simulate On-Off Keying modulation optical systems.
>>> import opticomlib.ook as ook
Functions
|
Threshold estimator |
|
On-Off Keying Digital Signal Processing |
|
BER Analizer |
|
Calculates the theoretical bit error probability for an OOK system. |
- opticomlib.ook.THRESHOLD_EST(eye_obj: eye)[source]
Threshold estimator
Estimates the decision threshold for OOK from the means and standard deviations of the eye diagram.
- Parameters:
eye_obj (
eye
) – Object with the parameters of the eye diagram.- Returns:
Decision threshold for OOK.
- Return type:
float
Notes
The decision threshold is estimated as the value of amplitud that minimizes the probability of error given the means and standard deviations of the eye diagram. This is done by minimizing the probability function [th]:
\[f(r) = \frac{1}{2} Q\left(\frac{\mu_1 - r}{\sigma_1}\right) + \frac{1}{2} Q\left(\frac{r - \mu_0}{\sigma_0}\right)\]where \(\mu_0\) and \(\mu_1\) are the means of the eye diagram, \(\sigma_0\) and \(\sigma_1\) are the standard deviations and
Q()
is the Q-function.References
[th]Armando Palacio Romeu, “Comunicaciones ópticas entre satélites LEO y GEO”, chapter 2.4. link: https://ricabib.cab.cnea.gov.ar/1143/1/1Palacio_Romeu.pdf
- opticomlib.ook.DSP(input: electrical_signal, BW: float = None)[source]
On-Off Keying Digital Signal Processing
Performs the decision task of the photodetected electrical signal.
If
BW
is provided bessel filter will be applied to the signal (opticomlib.devices.LPF()
)eye diagram parameters are estimated from the input electrical signal with function
opticomlib.devices.GET_EYE()
.it subsamples the electrical signal to 1 sample per bit using function
opticomlib.devices.SAMPLER()
.Then, it compares the amplitude of the subsampled signal with optimal threshold. The optimal threshold is obtained from function
opticomlib.ook.THRESHOLD_EST()
.Finally, it returns the received binary sequence, eye object and optimal threshold.
- Parameters:
input (
electrical_signal
) – Photodetected electrical signal.BW (
float
, optional) – Bandwidth of DSP filter. If not specified, signal won’t be filtered.
- Returns:
output (
binary_sequence
) – Received bits.eye_obj (
eye
) – Eye diagram parameters.rth (
float
) – Decision threshold for OOK.
Examples
from opticomlib.devices import DAC, gv from opticomlib.ook import DSP import numpy as np import matplotlib.pyplot as plt gv(sps=64, R=1e9) x = DAC('01000100100000', 1, pulse_shape='gaussian') x.noise = np.random.normal(0, 0.1, x.len()) y, eye_, xth = DSP(x) x.plot('y', label='Photodetected signal') DAC(y).plot(c='r', lw=2, label='Received sequence') plt.axhline(xth, color='b', linestyle='--', label='Threshold') plt.legend(loc='upper right') plt.show()
(
Source code
,png
,hires.png
,pdf
)
- opticomlib.ook.BER_analizer(mode: Literal['counter', 'estimator'], **kargs)[source]
BER Analizer
Calculates the bit error rate (BER), either by error counting (comparing the received sequence with the transmitted one) or by estimation (using estimated means and variances from the eye diagram and substituting those values into the theoretical expressions).
- Parameters:
mode (
str
) – Mode in which the Bit Error Rate (BER) will be determined.Tx (
binary_sequence
, optional) – Transmitted binary sequence. Required if mode=’counter’.Rx (
binary_sequence
, optional) – Received binary sequence. Required if mode=’counter’.eye_obj (
eye
, optional) – eye object with the estimated parameters of the eye diagram. Required if mode=’estimator’.
- Returns:
BER.
- Return type:
float
Examples
from opticomlib.devices import DAC, gv, binary_sequence from opticomlib.ook import DSP, BER_analizer import numpy as np gv(sps=64, R=1e9) tx = binary_sequence('01000100100000') x = DAC(tx, pulse_shape='gaussian') x.noise = np.random.normal(0, 0.1, x.len()) rx, eye_, xth = DSP(x) BER_count = BER_analizer('counter', Tx=tx, Rx=rx) BER_est = BER_analizer('estimator', eye_obj=eye_) print(f'BER by counting: {BER_count:.1e}') print(f'BER by estimation: {BER_est:.1e}')
Output:
BER by counting: 0.0e+00 BER by estimation: 3.7e-07
- opticomlib.ook.theory_BER(mu1: int | ndarray, s0: int | ndarray, s1: int | ndarray)[source]
Calculates the theoretical bit error probability for an OOK system.
- Parameters:
mu1 (
float
) – Average current (or voltage) value of the signal corresponding to a bit 1.s0 (
float
) – Standard deviation of current (or voltage) of the signal corresponding to a bit 0.s1 (
float
) – Standard deviation of current (or voltage) of the signal corresponding to a bit 1.
- Returns:
Theoretical bit error probability (BER).
- Return type:
float
Notes
The theoretical bit error probability is calculated using the following expression:
\[P_e = \frac{1}{2} \left[Q\left(\frac{\mu_1 - r_{th}}{\sigma_1}\right) + Q\left(\frac{r_{th}}{\sigma_0}\right)\right]\]Examples
>>> from opticomlib.ook import theory_BER >>> theory_BER(mu1=1, s0=0.1, s1=0.1) 2.8674468224390994e-07