<jupyter_start><jupyter_text>Equalizers Quickstart[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/remifan/commplax/blob/master/docs/tutorial/equalizers.ipynb)[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/remifan/commplax/HEAD?filepath=docs%2Ftutorial%2Fequalizers.ipynb)  Install dependencies<jupyter_code># install Jax if not found
try:
  import jax
except ModuleNotFoundError:
  %pip install --upgrade "jax[cpu]"
  # %pip install --upgrade "jax[cuda]" -f https://storage.googleapis.com/jax-releases/jax_releases.html  # Note: wheels only available on linux.

# install commplax if not found
try:
  import commplax
except ModuleNotFoundError:
  %pip install --upgrade https://github.com/remifan/commplax/archive/master.zip

# install data api if not found
try:
  import labptptm1
except ModuleNotFoundError:
  %pip install https://github.com/remifan/LabPtPTm1/archive/master.zip<jupyter_output><empty_output><jupyter_text>A minimal example of blind demodulation<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from labptptm1 import dataset as dat
from commplax import comm, xcomm, equalizer as eq, plot as cplt<jupyter_output>WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)<jupyter_text>Load datasetlet's get started with one of our public datasets -- experimental transmission of DP-16QAM siganl over ~815km SSMF see [LabPtPTm1](https://github.com/remifan/LabPtPTm1) for more information<jupyter_code>ds = dat['815km_SSMF/DP16QAM_RRC0.2_28GBd_1ch']

y = ds['LP-6_5/recv'][:200000]
x = dat['source/16QAM65536/src'][:]
sr = ds.attrs['samplerate']
br = ds.attrs['baudrate']
dist = ds.attrs['distance']
spans = ds.attrs['spans']
mf = ds.attrs['modformat']
lpw = ds['LP-6_5'].attrs['lpw']
         
# meta data
print('shape of y: %s (received waveforms, resampled to 2 samples/symbol): ' % str(y.shape))
print('shape of x: %s (source symbols): ' % str(x.shape))
print('sample rate: %.1f GHz' % (sr / 1e9))
print('baud rate: %.1f GBd' % (br / 1e9))
print('launched power: %.3f mW' % (lpw * 1e3))
print('link distance: %.1f km (measured)' % (dist / 1e3))
print('number of spans: %d' % spans)<jupyter_output>shape of y: (200000, 2) (received waveforms, resampled to 2 samples/symbol): 
shape of x: (65536, 2) (source symbols): 
sample rate: 56.0 GHz
baud rate: 28.0 GBd
launched power: 0.871 mW
link distance: 815.0 km (measured)
number of spans: 10<jupyter_text>Preprocessing<jupyter_code># DC-block and normalize raw signal
y -= np.mean(y, axis=0)
y =  xcomm.normpower(y, real=True) / np.sqrt(2)
 
# CD measurement
CD = 13.6
# CD = xcomm.measure_cd(y[10000:30000, 0], sr, bins=2000)[0]  # Uncomment this to measure CD, Note: slow on CPU
print('estimated accumulated CD = %.4g s/m' % CD)<jupyter_output>estimated accumulated CD = 13.6 s/m<jupyter_text>Adaptive equalization using `commplax.equalizer` APIs<jupyter_code>z_cdc = eq.cdcomp(y, sr, CD)  # CD compensaton
z_mimo = eq.modulusmimo(z_cdc, taps=19, lr=2**-14)[0]  # polarization demultiplexing
cplt.scatter(z_mimo[90000:95000])
z_foe = eq.qamfoe(z_mimo)[0]  # frequency offset equalization
cplt.scatter(z_foe[90000:95000])
z_cpr = eq.ekfcpr(z_foe)[0]  # carrier phase recovery
cplt.scatter(z_cpr[90000:95000], kde=True) # kdeplot takes more time
# aligning sent symbols to calc. BER
x_rep = xcomm.repalign(z_cpr, x)

# removing phase ambiguity and rescale signal
x_hat = xcomm.alignphase(z_cpr, x_rep) * xcomm.qamscale(mf)

# get metrics
qot = comm.qamqot(x_hat, x_rep, eval_range=(50000, -1000))
qot<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13730853391684902, 'fraction_numerical': 0.04266958424507659, 'mean_word_length': 5.518716577540107, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '545943', 'license': 'Apache-2.0', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1390, 'n_words': 329, 'path': 'docs/tutorial/equalizers.ipynb', 'repo_name': 'remifan/commplax', 'size': '3656'}