# Here I define constants of the model
c_til = 50 # air particle velocity, m/s
d_len = 0.0175 # length of vocal folds, m
x_0 = 0.001 # half glottal width at rest position, m
sol_0 = [0,0.1,0,0.1] # Initial state from papers (reference) (x(0),x'(0),y(0),y'(0))
theta = [c_til,d_len,x_0]
if(dataset == 'Synthetic'):
if(dataset == 'Synthetic'):
# Here I define a synthetic dataset just to test the fit
A = 0.50 # Reference value
B = 0.32 # Reference value
D = 0.00 # Reference value
t = np.linspace(0,60*pi,1000)
data , tgt = ode_solver(A,B,D,sol_0,t)
data = data + 0.1*np.random.normal(size=t.shape) # Add a noise to see the robustness.
else:
# Here I upload a given audio file
t, signal , glot_flow, sr = load_audio('target.WAV')
t = t[:900]
data = glot_flow[:900] * 1.0e-01
else:
# Here I upload a given audio file
t, signal , glot_flow, sr = load_audio('target.WAV')
t = t[:900]
data = glot_flow[:900] * 1.0e-01
Step 2, declare the parameters to fit, plus the min-max limits and other props.
# Define the initial shoot and ranges for the parameters to fit
ID = ['A' ,'B' ,'D']
if(dataset == 'Synthetic'):
i0 = [0.50,0.50,0.50] # This one works for synthetic
else:
i0 = [0.50,0.50,0.50]
vi , vf = [0,0,0] , [1,1,1] # According to code, they are always between (0,1)
Step 3, Define and call the lmfit minimizer stuff
# According to lmfit, you must define ranges for parameters and initial guess
params = lmf.Parameters()
params.add(ID[0],value=i0[0], min=vi[0], max=vf[0]) # alpha
params.add(ID[1],value=i0[1], min=vi[1], max=vf[1]) # beta
params.add(ID[2],value=i0[2], min=vi[2], max=vf[2]) # Delta
# lmfit minimizer
foo = lmf.Minimizer(residual_ode, params,fcn_kws={'t': t, 'data':data,'ID':ID, 'theta':theta, 'sol_0':sol_0})
result = foo.minimize(method='leastsq')
lmf.report_fit(result)
As you can notice from the figures I shared before, the synthetic case works well... I mean I