Skip to content

Instantly share code, notes, and snippets.

@jondoesntgit
Last active December 15, 2017 00:34
Show Gist options
  • Save jondoesntgit/e129cf8b119a6f47e565e2a68743b720 to your computer and use it in GitHub Desktop.
Save jondoesntgit/e129cf8b119a6f47e565e2a68743b720 to your computer and use it in GitHub Desktop.
Scale Factor Fitting for Voltage
%pylab inline
from hardware import *
import pyfog
import time
import pandas as pd
from scipy.optimize import curve_fit
scale_factors = pd.DataFrame(columns=['scale_factor'])
for vpp in linspace(1.6, 2.5, 5):
awg.voltage = vpp
time.sleep(2)
scale_factors.loc[vpp] = fog.get_scale_factor(sensitivity=.1)
from scipy.optimize import curve_fit
def fit(V, A, Vpi):
return -A*pi/(2*Vpi) * sin(V*pi/Vpi)
params, varmatrix = curve_fit(fit, scale_factors.index, 1/scale_factors['scale_factor'].values, p0=(max(1/scale_factors['scale_factor']), 2.25))
xs = linspace(1.5, 3.2, 40)
plot(1/scale_factors, 'o')
plot(xs, fit(xs, *params))
# Use this to get the scale factor for a given voltage
def sf(V):
return 1/fit(V, *params)
print(params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment