Detecting of binary signal, LCR (Skeleton) [ex910.0]ΒΆ

../../_images/sphx_glr_fig-exercise-binary-decision_001.png
import matplotlib.pyplot as plt
import numpy as np
import numpy.matlib
import lmlib as lm
from lmlib.utils.generator import gen_wgn

# --- Generating Test signal ---
SIGMA2 = 0.5
SYMBOL_LENGTH = 100 # number of samples per symbol (bit)

SYMBOLS = [1,-1,1,-1,1,1,1,-1,-1,-1,-1,1,-1,1,-1,-1,1,-1] # symbol sequence to be detected (test sequence)

X_HIGH = 1 # logic '1' signal value
X_LOW = -1 # logic '0' signal value



# signal generator with additive noise
def gen_test_signal(symbols, symbol_length, sigma2):
    K = len(symbols)*symbol_length
    y0 = np.kron(symbols, np.ones((symbol_length,)))
    y_n = gen_wgn(K, 1, seed=1234)
    return (y0+y_n*sigma2, y0)


(y, y0) = gen_test_signal(SYMBOLS, SYMBOL_LENGTH, SIGMA2)

K = y.shape[0]
k = np.arange(K)

# ----- Models and Parameter Estimation  --------------

# Line ALSSM
alssm_poly = lm.AlssmPoly(poly_degree=0)
# Segment
segment = lm.Segment(a=-int(SYMBOL_LENGTH/2), b=int(SYMBOL_LENGTH/2)-1, direction=lm.FORWARD, g=500)

# Cost Segment
costs = lm.CostSegment(alssm_poly, segment)

# filter signal and take the approximation
se_param = lm.SEParam(costs)
se_param.filter(y)

# cost functions
J_high = se_param.eval_errors(np.matlib.repmat(X_HIGH, K, 1))
J_low = se_param.eval_errors(np.matlib.repmat(X_LOW, K, 1))




# ========== DUMMY CODE - TO BE REPLACED ========

lcr = np.zeros((K,))    # lcr value
y_hat = np.zeros((K,))  # binary reconstruction of y

# ==============================================



# ----------------  Plot  -----------------
fig = plt.figure(figsize=(7,5))

fig.suptitle('Binary signal with white Gaussian noise $sigma^2=$'+str(SIGMA2), fontsize=12)

axs = fig.add_subplot(3, 1, 1)
axs.plot(k, y, lw=1.0, c='tab:gray', label='$y$')
axs.plot(k, y0, lw=1.0, c='r', ls='--', label='${y}_{0}$')
axs.plot(k, y_hat, lw=2.0, c='b', ls='-', label='$\hat{y}$')
axs.set( ylabel='observations')

axs.grid(True)
axs.legend(loc='upper right')

axs = fig.add_subplot(3, 1, (2), sharex=axs)
axs.plot(k, J_high, label='$J('+str(X_HIGH)+')$', c='tab:orange')
axs.plot(k, J_low, label='$J('+str(X_LOW)+')$', c='tab:blue')
axs.legend(loc='upper right')
axs.set( ylabel='Costs')


axs = fig.add_subplot(3, 1, (3), sharex=axs)
axs.plot(k, lcr, label='LCR',  c='tab:purple')
axs.axhline(y=0, c='k', lw=0.5, ls='--')
axs.legend(loc='upper right')
#axs.set( ylabel='LCR')


plt.subplots_adjust(hspace=0.4)

plt.show()

Total running time of the script: ( 0 minutes 0.365 seconds)

Gallery generated by Sphinx-Gallery