forked from M-Labs/artiq
examples/flopping_f_simulation: fitting
This commit is contained in:
parent
0983862c03
commit
ef32e7aa7a
|
@ -1,10 +1,18 @@
|
||||||
from math import sqrt, cos, pi
|
from math import sqrt, cos, pi
|
||||||
import time
|
import time
|
||||||
|
import random
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
from scipy.optimize import curve_fit
|
||||||
|
|
||||||
from artiq import *
|
from artiq import *
|
||||||
|
|
||||||
|
|
||||||
def model(x, F0=1500, A=80, B=40, t=0.02, tpi=0.03):
|
def model(x, F0):
|
||||||
|
t = 0.02
|
||||||
|
tpi = 0.03
|
||||||
|
A = 80
|
||||||
|
B = 40
|
||||||
return A+(B-A)/2/(4*tpi**2*(x-F0)**2+1)*(1-cos(pi*t/tpi*sqrt(4*tpi**2*(x-F0)**2+1)))
|
return A+(B-A)/2/(4*tpi**2*(x-F0)**2+1)*(1-cos(pi*t/tpi*sqrt(4*tpi**2*(x-F0)**2+1)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +24,9 @@ class FloppingF(AutoDB):
|
||||||
min_freq = Argument(1000)
|
min_freq = Argument(1000)
|
||||||
max_freq = Argument(2000)
|
max_freq = Argument(2000)
|
||||||
|
|
||||||
|
F0 = Argument(1500)
|
||||||
|
noise_amplitude = Argument(0.1)
|
||||||
|
|
||||||
frequency = Result()
|
frequency = Result()
|
||||||
brightness = Result()
|
brightness = Result()
|
||||||
|
|
||||||
|
@ -30,16 +41,16 @@ class FloppingF(AutoDB):
|
||||||
def run(self):
|
def run(self):
|
||||||
for i in range(self.npoints):
|
for i in range(self.npoints):
|
||||||
frequency = (self.max_freq-self.min_freq)*i/(self.npoints - 1) + self.min_freq
|
frequency = (self.max_freq-self.min_freq)*i/(self.npoints - 1) + self.min_freq
|
||||||
brightness = model(frequency)
|
brightness = model(frequency, self.F0) + self.noise_amplitude*random.random()
|
||||||
self.frequency.append(frequency)
|
self.frequency.append(frequency)
|
||||||
self.brightness.append(brightness)
|
self.brightness.append(brightness)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
self.analyze()
|
self.analyze()
|
||||||
|
|
||||||
def analyze(self):
|
def analyze(self):
|
||||||
min_f = self.frequency.read[0]
|
popt, pcov = curve_fit(lambda xdata, F0: [model(x, F0) for x in xdata],
|
||||||
min_b = self.brightness.read[0]
|
self.frequency.read, self.brightness.read,
|
||||||
for f, b in zip(self.frequency.read, self.brightness.read):
|
p0=[self.flopping_freq])
|
||||||
if b < min_b:
|
perr = np.sqrt(np.diag(pcov))
|
||||||
min_f, min_b = f, b
|
if perr < 0.1:
|
||||||
self.flopping_freq = min_f
|
self.flopping_freq = float(popt)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{}
|
{"flopping_freq": 1500.0294421161527}
|
||||||
|
|
Loading…
Reference in New Issue