120 Random-process Simulation and Monte Carlo Studies with Noisy Signals
-- VECTORIZED MONTE SIMULATION OF A NOISY SERVO
-- note noise sampling and initialization
----------------------------------------------------------------------------------------------------
A = 0.1 | omega = 1.2 | -- input-signal parameters
a = 4000 | w = 100 | -- noise parameters
k = 40 | r = 2 | g1 = 10000 | -- controller parameters
B = 100 | maxtrq=1 | g2=2 | R=0.6 | -- servo parameters
----------------------------------------------------------------------------------------------------
TMAX = 7.5 | DT = 0.001 | NN = 3750 | scale = 1
display N1 | display C8 | display R | -- display colors
--------
n = 1000
STATE p[n], unoise[n], x[n], xdot[n], v[n]
ARRAY noise[n], voltage[n], torque[n], e[n]
-- initialize noise
for i = 1 to n | noise[i] = a * (ran()+ran()+ran()+ran()) | next
--
drun
write "eAvg = ";eAvg;" eeAvg = ";eeAvg
----------------------------------------------------------------------------------------------------
DYNAMIC
----------------------------------------------------------------------------------------------------
Vectr d/dt p = - w * p + noise | -- two-section
Vectr d/dt unoise = - w * unoise + p | -- low-pass filter
--
u = A * cos(omega * t) | -- servo input for all n models
Vector e = x - u | -- servo error
Vector voltage = - k * e - r * xdot + unoise | -- noisy motor voltage
Vectr d/dt v = - B * v + g1 * voltage | -- motor-field buildup
--
Vector torque = maxtrq * tanh(g2 * v/maxtrq) | -- dynamics
Vectr d/dt x = xdot | Vectr d/dt xdot = torque-R * xdot
------------------------------------------------------------------
-- sample at sampling points
OUT
Vector noise = a * (ran()+ran()+ran() +ran()) | -- sampled noise
--
DOT eSum = e * 1 | DOT eeSum = e * e | -- compute averages
eAvg = eSum/n | eeAvg = eeSum/n
----------------------------------------------------------------------------------------------------
-- offset curves for a rescaled stripchart display
--
X = 5 * x[17] + 0.5 * scale
U = 5 * u + 0.5 * scale | Unoise = 0.5 * unoise[17] + 0.5 * scale
error10 = 10 * e[17]
eAvg10 = 10 * eAvg - 0.5 * scale
eeAvg100 = 100 * eeAvg - scale
dispt X, U, Unoise, error10, eAvg1000, eeAvg100
FIGURE 5-5
a
. The vectorized Monte Carlo simulation program for the noise-perturbed
servomechanism is similar to Figure 5-4b, but note the different servo input and motor voltage.