def test_sos_phys2filter():
    b, a = sos_phys2filter(S0, delta, f0)
    H = freqs(b, a, 2 * np.pi * fe5)[1]
    indmax = np.abs(H).argmax()
    assert np.round(np.abs(f0 - fe5[indmax])) <= 0.01 * f0
    assert np.abs(H[0]) == approx(S0)
    bmulti, amulti = sos_phys2filter(S0 * np.ones(K), delta * np.ones(K), f0 * np.ones(K))
    assert len(bmulti[0]) == K
    assert amulti.shape == (K, 3)
def test_sos_phys2filter():
    b, a = sos_phys2filter(S0, delta, f0)
    H = freqs(b, a, 2 * np.pi * fe5)[1]
    indmax = np.abs(H).argmax()
    assert np.round(np.abs(f0 - fe5[indmax])) <= 0.01 * f0
    assert np.abs(H[0]) == approx(S0)
    bmulti, amulti = sos_phys2filter(S0 * np.ones(K), delta * np.ones(K),
                                     f0 * np.ones(K))
    assert len(bmulti[0]) == K
    assert amulti.shape == (K, 3)
Esempio n. 3
0
def digital_filter(measurement_system, sampling_freq):
    # transform continuous system to digital filter
    bc, ac = sos_phys2filter(
        measurement_system["S0"], measurement_system["delta"], measurement_system["f0"]
    )
    assert_almost_equal(bc, [20465611686.098896])
    assert_allclose(ac, np.array([1.00000000e00, 4.52389342e03, 5.11640292e10]))
    b, a = dsp.bilinear(bc, ac, sampling_freq)
    assert_allclose(
        b, np.array([0.019386043211510096, 0.03877208642302019, 0.019386043211510096])
    )
    assert_allclose(a, np.array([1.0, -1.7975690550957188, 0.9914294872108197]))
    return {"b": b, "a": a}
Esempio n. 4
0
tau = 6  # time delay

# parameters of simulated measurement
Fs = 500e3  # sampling frequency (in Hz)
Ts = 1 / Fs  # sampling intervall length (in s)

# sensor/measurement system
f0 = 36e3
uf0 = 0.01 * f0  # resonance frequency
S0 = 0.124
uS0 = 0.001 * S0  # static gain
delta = 0.0055
udelta = 0.1 * delta  # damping

# transform continuous system to digital filter
bc, ac = sos_phys2filter(S0, delta,
                         f0)  # calculate analogue filter coefficients
b, a = dsp.bilinear(bc, ac, Fs)  # transform to digital filter coefficients

# simulate input and output signals
time = np.arange(0, 4e-3 - Ts, Ts)  # time values
x = shocklikeGaussian(time, t0=2e-3, sigma=1e-5, m0=0.8)  # input signal
y = dsp.lfilter(b, a, x)  # output signal
noise = 1e-3  # noise std
yn = y + rst.randn(np.size(y)) * noise  # add white noise

