Classifying system models and simulation with MATLAB The dia
Classifying system models and simulation with MATLAB
The diagram shows an inverted pendulum on a cart that is driven by a force F. Here we consider the case where F = 0. Assume that the mass of the pendulum is concentrated at the ball (the rod is massless). Let x denote the position of the cart in an inertial reference frame. The linearized equations of motion are the following: x^- = mg/M theta, theta^- = M+m/Ml g theta Use the definitions from Lecture 1 to answer the following questions and justify your answers. Are the ODE\'s: Use the definitions from Lecture 1 to answer the following questions and justify your answers. Are the ODEs: Linear or nonlinear? Time-varying or time-invariant? Discrete-time or continuous-time? Homogeneous or nonhomogeneous? Define the state variables of the system and the state vector x. Convert the two 2nd-order ODEs above into four 1st-order ODEs that are functions of the state variables. Write an output equation y = Cx+Du in which there are 3 outputs, theta, x and x^.. Suppose that the system starts at rest with the cart position at x = 0m and the pendulum angle at theta = pi/12. Use the MATLAB function ode45 to numerically solve the four 1st-order ODEs from time 0 sec to 1 sec with parameters m = 0.1 kg, M = 1kg, l = 1m, and g = 9.81m/s^2. Plot x over time in one figure, and plot theta over time in another figure. Hand in your code \ th your homework.Solution
This example shows some of the main steps needed to design and evaluate a sine wave data table for use in digital waveform synthesis applications in embedded systems and arbitrary waveform generation instruments.
Real-Time direct digital synthesis of analog waveforms using embedded processors and digital signal processors (DSPs) connected to digital-to-analog converters (DACs) is becoming pervasive even in the smallest systems. Developing waveforms for use in embedded systems or laboratory instruments can be streamlined using the tight integration of MATLAB® and Simulink®. You can develop and analyze the waveform generation algorithm and its associated data at your desktop before implementing it with Simulink® Coder™ on target hardware.
When feasible, the most accurate way to digitally synthesize a sine wave is to compute the full precision sin() function directly for each time step, folding omega*t into the interval 0 to 2*pi. In real-time systems, the computational burden is typically too large to permit this approach. One popular way around this obstacle is to use a table of values to approximate the behavior of the sin() function, either from 0 to 2*pi, or even half wave or quarter wave data to leverage symmetry.
Tradeoffs to consider include algorithm efficiency, data ROM size required, and accuracy/spectral purity of the implementation. Similar analysis is needed when performing your own waveform designs. The table data and look-up algorithm alone do not determine performance in the field. Additional considerations such as the accuracy and stability of the real-time clock, and digital to analog converter are also needed in order to assess overall performance. The Signal Processing Toolbox™ and the DSP System Toolbox™ complement the capabilities of MATLAB and Simulink for work in this area.
Another popular way to approximate the behavior of sine wave is to use the CORDIC approximation method. CORDIC is an acronym for COordinate Rotation DIgital Computer. The Givens rotation-based CORDIC algorithm is among one of the most hardware-efficient algorithms because it requires only shift-add iterative operations. If you have Fixed- Point Designer license then you can see fi_sin_cos_demo for a style example on CORDIC approximation.
The distortion analysis in this example is based on principles presented in \"Digital Sine-Wave Synthesis Using the DSP56001/DSP56002\", by Andreas Chrysafis, Motorola® Inc. 1988
Create a Table in Double Precision Floating Point
The following commands make a 256 point sine wave and measure its total harmonic distortion when sampled first on the points and then by jumping with a delta of 2.5 points per step using linear interpolation. Similar computations are done by replacing the sine values with CORDIC sine approximation. For frequency-based applications, spectral purity can be more important than absolute error in the table.
The file ssinthd.m is the core function in this example. It is used for calculating total harmonic distortion (THD) for digital sine wave generation with or without interpolation. This THD algorithm proceeds over an integral number of waves to achieve accurate results. The number of wave cycles used is A. Since the step size \'delta\' is A/B and traversing A waves will hit all points in the table at least one time, which is needed to accurately find the average THD across a full cycle.
The relationship used to calculate THD is:
where ET = total energy, and EF = fundamental energy
The energy difference between ET and EF is spurious energy.
Put the Sine Wave Approximations in a Model
You can put the sine wave designed above into a Simulink model and see how it works as a direct lookup, with linear interpolation, and with CORDIC approximation. This model compares the output of the floating point tables to the sin() function. As expected from the THD calculations, the linear interpolation has a lower error than the direct table lookup in comparison to the sin() function. The CORDIC approximation shows a lower error margin when compared to the linear interpolation method. This margin depends on the number of iterations when computing the CORDIC sin approximation. You can typically achieve greater accuracy by increasing the number of iterations (corresponding to a longer computation time). The CORDIC approximation eliminates the need for explicit multipliers. It is used when multipliers are less efficient or non-existent in hardware.
Open the sldemo_tonegen model

