2

Python を使用して、信号が参照信号の制限を下回っているかどうかを確認するにはどうすればよいですか? 各信号は、たとえば次のコードと図のように、2 次元のリストとして与えられます。

#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]]

リファレンスとキャプチャされた信号 http://www.img-host.de/bild.php/35899,caprefsigWQJ8Z.png

私の問題は、2 つの信号のサンプリング ポイントが一致しないことです。比較可能な値を取得するために 2 つのポイント間を補間することもできますが、SciPy、NumPy などで関数を使用する準備ができていることをご存知かもしれません。

4

2 に答える 2

2

補間を使用する必要があります。これには常にある程度の不確実性が伴いますが (サンプリング ポイントの間に何があるかは決してわかりません)、サンプリング レートが十分に高い限り、安全な側にいることができます。

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()    

このプロットの結果:

結果

于 2013-01-07T13:13:19.243 に答える
1

これにNumPyを使用する必要はありません。ゼロ次ホールドを使用できます。これは、信号がサンプル間で一定であると想定していることを意味します。これは、数行でコーディングするのに十分な単純な種類の補間です。

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]]

def refat(x):
    "Simple interpolation (Zero-order hold) of reference signal"
    for i, n in enumerate(ReferenceSignal[0]):
        if n > x:
            if i == 0: return None
            return ReferenceSignal[1][i-1]

def capat(x):
    "Simple interpolation of capture signal"
    for i, n in enumerate(CapturedSignal[0]):
        if n > x:
            if i == 0: return None
            return CapturedSignal[1][i-1]   

def aboveref():
    "Check whether there is a captured value above its interpolated reference value and vice versa"
    print ' X  Cap Ref'
    for i, x in enumerate(CapturedSignal[0]):
        cap = CapturedSignal[1][i]
        ref = refat(x)
        print x, cap, ref
        if cap > ref:
            print "Uh oh! At %.1f, the captured signal is above the reference signal!" % x
            return False
    print '---'
    for i, x in enumerate(ReferenceSignal[0]):
        ref = ReferenceSignal[1][i]
        cap = capat(x)
        print x, cap, ref
        if cap > ref:
            print "Uh oh! At %.1f, the captured signal is above the reference signal!" % x
            return False
    return True

aboveref()

結果:

 X  Cap Ref
1.0 0.0 1.2
1.9 0.0 1.2
2.0 1.0 1.2
3.0 1.0 1.2
3.1 0.0 1.2
4.0 0.0 1.2
---
0.5 None 1.2
2.4 1.0 1.2
2.5 1.0 0.4
Uh oh! At 2.5, the captured signal is above the reference signal!
于 2013-01-07T13:30:36.180 に答える