# Monte Carlo for calculation of unc. assoc. with [real(H),imag(H)]
runs = 10000
MCf0 = f0 + rst.randn(runs) * uf0  # MC draws of resonance frequency
MCS0 = S0 + rst.randn(runs) * uS0  # MC draws of static gain
MCd = delta + rst.randn(runs) * udelta  # MC draws of damping
f = np.linspace(0, 120e3,
Esempio n. 5
0
tau = 6  # time delay

# parameters of simulated measurement
Fs = 500e3
Ts = 1 / Fs

# sensor/measurement system
f0 = 36e3
uf0 = 0.01 * f0
S0 = 0.124
uS0 = 0.001 * S0
delta = 0.0055
udelta = 0.1 * delta

# transform continuous system to digital filter
bc, ac = sos_phys2filter(S0, delta, f0)
b, a = dsp.bilinear(bc, ac, Fs)

# simulate input and output signals
time = np.arange(0, 4e-3 - Ts, Ts)
x = shocklikeGaussian(time, t0=2e-3, sigma=1e-5, m0=0.8)
y = dsp.lfilter(b, a, x)
noise = 1e-3
yn = y + np.random.randn(np.size(y)) * noise

# Monte Carlo for calculation of unc. assoc. with [real(H),imag(H)]
runs = 10000
MCS0 = S0 + rst.randn(runs) * uS0
MCd = delta + rst.randn(runs) * udelta
MCf0 = f0 + rst.randn(runs) * uf0
f = np.linspace(0, 120e3, 200)
Esempio n. 6
0
def monte_carlo(
    measurement_system,
    random_number_generator,
    sampling_freq,
    freqs,
    complex_freq_resp,
    reference_array_path,
):
    udelta = 0.1 * measurement_system["delta"]
    uS0 = 0.001 * measurement_system["S0"]
    uf0 = 0.01 * measurement_system["f0"]

    runs = 10000
    MCS0 = random_number_generator.normal(
        loc=measurement_system["S0"], scale=uS0, size=runs
    )
    MCd = random_number_generator.normal(
        loc=measurement_system["delta"], scale=udelta, size=runs
    )
    MCf0 = random_number_generator.normal(
        loc=measurement_system["f0"], scale=uf0, size=runs
    )
    HMC = np.empty((runs, len(freqs)), dtype=complex)
    for index, mcs0_mcd_mcf0 in enumerate(zip(MCS0, MCd, MCf0)):
        bc_, ac_ = sos_phys2filter(mcs0_mcd_mcf0[0], mcs0_mcd_mcf0[1], mcs0_mcd_mcf0[2])
        b_, a_ = dsp.bilinear(bc_, ac_, sampling_freq)
        HMC[index, :] = dsp.freqz(b_, a_, 2 * np.pi * freqs / sampling_freq)[1]

    H = complex_2_real_imag(complex_freq_resp)
    assert_allclose(
        H,
        np.load(
            os.path.join(reference_array_path, "test_LSFIR_H.npz"),
        )["H"],
    )
    uAbs = np.std(np.abs(HMC), axis=0)
    assert_allclose(
        uAbs,
        np.load(
            os.path.join(reference_array_path, "test_LSFIR_uAbs.npz"),
        )["uAbs"],
        rtol=3.5e-2,
    )
    uPhas = np.std(np.angle(HMC), axis=0)
    assert_allclose(
        uPhas,
        np.load(
            os.path.join(reference_array_path, "test_LSFIR_uPhas.npz"),
        )["uPhas"],
        rtol=4.3e-2,
    )
    UH = np.cov(np.hstack((np.real(HMC), np.imag(HMC))), rowvar=False)
    UH = make_semiposdef(UH)
    assert_allclose(
        UH,
        np.load(
            os.path.join(reference_array_path, "test_LSFIR_UH.npz"),
        )["UH"],
        atol=1,
    )
    return {"H": H, "uAbs": uAbs, "uPhas": uPhas, "UH": UH}
Esempio n. 7
0
##### FIR filter parameters
N = 12  # filter order
tau = 6 # time delay

# parameters of simulated measurement
Fs = 500e3      # sampling frequency (in Hz)
Ts = 1 / Fs     # sampling intervall length (in s)

# sensor/measurement system
f0 = 36e3; uf0 = 0.01*f0            # resonance frequency
S0 = 0.124; uS0= 0.001*S0           # static gain
delta = 0.0055; udelta = 0.1*delta  # damping

# transform continuous system to digital filter
bc, ac = sos_phys2filter(S0,delta,f0)   # calculate analogue filter coefficients
b, a = dsp.bilinear(bc, ac, Fs)         # transform to digital filter coefficients

# simulate input and output signals
time = np.arange(0, 4e-3 - Ts, Ts)                              # time values
x = shocklikeGaussian(time, t0 = 2e-3, sigma = 1e-5, m0=0.8)    # input signal
y = dsp.lfilter(b, a, x)                                        # output signal
noise = 1e-3                                                    # noise std
yn = y + rst.randn(np.size(y)) * noise                          # add white noise

# Monte Carlo for calculation of unc. assoc. with [real(H),imag(H)]
runs = 10000
MCf0 = f0 + rst.randn(runs)*uf0                 # MC draws of resonance frequency
MCS0 = S0 + rst.randn(runs)*uS0                 # MC draws of static gain
MCd  = delta+ rst.randn(runs)*udelta            # MC draws of damping
f = np.linspace(0, 120e3, 200)                  # frequencies at which to calculate frequency response