Detection of jumps in a signal [ex912.0]ΒΆ

../../_images/sphx_glr_fig-examp-jumpdetector_001.png
from L1_costs import estAverageRect # import cost computation functions
from L1_costs import calcCostRatio
from L1_costs import getSEParams

from L1_plots import plotFigsCR1 # import plotting functions
from L1_plots import plotFigsCR2 # import plotting functions
from L1_plots import plotFigsCR3 # import plotting functions

import numpy as np

import matplotlib.pyplot as plt
import lmlib as lm

from scipy.signal import find_peaks
from lmlib.utils.generator import *



seed = 1234578 # set pseudo-radom generator to fixed start value --> leads to reproducible results

NOF_X = 100
J_MAX = 100
a = -100 # rectangular window
b = 100
K = 2000 # number of samples
k = np.arange(0, K)
gamma = .992 # decay factor
sigma_noise = .1
min_distance = 150 # minimal distance between two detected peaks
min_lcr = 0.025 # minimal lcr to detect an event


# generate windows
i_w = np.arange(-K,K) # indices of window weights
w_Left = np.zeros(2*K); # generate window
np.putmask(w_Left, i_w<=0, gamma**np.abs(i_w))

w_Right = np.zeros(2*K); # generate window
np.putmask(w_Right, i_w>0, gamma**np.abs(i_w))


# create test signal
y1 = gen_steps(K, [500, 700, 1100, 1400], [1, .5, -1, .2])
yn = gen_wgn(K, sigma=sigma_noise, seed=seed)

y = y1+yn

# ------------
(W_Left, xi_Left, kappa_Left) = getSEParams(y, a,b, w_Left, i_w)
(W_Right, xi_Right, kappa_Right) = getSEParams(y, a,b, w_Right, i_w)

(CR,x_hatLeft, x_hatRight, x_hat, J1, J2, J12) = calcCostRatio(W_Left, xi_Left, kappa_Left, W_Right, xi_Right, kappa_Right)

plotFigsCR1(y, k, CR, x_hatLeft, x_hatRight, x_hat, w_Left, w_Right, i_w, J1, J2, J12)

plt.show()

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

Gallery generated by Sphinx-Gallery