예제 #1
0
def test_compare_multisine_with_sine(time, freq, amp):
    # Compare the result of a call of sine and a similar call of multi_sine
    # with one-element lists of amplitudes and frequencies.

    x = sine(time=time, amp=amp, freq=freq)
    multi_x = multi_sine(time=time, amps=[amp], freqs=[freq])
    # Check for minimal callability and that maximum amplitude at
    # timestamps is below default.
    assert_almost_equal(x, multi_x)
예제 #2
0
def multisine_testsignal():
    # set amplitude values of multi-sine componentens (last parameter is number of components)
    sine_amps = np.random.randint(1, 4, 10)
    # set frequencies of multi-sine components
    sine_freqs = np.linspace(100, 500, len(sine_amps)) * 2 * np.pi
    # define time axis
    dt = 0.0001
    time = np.arange(0.0, 0.2, dt)
    # measurement noise standard deviation (assume white noise)
    sigma_noise = 0.001
    # generate test signal
    testsignal = multi_sine(time, sine_amps, sine_freqs, noise=sigma_noise)
    return testsignal, sigma_noise
예제 #3
0
def multisine_testsignal(dt=0.0001):
    """ Additional helper function to create test multi-sine signal
    """
    # set amplitude values of multi-sine componentens (last parameter is number of components)
    sine_amps = np.random.randint(1, 4, 10)
    # set frequencies of multi-sine components
    sine_freqs = np.linspace(100, 500, len(sine_amps)) * 2 * np.pi
    # define time axis
    time = np.arange(0.0, 0.2, dt)
    time = time[:prevpow2(len(time))]
    # measurement noise standard deviation (assume white noise)
    sigma_noise = 0.001
    # generate test signal
    testsignal = multi_sine(time, sine_amps, sine_freqs, noise=sigma_noise)
    return testsignal, sigma_noise
예제 #4
0
import numpy as np
import matplotlib.pyplot as plt
from PyDynamic.uncertainty.propagate_DFT import AmpPhase2Time, Time2AmpPhase, GUM_DFTfreq, Time2AmpPhase_multi
from PyDynamic.misc.testsignals import multi_sine

# set amplitude values of multi-sine componentens (last parameter is number of components)
sine_amps = np.random.randint(1, 4, 10)
# set frequencies of multi-sine components
sine_freqs = np.linspace(100, 500, len(sine_amps)) * 2 * np.pi
# define time axis
dt = 0.0001
time = np.arange(0.0, 0.2, dt)
# measurement noise standard deviation (assume white noise)
sigma_noise = 0.001
# generate test signal
testsignal = multi_sine(time, sine_amps, sine_freqs, noise=sigma_noise)

plt.figure(1, figsize=(12, 6))
plt.plot(time, testsignal)
plt.xlabel("time in s")
plt.ylabel("signal amplitude in a.u.")

# uncertainty propagation from time domain to frequency domain
A, P, UAP = Time2AmpPhase(testsignal, sigma_noise**2)
f = GUM_DFTfreq(len(time), dt)

plt.figure(2, figsize=(12, 6))
plt.errorbar(f, A, np.sqrt(np.diag(UAP)[:len(A)]), fmt=".-")
plt.xlabel("frequency in Hz")
plt.ylabel("DFT magnitude values in a.u.")
예제 #5
0
    def __init__(self):
        multi_sine_amps = np.random.randint(1, 4, 10)
        multi_sine_freqs = np.linspace(100, 500, len(multi_sine_amps)) * 2 * np.pi
        time_step = 0.0001
        time = np.arange(start=0.0, stop=0.2, step=time_step)
        measure_noise_std_sigma = 0.001
        testsignal = multi_sine(
            time, multi_sine_amps, multi_sine_freqs, noise=measure_noise_std_sigma
        )

        plt.figure(1, figsize=(12, 6))
        plt.plot(time, testsignal)
        plt.xlabel("time in s")
        plt.ylabel("signal amplitude in a.u.")

        # uncertainty propagation from time domain to frequency domain
        A, P, UAP = Time2AmpPhase(testsignal, measure_noise_std_sigma ** 2)
        f = GUM_DFTfreq(len(time), time_step)

        plt.figure(2, figsize=(12, 6))
        plt.errorbar(f, A, np.sqrt(np.diag(UAP)[: len(A)]), fmt=".-")
        plt.xlabel("frequency in Hz")
        plt.ylabel("DFT magnitude values in a.u.")

        # uncertainty propagation from frequency domain to time domain
        x, ux = AmpPhase2Time(A, P, UAP)

        plt.figure(3, figsize=(12, 6))
        plt.subplot(211)
        plt.errorbar(
            time,
            x,
            np.sqrt(np.diag(ux)),
            fmt=".-",
            label="after DFT and iDFT using amplitude and phase",
        )
        plt.plot(time, testsignal, label="original signal")
        plt.xlabel("time in s")
        plt.ylabel("signal amplitude in a.u.")
        plt.legend()
        plt.subplot(212)
        plt.plot(
            time,
            np.sqrt(np.diag(ux)),
            label="uncertainty after DFT and iDFT using amplitude and phase",
        )
        plt.plot(
            time,
            np.ones_like(time) * measure_noise_std_sigma,
            label="original uncertainty",
        )
        plt.xlabel("time in s")
        plt.ylabel("uncertainty in a.u.")
        plt.legend()

        # # apply the same method to several signals with one call
        M = 10
        testsignals = np.zeros((M, len(time)))
        for m in range(M):
            testsignals[m, :] = multi_sine(
                time, multi_sine_amps, multi_sine_freqs, noise=measure_noise_std_sigma
            )

        # select those frequencies of the 10 % largest magnitude values
        indices = np.argsort(A)[: len(A) // 10]
        # propagate from time to frequency domain and select specified frequencies
        A_multi, P_multi, UAP_multi = Time2AmpPhase_multi(
            testsignals, np.ones(M) * measure_noise_std_sigma ** 2, selector=indices
        )

        plt.figure(4, figsize=(12, 6))
        plt.subplot(211)
        plt.plot(f[indices], A_multi.T, linestyle=":")
        plt.subplot(212)
        plt.plot(f[indices], P_multi.T, linestyle=":")