Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if signal is in the limits given by another signal

How can I check if a signal is below the limits of a reference signal, with python? Each signal is given as a two-dimensional list, for example like in following code and diagram.

#Signal = [[t0, t1, t2, ...], [y(t0), y(t1), y(t2), ...]]
CapturedSignal = [[1.0, 1.9, 2.0, 3.0, 3.1, 4.0], [0.0, 0.0, 1.0, 1.0, 0.0, 0.0]]
ReferenceSignal = [[0.5, 2.4, 2.5, 2.7, 2.8, 4.5], [1.2, 1.2, 0.4, 0.4, 1.2, 1.2]]

reference and captured signal http://www.img-host.de/bild.php/35899,caprefsigWQJ8Z.png

My problem is, that the sampling points of the two signals don't match. I could interpolate between two points to get comparable values but maybe you know ready to use functions in SciPy, NumPy or something else.

like image 918
wewa Avatar asked Dec 05 '25 02:12

wewa


1 Answers

You must use interpolation. It involves always some incertainty (you never know what's between your sampling points) but as long as your sampling rate is sufficiently high, you will be on the safe side.

import numpy as np
import pylab as plt

from scipy.interpolate import interp1d


CapturedSignal = [[1.0, 1.9, 2.0, 3.0, 3.1, 4.0], [0.0, 0.0, 1.0, 1.0, 0.0, 0.0]]
ReferenceSignal = [[0.5, 2.4, 2.5, 2.7, 2.8, 4.5], [1.2, 1.2, 0.4, 0.4, 1.2, 1.2]]

representation_captured = interp1d(CapturedSignal[0], CapturedSignal[1], kind="linear")
representation_reference = interp1d(ReferenceSignal[0], ReferenceSignal[1], kind="linear")

min_x = max(min(CapturedSignal[0]), min(ReferenceSignal[0]))
max_x = min(max(CapturedSignal[0]), max(ReferenceSignal[0]))

xs = np.linspace(min_x, max_x, 100, False)

captured_interpolated = representation_captured(xs)
reference_interpolated = representation_reference(xs)

captured_signal_in_bounds = np.all(captured_interpolated<reference_interpolated)

plt.plot(xs, captured_interpolated, "r-", label="Captured")
plt.plot(CapturedSignal[0], CapturedSignal[1], "rD")
plt.plot(xs, reference_interpolated, "b-", label="Reference")
plt.plot(ReferenceSignal[0], ReferenceSignal[1], "bD")
plt.title("Signal below reference" if captured_signal_in_bounds else "Signal exceeds bounds")

plt.legend(loc='best')
plt.show()    

results in this plot:

Resuls

like image 53
Thorsten Kranz Avatar answered Dec 07 '25 17:12

Thorsten Kranz