示例#1
0
文件: figure10.py 项目: righetti/AFOs
def simulate_pool(N, K, lamb, eta, amplitudes, frequencies, phases, dt):
    save_dt = 10**-3
    t_end = 50. #50 * 2 * np.pi / omegaC#30.
    t_start = 0.

    oscill = pyafos.PoolAFO()
    oscill.initialize(N, K, lamb, eta)
    oscill.input().vec_of_sines(frequencies, amplitudes, phases)

    phi0 = np.zeros([3])
    alpha0 = np.zeros([3])
    omega0 = np.array([40., 69., 71.])/lamb
    x0 = np.hstack([phi0, omega0, alpha0])
    pyafos.integrate(oscill, t_start,t_end,x0,dt,save_dt)

    #generate data to be plotted    
    t = oscill.t()
    phi = oscill.y()[0:3,:]
    omega = lamb*oscill.y()[3:6,:]
    alpha = oscill.y()[6:,:]
    
    return t, phi, omega, alpha
示例#2
0
文件: figure9.py 项目: righetti/AFOs
def simulate_pool(N, K, lamb, eta, amplitudes, frequencies, phases):
    dt = 10**-5  #need 10-7 for Euler with K = 10*7
    save_dt = 10**-3
    t_end = 21.  #50 * 2 * np.pi / omegaC#30.
    t_start = 0.

    oscill = pyafos.PoolAFO()
    oscill.initialize(N, K, lamb, eta)
    oscill.input().vec_of_sines(frequencies, amplitudes, phases)

    phi0 = np.zeros([N])
    alpha0 = np.ones([N]) * 0
    omega0 = np.array([50.]) / lamb  #np.array([40., 69., 71.])/lamb
    x0 = np.hstack([phi0, omega0, alpha0])
    pyafos.integrate(oscill, t_start, t_end, x0, dt, save_dt)

    #generate data to be plotted
    t = oscill.t()
    phi = oscill.y()[0:N, :]
    omega = lamb * oscill.y()[N:2 * N, :]
    alpha = oscill.y()[2 * N:, :]

    return t, phi, omega, alpha
示例#3
0
def find_frequency_response(arg):
    lamb = arg[0]
    omegaC = arg[1]

    K = 10.**5
    omegaF = 1000.

    dt = 10**-5

    if omegaC < 50.:
        save_dt = 10**-4
    else:
        save_dt = 10**-5

    # here the convergence rate is too slow - leads to large transcient
    if lamb < 1.:
        min_time = 200.
    else:
        min_time = 100.

    max_time = 10000.

    print("processing lambda = " + str(lamb) + " and omegaC = " + str(omegaC))

    oscill = pyafos.PhaseAFO()
    oscill.initialize(K, lamb)
    oscill.input().frequency_changing_sine(omegaF, omegaC)

    # set initial conditions
    # we want to measure at least 50 oscillations of omegaC
    # 50 * 2pi/omegaC
    t_end = np.min([np.max([50 * 2 * np.pi / omegaC, min_time]), max_time])
    t_start = 0.
    omega0 = (omegaF + 1.) / lamb
    phi0 = 0.

    pyafos.integrate(oscill, t_start, t_end, np.array([phi0, omega0]), dt,
                     save_dt)

    omega = lamb * oscill.y()[1, :]
    t = oscill.t()

    mins, maxs = find_envelop(omega)

    n_min = mins[:, 1].size
    n_max = maxs[:, 1].size
    if n_min < n_max:
        track = 0.5 * (mins[:, 1] + maxs[:-(n_max - n_min), 1])
        track_signal = omegaF + np.cos(omegaC * t[mins.astype(int)[:, 0]])
    elif n_min == n_max:
        track = 0.5 * (mins[:, 1] + maxs[:, 1])
        track_signal = omegaF + np.cos(omegaC * t[mins.astype(int)[:, 0]])
    else:
        track = 0.5 * (mins[:, 1] + maxs[:-(n_min - n_max), 1])
        track_signal = omegaF + np.cos(omegaC * t[maxs.astype(int)[:, 0]])

    # we get rid of the first half of the signal, make sure no transcients are here
    track = track[int(track.size / 2):]
    track_signal = track_signal[int(track_signal.size / 2):]

    response = scipy.signal.hilbert(
        track - np.mean(track)) / scipy.signal.hilbert(track_signal - omegaF)

    # we only keep the middle third of the response to remove boarder effects
    si = response.size
    am = np.mean(np.abs(response[int(si / 3):int(2 * si / 3)]))
    #to make sure all is close to each other
    angle = np.unwrap(np.angle(response[int(si / 3):int(2 * si / 3)]))
    ph = np.mean(angle - 2 * np.pi) % (-2 * np.pi)
    if np.abs(ph) > 1.8 * np.pi:
        ph = ph + 2 * np.pi
    # ph = np.mean((np.angle(response[int(si/3):int(2*si/3)]) - 2 * np.pi))%(-2*np.pi)
    print("done with lambda = " + str(lamb) + " and omegaC = " + str(omegaC) +
          "found " + str(am) + " " + str(ph))

    # amplitude[i,j] = am
    # phase[i,j] = ph
    return am, ph
