Multi-Channel Symmetric Signal Filter [ex120.0]ΒΆ

Applies a Composite Cost with a symmetric window as a symmetric, linear filter to a multi-channel signal.

../../_images/sphx_glr_example-ex120.0-mc-filter_001.png
import matplotlib.pyplot as plt
import numpy as np
import lmlib as lm
from lmlib.utils.generator import gen_sinusoidal, gen_rand_walk

# --- Generating test signal ---
K = 1000
k = np.arange(K)
M=4
seeds = [130, 150, 200, 220]
y = np.stack([gen_rand_walk(K, seed=s) for s in seeds], axis=-1)[:, np.newaxis, :]


# --- ALSSM Filtering ---
# Polynomial ALSSM
alssm_poly = lm.AlssmPoly(poly_degree=3)

# Segments
segment_left = lm.Segment(a=-np.inf, b=0, direction=lm.FORWARD, g=20)
segment_right = lm.Segment(a=1, b=np.inf, direction=lm.BACKWARD, g=20)

# CompsiteCost
costs = lm.CompositeCost((alssm_poly,), (segment_left, segment_right), F=[[1, 1]])

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

# extracts filtered signal
y_hat = costs.eval_alssm(xs, alssm_selection=[1])


# --- Plotting ----
fig, axs = plt.subplots(M, 1, sharex='all')
for m, ax in enumerate(axs):
    ax.plot(k, y[:, :, m], lw=0.6, c='gray', label=r'$y_{}$'.format(m))
    ax.plot(k, y_hat[:, :, m], lw=1, label=r'$\hat{{y}}_{}$'.format(m))
    ax.legend(loc='upper right')

axs[-1].set_xlabel('time')

plt.show()

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

Gallery generated by Sphinx-Gallery