您必须使用插值。它总是涉及一些不确定性(您永远不知道采样点之间的内容),但只要您的采样率足够高,您就会安全。
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()
结果在这个图中: