예제 #1
0
def plot_complex(f0, a_norm, do_plots):

    sr = 48000

    dur = 3
    t = np.linspace(0, 2 * np.pi * f0 * dur, sr * dur)
    audio = np.sin(t)
    audio = np.append(audio, np.zeros(sr))

    method = DetectorBank.runge_kutta
    f_norm = DetectorBank.freq_unnormalized

    d = 0.0001
    gain = 5
    f = np.array([f0])
    bandwidth = np.zeros(len(f))
    det_char = np.array(list(zip(f, bandwidth)))

    det = DetectorBank(sr, audio.astype(np.float32), 4, det_char,
                       method | f_norm | a_norm, d, gain)

    z = np.zeros((len(f), len(audio)), dtype=np.complex128)
    det.getZ(z)

    r = np.zeros(z.shape)
    det.absZ(r, z)

    # number of oscillations to plot
    nOsc = 5
    # signal may have been modulated by DetectorBank
    # detFreq is the frequency the detector is actually operating at, therefore
    # the frequency of the orbits
    detFreq = det.getW(0) / (2 * np.pi)
    # number of samples in nOsc
    sOsc = int(nOsc / detFreq * sr)

    t0 = (dur * sr) - sOsc  # int(0.0 * sr)
    t1 = dur * sr  # int(nOsc/f[0] * sr)

    x = z[0].real[t0:t1]
    y = z[0].imag[t0:t1]

    c = ['darkmagenta']

    a, b = getEllipseParams(x, y)
    e = np.sqrt(a**2 - b**2) / a

    if do_plots:
        plt.plot(x, y, c[0])
        plt.grid()

        plt.title('{}Hz'.format(f0))
        plt.xlabel('real')
        plt.ylabel('imag')

        plt.show()
        plt.close()

    return e
예제 #2
0
def getMax(f0, sr, method, f_norm):
    """ Get maximum abs value in response. Also returns internal detector
        frequency (which will be different from f0 if search normalisation is
        used)
        
        Parameters
        ----------
        fo : float
            Centre frequency
        sr : int
            Sample rate
        method : DetectorBank Feature
            Numerical method
        f_norm : DetectorBank Feature
            Frequency normalisation
    
        Returns
        -------
        z value at point which is max value in |z|, max value in |z|,
        frequency used by detector 
    """

    f = np.array([f0])
    b = np.zeros(len(f))
    det_char = np.array(list(zip(f, b)))
    d = 0.0001
    amp = 5
    a_norm = DetectorBank.amp_unnormalized

    audio = make_audio(f0, 1, 4, sr)

    det = DetectorBank(sr, audio.astype(np.float32), 4, det_char,
                       method | f_norm | a_norm, d, amp)

    z = np.zeros((len(f), len(audio)), dtype=np.complex128)
    r = np.zeros(z.shape)

    det.getZ(z)
    m = det.absZ(r, z)

    i = np.where(r[0] == m)[0][0]
    mz = z[0][i]

    f_adjusted = det.getW(0) / (2 * np.pi)

    return mz, m, f_adjusted
예제 #3
0
r = np.zeros(z.shape)

det = DetectorBank(sr, audio, 4, det_char, method | f_norm | a_norm, d, amp)

det.getZ(z)
det.absZ(r, z)

t = np.linspace(0, len(audio) / sr, len(audio))
c = ['darkmagenta', 'orange', 'red']
style = ['-', ':', '--']
#t *= 1000
t0 = 0
t1 = len(audio)  # int(sr * 0.2) #
for k in range(len(r)):
    plt.plot(t[t0:t1], r[k][t0:t1], c[k], label=f[k])
    print('Det freq: {}Hz'.format(det.getW(k) / (2 * np.pi)))
#    plt.plot(t[t0:t1], r[k][t0:t1], 'black', label=f[k], linestyle=style[k])

#### make table of time advances

# need a new DetectorBank for this, as we're using more frequencies
f = np.linspace(f0, f0 + 5, num=11)

bandwidth = np.zeros(len(f))
det_char = np.array(list(zip(f, bandwidth)))

z = np.zeros((len(f), len(audio)), dtype=np.complex128)
r = np.zeros(z.shape)

det = DetectorBank(sr, audio, 4, det_char, method | f_norm | a_norm, d, amp)
det.getZ(z)
예제 #4
0
def plot_complex(f0, i, nOsc, end):

    d = 0.0001

    sr = 48000

    dur = 5
    t = np.linspace(0, 2 * np.pi * f0 * dur, sr * dur)
    audio = np.sin(t)
    audio = np.append(audio, np.zeros(sr))
    gain = 5

    method = DetectorBank.runge_kutta  #central_difference #
    f_norm = DetectorBank.freq_unnormalized
    a_norm = DetectorBank.amp_unnormalized
    d = 0.0001
    gain = 5
    f = np.array([f0])
    bandwidth = np.zeros(len(f))
    det_char = np.array(list(zip(f, bandwidth)))

    det = DetectorBank(sr, audio.astype(np.float32), 4, det_char,
                       method | f_norm | a_norm, d, gain)

    z = np.zeros((len(f), len(audio)), dtype=np.complex128)
    det.getZ(z)

    r = np.zeros(z.shape)
    det.absZ(r, z)

    # number of oscillations to plot
    # signal may have been modulated by DetectorBank
    # detFreq is the frequency the detector is actually operating at, therefore
    # the frequency of the orbits
    detFreq = det.getW(0) / (2 * np.pi)
    # number of samples in nOsc
    sOsc = int(nOsc / detFreq * sr)

    if end == 'first':
        t0 = 0
        t1 = sOsc
    elif end == 'last':
        t0 = (dur * sr) - sOsc
        t1 = dur * sr

    x = z[0].real[t0:t1]
    y = z[0].imag[t0:t1]

    c = ['darkmagenta']

    a, b = getEllipseParams(x, y)
    e = np.sqrt(a**2 - b**2) / a

    plt.plot(x, y, c[0])
    plt.grid(True)

    plt.xlabel('real')
    plt.ylabel('imag')

    fig = plt.gcf()
    fig.set_size_inches(8, 8)

    plt.show()
    plt.close()

    return e