예제 #1
0
def overshoot(det):
    '''
    How do I get me a decaying overshoot?
    '''

    lowpass = DigitalFilter(2)
    lowpass.num = [1, 2, 1]
    lowpass.set_poles(0.975, 0.007)

    hipass = DigitalFilter(1)
    hipass.num, hipass.den = rc_decay(82, 1E9)

    det.AddDigitalFilter(lowpass)
    # det.AddDigitalFilter(hipass)

    wf_proc = np.copy(
        det.MakeSimWaveform(25, 0, 25, 1, 125, 0.95, wf_length, smoothing=20))
    wf_compare = np.copy(wf_proc)

    f, ax = plt.subplots(2, 2, figsize=(15, 8))
    # plt.figure()
    ax[0, 0].plot(wf_compare, color="r")
    cmap = cm.get_cmap('viridis')

    new_filt = DigitalFilter(1)
    det.AddDigitalFilter(new_filt)

    p_mags = 1 - np.logspace(-4, -2, 100, base=10)
    z_mags = 1 - np.logspace(-4, -2, 20, base=10)

    for zero_mag in [5E-4]:  #z_mags:
        for pole_mag in np.logspace(-7, -5, 100, base=10):  #p_mags:
            zero_mag = 1 - zero_mag
            pole_mag = zero_mag - pole_mag

            if zero_mag == pole_mag: continue

            color = "b"
            # color = cmap( (mag2 - mags[0])/(mags[-1] - mags[0]) )
            new_filt.set_zeros(zero_mag, 0)
            new_filt.set_poles(pole_mag, 0)

            # print (new_filt.num, np.sum(new_filt.num))
            # print (new_filt.den, np.sum(new_filt.den))
            # exit()

            wf_proc = np.copy(
                det.MakeSimWaveform(25,
                                    0,
                                    25,
                                    1,
                                    125,
                                    0.95,
                                    1000,
                                    smoothing=20))

            try:
                if wf_proc[155] < 1.00001: continue
                if np.amax(wf_proc) > 1.1: continue
                print(zero_mag, pole_mag)
                p = ax[0, 0].plot(wf_proc)
                color = p[0].get_color()
                ax[1, 0].plot(wf_proc - wf_compare, color=color)
            except (TypeError, IndexError) as e:
                continue

            w, h2 = get_freq_resp(new_filt,
                                  w=np.logspace(-15, 0, 500, base=np.pi))
            ax[0, 1].loglog(w, h2, color=color)

            p[0] = ax[1, 1].scatter(zero_mag, 0, color=color)
            ax[1, 1].scatter(pole_mag, 0, color=color, marker="x")
            an = np.linspace(0, np.pi, 200)
            ax[1, 1].plot(np.cos(an), np.sin(an), c="k")
            ax[1, 1].plot(np.cos(an), -np.sin(an), c="k")
            ax[1, 1].axis("equal")

    plt.show()
예제 #2
0
def oscillation(det):
    '''
    How do I get me a decaying oscillation?
    '''

    lowpass = DigitalFilter(2)
    lowpass.num = [1, 2, 1]
    lowpass.set_poles(0.975, 0.007)

    hipass = DigitalFilter(1)
    hipass.num, hipass.den = rc_decay(82, 1E9)

    det.AddDigitalFilter(lowpass)
    # det.AddDigitalFilter(hipass)

    wf_proc = np.copy(
        det.MakeSimWaveform(25, 0, 25, 1, 125, 0.95, wf_length, smoothing=20))
    wf_compare = np.copy(wf_proc)

    f, ax = plt.subplots(2, 2, figsize=(15, 8))
    # plt.figure()
    ax[0, 0].plot(wf_compare, color="r")
    cmap = cm.get_cmap('viridis')

    new_filt = DigitalFilter(2)
    det.AddDigitalFilter(new_filt)
    new_filt.num = [1, 2, 1]

    p_mags = 1 - np.logspace(-3, -2, 20, base=10)
    p_phis = [0.5 * np.pi**-3]
    # p_phis = np.logspace(-5, 1, 4, base=np.pi)
    # z_mags = 1 - np.logspace(-4, -2, 20, base=10)

    pole_phi = 0.5 * np.pi**-3
    pole_mag = 0.995

    for i in range(3):

        # for pole_phi in p_phis:
        #     for pole_mag in p_mags:
        # zero_mag = 1-zero_mag
        # pole_mag = zero_mag + pole_mag
        # if zero_mag == pole_mag: continue

        color = get_color(cmap, pole_mag, p_mags)
        if i == 0:
            color = "k"
        elif i == 1:
            new_filt.set_zeros(0.99, 0.01)
            color = "b"
        elif i == 2:
            new_filt.set_zeros(0.995, 0.001)
            color = "g"
        new_filt.set_poles(pole_mag, pole_phi)

        # print (new_filt.num, np.sum(new_filt.num))
        # print (new_filt.den, np.sum(new_filt.den))
        # exit()

        wf_proc = np.copy(
            det.MakeSimWaveform(25, 0, 25, 1, 125, 0.95, 1000, smoothing=20))

        try:
            # if wf_proc[155] < 1.00001: continue
            # # if np.amax(wf_proc) > 1.1: continue
            # print( zero_mag, pole_mag)
            p = ax[0, 0].plot(wf_proc, color=color)
            # color = p[0].get_color()
            ax[1, 0].plot(wf_proc - wf_compare, color=color)
        except (TypeError, IndexError) as e:
            continue

        w, h2 = get_freq_resp(new_filt, w=np.logspace(-15, 0, 500, base=np.pi))
        ax[0, 1].loglog(w, h2, color=color)
        ax[0, 1].axvline(pole_phi / (np.pi / nyq_freq))

        # p[0] = ax[1,1].scatter(zero_mag, 0, color=color)
        ax[1, 1].scatter(pole_mag * np.cos(pole_phi),
                         pole_mag * np.sin(pole_phi),
                         color=color,
                         marker="x")
        an = np.linspace(0, np.pi, 200)
        ax[1, 1].plot(np.cos(an), np.sin(an), c="k")
        ax[1, 1].plot(np.cos(an), -np.sin(an), c="k")
        ax[1, 1].axis("equal")

    plt.show()