예제 #1
0
def test_whitesignal_continuity(rng, plt):
    """Test that WhiteSignal is continuous over multiple periods."""
    rms = 0.5
    high = 10
    dt = 0.001
    t = 1
    process = WhiteSignal(t, high=high, rms=rms)
    x = process.run(4 * t, d=1, dt=dt, rng=rng)

    plt.plot(process.ntrange(len(x), dt=dt), x)

    # tolerances approximated from derivatives of sine wave of highest freq
    safety_factor = 2.
    a, f = np.sqrt(2) * rms, (2 * np.pi * high) * dt
    assert abs(np.diff(x, axis=0)).max() <= safety_factor * a * f
    assert abs(np.diff(x, n=2, axis=0)).max() <= safety_factor**2 * a * f**2
예제 #2
0
def test_whitesignal_continuity(rng, plt):
    """Test that WhiteSignal is continuous over multiple periods."""
    rms = 0.5
    high = 10
    dt = 0.001
    t = 1
    process = WhiteSignal(t, high=high, rms=rms)
    x = process.run(4 * t, d=1, dt=dt, rng=rng)

    plt.plot(process.ntrange(len(x), dt=dt), x)

    # tolerances approximated from derivatives of sine wave of highest freq
    safety_factor = 2.
    a, f = np.sqrt(2) * rms, (2 * np.pi * high) * dt
    assert abs(np.diff(x, axis=0)).max() <= safety_factor * a * f
    assert abs(np.diff(x, n=2, axis=0)).max() <= safety_factor**2 * a * f**2
예제 #3
0
def test_whitesignal_rms(rms, rng, plt):
    d = 500
    t = 1
    dt = 0.001

    process = WhiteSignal(t, rms=rms)
    values = process.run(t, d=d, dt=dt, rng=rng)
    freq, val_psd = psd(values)

    trange = process.trange(t, dt=dt)
    plt.subplot(2, 1, 1)
    plt.title("First two D of white noise process, rms=%.1f" % rms)
    plt.plot(trange, values[:, :2])
    plt.xlim(right=trange[-1])
    plt.subplot(2, 1, 2)
    plt.title("Power spectrum")
    plt.plot(freq, val_psd, drawstyle='steps')

    assert np.allclose(np.std(values), rms, rtol=0.02)
    assert np.allclose(val_psd[1:-1], rms, rtol=0.35)
예제 #4
0
def test_whitesignal_rms(rms, rng, plt):
    d = 500
    t = 1
    dt = 0.001

    process = WhiteSignal(t, rms=rms)
    values = process.run(t, d=d, dt=dt, rng=rng)
    freq, val_psd = psd(values)

    trange = process.trange(t, dt=dt)
    plt.subplot(2, 1, 1)
    plt.title("First two D of white noise process, rms=%.1f" % rms)
    plt.plot(trange, values[:, :2])
    plt.xlim(right=trange[-1])
    plt.subplot(2, 1, 2)
    plt.title("Power spectrum")
    plt.plot(freq, val_psd, drawstyle='steps')

    assert np.allclose(np.std(values), rms, rtol=0.02)
    assert np.allclose(val_psd[1:-1], rms, rtol=0.35)
예제 #5
0
def test_whitesignal_high(high, rng, plt):
    rms = 0.5
    d = 500
    t = 1
    dt = 0.001

    process = WhiteSignal(t, high, rms=rms)
    values = process.run(t, d=d, dt=dt, rng=rng)
    freq, val_psd = psd(values)

    trange = process.trange(t, dt=dt)
    plt.subplot(2, 1, 1)
    plt.title("First two D of white noise process, high=%d Hz" % high)
    plt.plot(trange, values[:, :2])
    plt.xlim(right=trange[-1])
    plt.subplot(2, 1, 2)
    plt.title("Power spectrum")
    plt.plot(freq, val_psd, drawstyle='steps')
    plt.xlim(right=high * 2.0)

    assert np.allclose(np.std(values, axis=1), rms, rtol=0.15)
    assert np.all(val_psd[npext.rfftfreq(t, dt) > high] < rms * 0.5)
예제 #6
0
def test_whitesignal_high(high, rng, plt):
    rms = 0.5
    d = 500
    t = 1
    dt = 0.001

    process = WhiteSignal(t, high, rms=rms)
    values = process.run(t, d=d, dt=dt, rng=rng)
    freq, val_psd = psd(values)

    trange = process.trange(t, dt=dt)
    plt.subplot(2, 1, 1)
    plt.title("First two D of white noise process, high=%d Hz" % high)
    plt.plot(trange, values[:, :2])
    plt.xlim(right=trange[-1])
    plt.subplot(2, 1, 2)
    plt.title("Power spectrum")
    plt.plot(freq, val_psd, drawstyle='steps')
    plt.xlim(right=high * 2.0)

    assert np.allclose(np.std(values, axis=1), rms, rtol=0.15)
    assert np.all(val_psd[npext.rfftfreq(t, dt) > high] < rms * 0.5)