Beispiel #1
0
den = [1,2*z*wn,wn**2]

# 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()
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()