Symmetric linear filter with ALSSMs using a covariance steady-state matrix (speed enhancement) [ex121.0]ΒΆ

Applies a Composite Cost with a symmetric window as a symmetric, linear filter to a multi-channel signal. This script uses a precomputed steady-state matrix W, i.e., only calculates parameter xi recursively to maximize computation speed. Note that using the steady-state matrix leads to some border effects, i.e., some imprecision at the observation interval borders.

../../_images/sphx_glr_example-ex121.0-sc-filter_001.png

Out:

/Users/wbr8/homedata/projects/lmlib-branches/reto-doc/lmlib/statespace/costfunc.py:133: UserWarning: This steady state calculation can be numerically unstable due to the inversion of a high conditioned matrix
  warnings.warn("This steady state calculation can be numerically unstable due to the inversion of a high conditioned matrix")

import matplotlib.pyplot as plt
import numpy as np
import lmlib as lm
from lmlib.utils.generator import gen_rand_walk
import time

# --- Generating test signal ---
K = 1000
k = np.arange(K)
y = gen_rand_walk(K, seed=1234)


# --- 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_1 = lm.SEParam(costs, use_steady_state=True, params=('xi',))
xs1 = se_param_1.filter_minimize_x(y)


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

# --- Plotting ----
fig, ax = plt.subplots(sharex='all', figsize=(10,3))
ax.plot(k, y, lw=0.6, c='gray', label=rf'$y$')
ax.plot(k, y_hat, lw=1, c='blue', label=r'$\hat{y}$')
ax.legend(loc='upper right')
ax.set_xlabel('time')

plt.show()

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

Gallery generated by Sphinx-Gallery