## Reduce Fast Dynamics

You can make your model real-time capable by identifying and reducing sources of fast or high-frequency dynamics. A real-time capable model is one that produces acceptable results on a real-time machine without generating overruns. The example shows you how to identify fast dynamics by examining the frequency response and pole locations of a linearized model. It also shows how to identify and remove sources of the fast dynamics.

### Why Reduce Fast Dynamics

Models with fast dynamics typically have a high computational cost. Removing fast dynamics decreases the computational cost and increases the minimum step size that you can specify for a fixed-step, fixed-cost simulation. Using a larger step size increases the likelihood that your model is real-time capable.

### Frequency-Response Analysis

*Frequency response* describes the steady-state
response of a system to sinusoidal inputs. For a linear system, a sinusoidal input
results in an output that is a sinusoid with the same frequency,
*ω*, but with a different amplitude and phase,
*θ*.

Frequency analysis shows how amplitude and phase change over a given range of frequencies. For a small change in frequency, a large magnitude or phase change indicates that a system has fast dynamics. This example uses Bode plots, which allow you to see how the amplitude, in terms of magnitude in dB, and phase vary as a function of frequency.

### Pole Analysis

Fast poles are also indicative of fast dynamics. Fast poles are poles that respond
or oscillate rapidly. Poles that have real components that are far to the left of
the imaginary axis on the complex plane have a fast response speed. Complex pole
pairs that have imaginary components that are far from the real axis oscillate
rapidly. For example, the real pole at -1500 has a faster response speed than the
real pole at -1000 and the complex pole pair at -500 ± 1500*i* has
a faster oscillation speed than the complex pole pair at -500 ±
500*i*.

For state-space models, the poles are the eigenvalues of the
*A*-matrix. This example shows you how to examine pole speed by
determining the state-space model and then, calculating and plotting the eigenvalues
of the *A*-matrix values.

### Linearize the Model

The model in this example is not linear. Before performing the frequency-response and pole analyses, trim, that is extract and specify operating points for linearization, and linearize the model.

Open and examine the model. At the MATLAB

^{®}command prompt, enter:%% Open the model open_system('ssc_hydraulic_actuator_digital_control')

In addition to signal-generation, operation, routing, and visualization blocks, the model contains these blocks:

**Controller**— A Transfer Fcn block that defines a continuous time representation of the control system. A callback function for the model saves the numerator,*num*, and denominator,*den*, of the transfer function as variables in the workspace.— A Transport Delay block to represent the delays associated with computational delay and the sample-and-hold function when deploying a discrete-time implementation of the continuous time control system.

**Linearization I/O points**— A subsystem that allows you to configure the system as a closed loop, for trimming, or as an open loop, for linearization. The callback function for the model configures the system as closed loop by setting*ClosedLoop*to`1`

in the workspace.**Hydraulic Actuator**— A subsystem that contains the physical model of the plant.

Find a suitable operating point for linearizing the system. Simulate the model, extract the data from the Simscape™ logging nodes, then plot and examine the results.

Script for Simulating the Model and Plotting the Results

The custom two-way valve is open when the simulation time,

*t*, is 2–3 seconds.Trim the model. Perform closed-loop simulation, using

*t*= 2.5 seconds, when the valve is open, for the operating point.Linearize an open-loop configuration of the continuous time model and save the state variables,

*a*,*b*,*c*, and*d*in the workspace using the`linmod`

function.

### Perform Frequency-Response and Pole-Speed Analyses

Generate a Bode plot.

Script for Generating a Bode Plot

When the frequency,

*ω*, is between 10^{2}and 10^{3}Hz, the phase drops by approximately 600 degrees. The rapid change in the phase shift, θ, indicates that the system has fast dynamics.Calculate eigenvalues of the

*a*matrix using the`eig`

function and plot the poles in the complex plane.Script for Calculating and Plotting the

*A*-Matrix EigenvaluesThere are six fast poles, including two potential oscillating pole pairs.

Confirm that there are pole pairs. Print the values of the six fast poles to the command window using the

`eigs`

function.Script for Printing Pole Values

ans = 1.0e+03 * -2.0000 + 1.1547i -2.0000 - 1.1547i -0.4614 + 1.4208i -0.4614 - 1.4208i -1.0314 + 0.0000i -1.0000 + 0.0000i

There are two sets of pole pairs.

### Identify and Eliminate the Sources of Fast Dynamics

Examine the model for potential sources of fast dynamics.

To linearize the model, this example uses the

`linmod`

function. The documentation for the`linmod`

advises against using the function to linearize a model that contains a Transport Delay block. The documentation for the Transport Delay block indicates that the Pade approximation for a linearization routine can add dynamic states to a model. Determine if the block is the source of the fast poles that result in the linearized model.To simulate the model without the effects of the Transport Delay block, comment through the block.

Script for Commenting Out Transport Delay Block

The icon for the Transport Delay fades to indicate that it is commented through.

To examine the frequency response of the model without the effects of the Transport Delay block, trim, linearize, and simulate the model, and then, update the Bode plot.

Script for Trimming and Linearizing the Model and Updating the Bode Plot

When the frequency,

*ω*, is between 10^{2}and 10^{3}Hz, the phase drops by only by ~250 degrees.Calculate and plot the fast poles.

Script for Calculating and Plotting the

*A*-Matrix EigenvaluesThe Transport Delay block is responsible for the missing oscillatory pole pair at -2000 ± 1.1547

*i*rad/secPlot the simulation results to see if they adequately match the original results.

Script for Simulating the Model and Plotting the Results

The results appear similar.

Zoom to evaluate accuracy in more detail.

At this level, you can see a small difference in the results for the modified model. However, the simulation is accurate enough that the results meet expectations based on empirical and theoretical data.

The model includes hydraulic compressibility, that is, oil column resonance. To confirm that the column resonance is responsible for the second oscillatory pole pair, turn off compressibility and repeat the frequency response and pole analyses.

Script for Eliminating Compressibility and Performing the Frequency Response and Pole Analysis

The further decrease in the phase drop reflects the reduction in high-frequency dynamics. There are now two fast poles. Even though one of the fast poles has moved further away from the imaginary axis, there are fewer fast dynamics because the oscillating pole pair at 458.8 ± 1.4273

*i*rad/sec is eliminated.Print the values of the remaining two fast poles to the command window.

Script for Printing Pole Values

two_fast_poles = 1.0e+03 * -2.6767 -1.0000

The fast pole at -2677 rad/s corresponds to the load mass and hydraulic damping introduced by the two orifice components in the hydraulic subsystem. These dynamics are central to the simulation results. The fast pole at -1000 rad/s corresponds to the controller denominator, 0.001 s+1. The transfer function is integral to the controller design. No more dynamic modes can be removed without changing important system-level behavior.

Plot the simulation results to see if they adequately match the original results.

Script for Plotting the Simulation Results

The accuracy of the updated model seems acceptable.

Zoom to evaluate accuracy in more detail.

At this level, you can see that there is only a small additional difference in the results for the modified model. The accuracy of the simulation is acceptable.

## See Also

### Blocks

### Functions

## Related Examples

- Determine Step Size
- Estimate Computation Costs
- Reduce Computation Costs
- Reduce Numerical Stiffness
- Reduce Zero Crossings