Exemplo n.º 1
0
def coupled_TF(Y1, Y2):
    d = dvma.DataSet()

    Y1.tf_data_list[0].tf_coherence = None
    Y2.tf_data_list[0].tf_coherence = None

    Y1d = Y1.tf_data_list[0].tf_data
    Y2d = Y2.tf_data_list[0].tf_data
    Yc = 1 / (1 / Y1d + 1 / Y2d)
    f = Y1.tf_data_list[0].freq_axis
    settings = Y1.tf_data_list[0].settings

    tf_data_coupled = dvma.TfData(
        f,
        Yc,
        None,
        settings,
        id_link=[Y1.tf_data_list[0].id_link, Y2.tf_data_list[0].id_link],
        test_name='predicted')

    d.add_to_dataset(Y1.tf_data_list[0])
    d.add_to_dataset(Y2.tf_data_list[0])
    d.add_to_dataset(tf_data_coupled)

    return d
Exemplo n.º 2
0
def measure_tf2(fs=8000, T=3, fmin=20, fmax=500):
    # sweep

    Tr = 0.1
    t, win = window_signal(fs, T, Tr=0.1)

    N = len(t)
    x = np.zeros(N)
    y = np.zeros(N)

    x = win * ss.chirp(t, fmin, T - 6 * Tr, fmax)

    f = np.fft.rfftfreq(N, 1 / fs)

    #%% LOG DATA
    print('Sweep: {} to {} (Hz)'.format(fmin, fmax))
    y = sd.playrec(x, samplerate=fs, channels=1, blocking=True)

    X = np.fft.rfft(x)
    Y = np.fft.rfft(y[:, 0])

    G2 = Y / X

    settings = dvma.MySettings(fs=fs, channels=1)

    tfdata = dvma.TfData(f, G2, None, settings, test_name='sweep')

    plot_tf(tfdata)

    return tfdata
Exemplo n.º 3
0
 def save(self, b):
     self.out.clear_output(wait=False)
     with self.out:
         i_sort = np.argsort(self.f)
         ff = self.f[i_sort]
         GG = self.G[i_sort]
         tf_data = dvma.TfData(ff,
                               GG,
                               None,
                               self.rec.settings,
                               test_name='stepped_sine')
         d = dvma.DataSet(tf_data)
         d.save_data()
Exemplo n.º 4
0
def measure_tf1(fs=8000, T=2, fmin=20, fmax=500, NF=20):
    # stepped sine

    global fig, ax

    #%% LOG DATA
    t = np.arange(0, T, 1 / fs)
    N = len(t)
    f = np.fft.rfftfreq(N, 1 / fs)
    freqs = np.linspace(fmin, fmax, NF)
    freqs = si.griddata(f, f, freqs, 'nearest')
    G1 = np.zeros(len(freqs), dtype=complex)
    c = -1
    for freq in freqs:
        c += 1

        t, win = window_signal(fs, T, Tr=0.1)
        x = np.sin(2 * np.pi * freq * t)
        x *= win

        print('Frequency = {} (Hz)'.format(freq))
        y = sd.playrec(x, samplerate=fs, channels=1, blocking=True)

        X = np.fft.rfft(x)
        Y = np.fft.rfft(y[:, 0])

        IX = np.argmax(np.abs(X))
        IY = np.argmax(np.abs(Y))
        G = Y[IY] / X[IX]
        G1[c] = G
        ax.plot(freq,
                20 * np.log10(np.abs(G)),
                'x',
                markeredgewidth=5,
                markersize=20,
                color=[0, 0, 0.8],
                label="stepped sine")
        fig.canvas.draw()
        fig.canvas.flush_events()

    settings = dvma.MySettings(fs=fs, channels=1)
    tfdata = dvma.TfData(freqs, G1, None, settings, test_name='stepped_sine')
    #ax.plot(freq,20*np.log10(np.abs(G1)),'x',markeredgewidth=5,markersize=20,color = [0, 0, 0.8],label="stepped sine")

    return tfdata
Exemplo n.º 5
0
def measure_tf4(filename='sample2021.wav', fs=8000, T=5.9, fmin=20, fmax=500):
    # signal
    fs, x = wf.read(filename)
    Nend = np.int(np.round(fs * T))
    x = x[0:Nend, 0]
    y = sd.playrec(x, samplerate=fs, channels=1, blocking=True)

    N = len(x)

    f = np.fft.rfftfreq(N, 1 / fs)
    X = np.fft.rfft(x)
    Y = np.fft.rfft(y[:, 0])

    G4 = Y / X

    #%% STORE
    settings = dvma.MySettings(fs=fs, channels=1)
    tfdata = dvma.TfData(f, G4, None, settings, test_name='sample')

    plot_tf(tfdata)
    return tfdata
Exemplo n.º 6
0
def measure_tf3(fs=8000, T=3, fmin=20, fmax=500):
    # noise

    t, win = window_signal(fs, T, Tr=0.1)

    N = len(t)
    x = np.zeros(N)
    y = np.zeros(N)

    f = np.fft.rfftfreq(N, 1 / fs)

    XS = np.zeros(len(f))
    XS[(f > fmin) & (f < fmax)] = 1
    phase = 2 * np.pi * np.random.rand(len(XS))
    XS = XS * np.exp(1j * phase)
    xs = np.fft.irfft(XS)

    xs = win * xs
    #xs = np.transpose(xs)
    x = xs / np.max(np.abs(xs))

    #%% LOG DATA
    print('Sweep: {} to {} (Hz)'.format(fmin, fmax))
    y = sd.playrec(x, samplerate=fs, channels=1, blocking=True)

    X = np.fft.rfft(x)
    Y = np.fft.rfft(y[:, 0])

    G3 = Y / X

    #%% STORE
    settings = dvma.MySettings(fs=fs, channels=1)
    tfdata = dvma.TfData(f, G3, None, settings, test_name='noise')

    plot_tf(tfdata)
    return tfdata