Пример #1
0
def test_fdscale():
    sig, t, f = ytools.gensweep(10, 1, 12, 8)
    scale = np.array([[0.0, 1.0], [4.0, 1.0], [5.0, 0.5], [8.0, 0.5],
                      [9.0, 1.0], [100.0, 1.0]])
    sr = 1 / t[1]
    sig_scaled = dsp.fdscale(sig, sr, scale)
    x = np.arange(0, 10, 0.001)
    y = 1 / np.interp(x, scale[:, 0], scale[:, 1])
    unscale = np.vstack((x, y)).T
    sig_unscaled = dsp.fdscale(sig_scaled, sr, unscale)
    assert np.allclose(sig, sig_unscaled, atol=1e-6)

    sig_scaled = dsp.fdscale(sig[:-1], sr, scale)
    sig_unscaled = dsp.fdscale(sig_scaled, sr, unscale)
    assert np.allclose(sig[:-1], sig_unscaled, atol=1e-6)

    sig2 = np.vstack((sig, sig)).T
    sig_scaled = dsp.fdscale(sig2, sr, scale)
    sig_unscaled = dsp.fdscale(sig_scaled, sr, unscale)
    assert np.allclose(sig2, sig_unscaled, atol=1e-6)

    sign = np.vstack((sig, sig, sig))
    sigf1 = dsp.fdscale(sign, sr, scale)
    sigf2 = dsp.fdscale(sign.T, sr, scale, axis=0).T
    assert np.allclose(sigf1, sigf2)

    sign3 = sign.reshape(1, 3, -1, 1)
    sigf3 = dsp.fdscale(sign3, sr, scale, axis=2).reshape(3, -1)
    assert np.allclose(sigf1, sigf3)
Пример #2
0
def test_waterfall():
    from pyyeti import srs

    sig, t, f = ytools.gensweep(10, 1, 50, 4)
    sr = 1 / t[1]
    frq = np.arange(1.0, 5.1)
    Q = 20
    sig2 = sig[: int(sr * 1.5), None]

    def func(s):
        return srs.srs(s, sr, frq, Q), frq

    mp, t, f = dsp.waterfall(sig, sr, 2, 0.5, func, which=0, freq=1)
    mp, t, f = dsp.waterfall(sig2, sr, 2, 0.5, func, which=0, freq=1)
    assert_raises(ValueError, dsp.waterfall, sig, sr, 2, 0.5, func, which=None, freq=1)
    assert_raises(
        ValueError, dsp.waterfall, sig, sr, 2, 1.5, func, which=None, freq=frq
    )
    assert_raises(
        ValueError, dsp.waterfall, sig, sr, 2, 1.0, func, which=None, freq=frq
    )
    assert_raises(
        ValueError, dsp.waterfall, sig, sr, 2, -0.5, func, which=None, freq=frq
    )
    sig = np.hstack((sig2, sig2))
    assert_raises(
        ValueError, dsp.waterfall, sig, sr, 2, 0.5, func, which=None, freq=frq
    )
Пример #3
0
def test_gensweep():
    sig, t, f = ytools.gensweep(10, 1, 12, 8)
    assert np.allclose(np.max(sig), 1.0)
    assert np.allclose(np.min(sig), -1.0)
    # 12 = 1*2**n_oct
    n_oct = np.log(12.0) / np.log(2.0)
    t_elapsed = n_oct / 8 * 60
    assert np.abs(t[-1] - t_elapsed) < 0.01
    assert np.allclose(f[0], 1)
    assert np.abs(f[-1] - 12) < 0.01
    assert np.allclose(t[1] - t[0], 1 / 10 / 12)
    # at 8 oct/min or 8/60 = 4/30 = 2/15 oct/sec, time for 3 octaves
    # is: 3/(2/15) = 45/2 = 22.5 s
    i = np.argmin(np.abs(t - 22.5))
    assert np.allclose(f[i], 8.0)
Пример #4
0
def test_srsmap():
    from pyyeti import ytools, dsp

    sig, ts, fs = ytools.gensweep(10, 1, 50, 4)
    sr = 1 / ts[1]
    frq = np.arange(1.0, 50.1)
    Q = 20
    mp, t, f = srs.srsmap(2, 0.5, sig, sr, frq, Q, 0.02, eqsine=1)
    assert np.all(f == frq)
    dt = 1.0
    segments = int(np.floor(ts[-1] / dt)) - 1
    assert len(t) == segments
    t_should_be = np.arange(segments) * dt + dt
    assert np.allclose(t, t_should_be)
    # test segment 63:
    seg = 63
    pv = np.logical_and(ts >= t[seg] - dt, ts < t[seg] + dt)
    sh = srs.srs(dsp.windowends(sig[pv], 0.02), sr, frq, Q, eqsine=1)
    assert np.allclose(sh, mp[:, seg])