Example #1
0
# create some data
tf = TransferFunction(num,den)
t = arange(0,2,.01)
u = create_step_vector(t, step_time=.5, amp=1.0)
y = tf.lsim(u,t)

#################################################
# start systemid
num_dict = {'0':'g*wn**2'}
den_dict = {'2':'1','1':'2*z*wn','0':'wn**2'}
var_dict = {'g':1,'z':z,'wn':10}
to_opt_dict = {'g':5,'z':z,'wn':10}

data = time_data(t,u,y)

###############################

model = Model(num_dict,den_dict,var_dict,to_opt_dict)

opt_dict = fit_time(model,data)
opt_model = Model(num_dict,den_dict,opt_dict)

fig = figure(1)
model.plot_resp(data.t,data.input,fig=fig,clear=True,linelabel='Initial Guess')
opt_model.plot_resp(data.t,data.input,fig=fig,clear=False,title='Model vs. Exp',linelabel='Opt',linewidth=5,linestyle=':')
data.plot_output(fig=fig,clear=False,linelabel='Output',linestyle='--')
data.plot_input(fig=fig,clear=False,linelabel='Input',linestyle='-',linewidth=1)

show()
z =  .5#0.8318682051
num_dict = {'0':'A'}
den_dict = {'2':'1','1':'z*p','0':'p**2'}
var_dict = {'A':A,'p':p,'z':z}
to_opt_dict = {'A':A,'p':p,'z':z}

usecols = (0,2,4)
datafile = 'swept.txt'

data = time_data_file(datafile)
data.read(usecols,skiprows=3)
#data.resample(2)
#data.scale_t(1.0/250)
#data.scale_output(1.0/128/4*2*pi)

model = Model(num_dict,den_dict,var_dict,to_opt_dict)

opt_dict = fit_time(model,data)
opt_model = Model(num_dict,den_dict,opt_dict)


# Time Data Stuff

fig = figure(1)

model.plot_resp(data.t,data.input,fig=fig,clear=True,title='Model vs. Exp',linelabel='Initial Guess')
opt_model.plot_resp(data.t,data.input,fig=fig,clear=False,linelabel='Optimized Model')
data.plot_input(fig=fig,clear=False,linelabel='Data Input')
data.plot_output(fig=fig,clear=False,linelabel='Data Output')

# Frequency Data Stuff
usecols = (0,2,4)

datafile = 'step.txt'

data = time_data_file(datafile)
data.read(usecols,skiprows=3)
#data.resample(2)
#data.scale_t(1.0/250)
#data.scale_output(1.0/128/4*2*pi)

##############################
# remove steady state stuff

inds = data.t<.7
new_data = time_data(data.t[inds],data.input[inds],data.output[inds])

###############################

model = Model(num_dict,den_dict,var_dict,to_opt_dict)

opt_dict = fit_time(model,new_data)
opt_model = Model(num_dict,den_dict,opt_dict)

fig = figure(1)
model.plot_resp(new_data.t,new_data.input,fig=fig,clear=True,linelabel='Initial Guess')
opt_model.plot_resp(new_data.t,new_data.input,fig=fig,clear=False,title='Model vs. Exp',linelabel='Opt')
new_data.plot_output(fig=fig,clear=False,linelabel='Output')
new_data.plot_input(fig=fig,clear=False,linelabel='Input')

show()
Example #4
0
num_dict = {"0": "A*p"}
den_dict = {"2": "1", "1": "p", "0": "A*p"}
var_dict = {"A": A, "p": p}
to_opt_dict = {"A": A, "p": p}

usecols = (0, 2, 4)
fixed_sine_freq = 5.0
datafile = "fixed.txt"

data = time_data_file(datafile)
data.read(usecols, skiprows=3)
# data.resample(2)
# data.scale_t(1.0/250)
# data.scale_output(1.0/128/4*2*pi)

model = Model(num_dict, den_dict, var_dict, to_opt_dict)

opt_dict = fit_time(model, data)
opt_model = Model(num_dict, den_dict, opt_dict)


# Time Data Stuff

fig = figure(1)

model.plot_resp(data.t, data.input, fig=fig, clear=True, title="Model vs. Exp", linelabel="Initial Guess")
opt_model.plot_resp(data.t, data.input, fig=fig, clear=False, linelabel="Optimized Model")
data.plot_input(fig=fig, clear=False, linelabel="Data Input")
data.plot_output(fig=fig, clear=False, linelabel="Data Output")

# Frequency Data Stuff