示例#4
0
freq = omegaF * np.array([1., 2., 3.])
amp = np.array([1.3, 1., 1.4])
phase = np.array([0.4, 0.0, 1.3]) + np.pi / 2.0
lamb = 1
dt = 10**-7
save_dt = 10**-3
t_end = 8.
t_start = 0.
omega0 = 20. / lamb
phi0 = 0.

#run an integration
oscill = pyafos.PhaseAFO()
oscill.initialize(K, lamb)
oscill.input().vec_of_sines(freq, amp, phase)
pyafos.integrate(oscill, t_start, t_end, np.array([phi0, omega0]), dt, save_dt)

#get the data to be plotted
t = oscill.t()
phi = oscill.y()[0, :]
omega = oscill.y()[1, :]

deltaT = np.linspace(0.0, 2 * pi / omegaF, 10000)
roots = find_roots(deltaT, freq, amp, phase)
roots_corrected = roots + (2. * pi / omegaF - roots[-1])
n_roots = size(roots)
print('num roots is ', n_roots)
print('roots ', roots)
print('roots corrected', roots_corrected)

#     omega_bar_p = omegaF * n_roots * (0.5 / lamb) + pi + omegaF * 0.5 * sum(roots[:-1])
示例#5
0
    def process_parallel(i, j):
        K = KSweep[i]
        om = omegaSweep[j]

        if K > 5:
            return
        if (om < 45) or (om > 80) or (om > 52 and om < 71):
            return

        if K < 5:
            T = 3600.
        elif K < 10:
            T = 1800.
        else:
            T = 300.
        # elif K < 50:
        #   T = 200.
        # else:
        #   T = 100.
        # T = 300.

        print("processing K = " + str(K) + " and omega = " + str(om))

        oscill = pyafos.DualPhasePhaseAFO()
        oscill.input().vec_of_sines(omegaPert, amplitudePert, phasePert)

        oscill.initialize(K, lamb, om)
        pyafos.integrate(oscill, 0.0, T, np.array([0., 0., om]), dt, save_dt)

        t = oscill.t()
        mid_point = int(3 * len(t) / 4)
        phiNormal = oscill.y()[0, :]
        omegaAFO = oscill.y()[2, :]

        # the average frequency of oscillations of the normal phase osc.
        avg_freq[i, j] = np.mean(np.diff(phiNormal) / save_dt)

        # the frequency of convergence of omega
        conv_freq[i, j] = np.mean(omegaAFO[mid_point:])

        # the max error between the mean converged frequency and the oscillations
        amp_error[i,
                  j] = np.max(np.abs(omegaAFO[mid_point:] - conv_freq[i, j]))

        # compute the frequency toward which it has converged (from the input signal)
        dis = np.abs(omegaPert - conv_freq[i, j])
        f = omegaPert[np.argwhere(dis == np.min(dis))][0, 0]

        # print('converged to: ' + str(f) + ' with conv freq ' + str(conv_freq[i,j]) + 'normal oscill avg. freq ' + str(avg_freq[i,j]))

        # if the conv_freq is close enough to f - then compute
        # mean error between exponential convergence using F and omega
        # max error between exponential convergence using F and omega
        if np.abs(f - conv_freq[i, j]) > 2 * np.pi:
            mean_error[i, j] = float('nan')
            max_error[i, j] = float('nan')
            print('NaN')
        else:
            y_avg = f + (om - f) * np.exp(-t)
            mean_error[i, j] = np.mean(omegaAFO - y_avg)
            max_error[i, j] = np.max(np.abs(omegaAFO - y_avg))
示例#6
0
文件: figure12.py 项目: righetti/AFOs
eta = 0.5

dt = 10**-5  #need 10-7 for Euler with K = 10*7
save_dt = 10**-3
t_end = 40.  #50 * 2 * np.pi / omegaC#30.
t_start = 0.

oscill = pyafos.PoolAFO()
oscill.initialize(N, K, lamb, eta)
oscill.input().chirps_and_exponentials()

phi0 = np.zeros([N])
alpha0 = np.zeros([N])
omega0 = np.random.uniform(50, 500, N) / lamb
x0 = np.hstack([phi0, omega0, alpha0])
pyafos.integrate(oscill, t_start, t_end, x0, dt, save_dt)

#generate data to be plotted
t = oscill.t()
phi = oscill.y()[0:N, :]
omega = lamb * oscill.y()[N:2 * N, :]
alpha = oscill.y()[2 * N:, :]

in_signal = get_chirp_exp_input(t)
output = get_pool_output(phi, alpha)

mp.rc('lines', lw=6)
mp.rc('savefig', format='pdf')
mp.rc('font', size=80)
mp.rc('text', usetex=True)
mp.rc('figure', figsize=(19.8875, 2 * 15.9125))