0
$\begingroup$

In presence of a process that produces a 1D signal that is composed by an initial "transient" regime followed by a decay that we look forward to use for the estimation of a model's parameters using an exponential function.

signal(t)

What's the standard way in the signal processing community to mark an approximate "beginning" for the decay process, i.e. to be able to automatically segment the transient regime as is the case for the manually-processed following images.

We can safely assume that the end of the signal measurement corresponds to the end of the decay, i.e. no trailing signal.

transient and decay regime of the signal. Four examples.

$\endgroup$

1 Answer 1

0
$\begingroup$

Don't know if there's a "standard" but this should work:

np.where(np.all(np.sign(np.diff(x)).reshape(-1, 10) == -1, axis=-1))[0][0] * 10
  1. diffs = np.sign(np.diff(x)) Take derivative as finite difference. Region of interest changes monotonically so derivative is either + or -.
  2. bools = diffs.reshape(-1, 10) == -1 Here it decays so it's -. We want to find 10 consecutive points where the derivative is negative, or whatever other "tolerance", until we declare "this is where decay begins". A fast way to do this in Python is by vectorizing via a reshape, but for-loop is also an option. If we can't reshape, then pad from left.
  3. bools_rows = np.all(bools, axis=-1) is how we check the entire row is -.
  4. np.where(bools_rows)[0][0] gives the earliest match, *10 converts it back to original length. This gives an answer within 10 points, then we can apply for-loop over the smaller interval of diffs to find the exact index.

Example w/ code

import numpy as np
import matplotlib.pyplot as plt
    
x = np.hstack([np.random.randn(30)/10 + 1,
               np.exp(-np.linspace(0, 5, 51))])

out = np.where(np.all(np.sign(np.diff(x)).reshape(-1, 10) == -1, axis=-1))[0][0] * 10

plt.plot(x)
plt.scatter(out, x[out], color='r', s=20)
plt.axvline(out, color='tab:red', linewidth=1)
plt.show()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.