Main Content

Model Engine Timing Using Triggered Subsystems

This example shows how to model a four-cylinder spark ignition internal combustion engine from the throttle to the crankshaft output using triggered subsystems. In this example, the sldemo_engine model is based on [1].

The sldemo_engine model uses the Triggered Subsystem blocks in the Valve Timing and Combustion subsystems. In this example, the tasks of all four cylinders are implemented with one set of blocks instead of four sets of blocks, one set per cylinder.

Open the model.


Top level of the engine model.

In an inline four-cylinder four-stroke engine, 180 degrees of crankshaft rotation separates the ignition of each successive cylinder. This separation means that each cylinder fires on every other crank revolution. In this model, the intake, compression, combustion, and exhaust strokes occur simultaneously (at any given time, one cylinder is in each phase). To account for compression, the combustion of each intake charge is delayed by 180 degrees of crank rotation from the end of the intake stroke.

In this model, an Integrator block accumulates the cylinder mass air flow in the Intake Manifold block located inside the Throttle and Manifold subsystem. The Valve Timing subsystem generates pulses that correspond to specific rotational positions to manage the crank angle, air-fuel mass and triggers execution of Compression subsystem. The Compression subsystem uses a Unit Delay block to insert 180 degree (one event period) of delay between the intake and combustion of each air-fuel charge.

Consider a complete four-stroke cycle for one cylinder. The following describes the functionality of each stroke.

  • Intake stroke - During this stroke, the intake manifold opens and takes in the air-fuel mixture. The piston moves from the top dead center (TDC) to the bottom dead center (BDC) and the crank shaft completes 180 degrees rotation. In this model, the Intake Manifold subsystem inside the Throttle and Manifold subsystem integrates the mass flow rate from the manifold.

  • Compression stroke - During this stroke, the intake manifold closes and the air-fuel charge is compressed by 180 degrees rotation of the crank shaft. The piston moves from BDC to TDC. Due to compression, the temperature of the air-fuel mixture increases which assists the combustion process.

  • Combustion stroke - The spark plug ignites the air-fuel mixture. Combustion of the mixture inside the cylinder generates pressure that forces the piston to move from TDC to BDC. During this stroke, the crank shaft rotates by 180 degrees and generates torque.

  • Exhaust stroke - During the exhaust stroke, the piston moves from BDC to TDC by 180 degrees rotation of the crank shaft. When the piston head reaches TDC, the exhaust manifold opens and let the exhaust out of the cylinder. In this model, the Integrator block inside the Throttle and Manifold subsystem is reset and prepared for the next cycle of four strokes (720 degrees) of this cylinder.

Valve Timing

The Valve Timing subsystem controls valve timing (opening and closing), triggers ignition, and resets the crank shaft angle based on the angular position of the engine crank shaft. The Valve Timing subsystem contains two Triggered subsystem blocks: Reset Crank Angle on Rising Edge and Reset Piston Air Mass on Falling Edge.

Reset Piston Air Mass on Falling Edge is triggered when the crankshaft moves from TDC to BDC, and transfers the air-fuel mixture from the intake manifold to the cylinders via discrete valve events. The transfer process takes place concurrently with the continuous-time processes of intake flow, torque generation, and acceleration.

Reset Crank Angle on Rising Edge is triggered once the crankshaft angle exceeds 180 degrees, and resets the angle to 0 degrees.

Valve Timing subsystem controls valve timing and resets crank angle


The Compression subsystem represents the engine dynamics during the compression stroke. This subsystem is triggered when it receives a positive trigger value at the Trigger port of the block. The Unit Delay block samples the integrator state. This value, the accumulated mass charge, is available at the output of the Compression subsystem for use during combustion.

Subsystem block that is triggered based on a positive ignition trigger

Throttle and Manifold

The throttle body of the engine is modeled by the Throttle and Manifold subsystem.

Throttle and Manifold subystem models the throttle body of the engine


The Throttle subsystem uses throttle plate angle (θ), manifold pressure (Pm), and atmospheric pressure (Pamb) as inputs. The air-fuel mixture intake rate(m˙ai) at the intake manifold can be expressed as the product of two functions:

  • Empirical function of the throttle plate angle

  • Function of the atmospheric and manifold pressures

In cases of lower manifold pressure (greater vacuum), the flow rate through the throttle body is sonic and is only a function of the throttle angle. This model accounts for this low pressure behavior with a switching condition in the following compressibility equations.

Equation 1

m˙ai=f(θ)g(Pm)=mass flow rate into manifold (g/s)


g(Pm)=1; if PmPamb/2

g(Pm)=2PambPmPamb-Pm2; if Pamb/2PmPamb

g(Pm)=-2PmPmPamb-Pamb2; if PambPm2Pamb

g(Pm)=-1; if Pm2Pamb

m˙aimass flow rate into manifold (g/s); 

θthrottle angle (deg);

Pmmanifold pressure (bar); 

Pambambient (atmospheric) pressure (bar);

The individual equations, mentioned above, are incorporated using Fcn blocks. A Switch block determines whether the flow is sonic by comparing the pressure ratio to its switch threshold. In the sonic regime, the flow rate is a function of the throttle position only. The direction of flow is from the higher to lower pressure, as determined by the Sign block. The MinMax block ensures that the pressure ratio is always unity or less.

Throttle Subsystem

Intake Manifold

The Throttle and Manifold subsystem contains the Intake Manifold subsystem. This subsystem uses the throttle flow input and engine speed (N) as inputs. The intake manifold is modeled as a differential equation for the manifold pressure (P˙m). The difference in the incoming and outgoing mass flow rates represents the net rate of change of air mass with respect to time. This quantity, according to the ideal gas law, is proportional to the time derivative of the manifold pressure.

However, unlike the model in [1], this model does not incorporate exhaust gas recirculation (EGR).

Equation 2


Rspecific gas constant; 

Ttemperature (K); 

Vmmanifold volume (m3); 

m˙aomass flow rate of air out of the manifold (g/s); 

P˙mrate of change of manifold pressure (bar/s);

The mass flow rate of air-fuel mixture that the model pumps into the cylinders from the manifold is described in the following empirical equation. This mass rate (m˙ao) is a function of the manifold pressure (P˙m) and the engine speed (N).

Equation 3


Nengine angular speed (rad/s); 

Pmmanifold pressure (bar); 

To determine the total air-fuel mixture charge pumped into the cylinders, the simulation integrates the mass flow rate from the intake manifold and samples it at the end of each intake stroke event. This sampling determines the total air mass that is present in each cylinder after the intake stroke and before compression.

The Intake Manifold subsystem is used to model the throttle dynamics expressed in Equation 2. The differential equation from Equation 2 models the intake manifold pressure. A Simulink Function block computes the mass flow rate into the cylinder, a function of manifold pressure and engine speed, expressed in Equation 3.

Intake Manifold Subsystem


Torque is generated during the combustion stroke. The Combustion subsystem models the combustion process and torque generation using four variables, expressed in Equation 4. The model uses a Mux block to combine these variables into a vector that provides input to the Fcn block that incorporates the Torqueeng equation.

Equation 4

N˙engine angular acceleration (rad/s2); 

mamass of air in cylinder for combustion (g); 

(AF)air to fuel ratio; 

σspark advance (degrees before top - dead - center); 

Torqueengtorque produced by the engine (Nm); 



Combustion subsystem that models the combustion and torue generation process

Engine Dynamics

The Engine Dynamics subsystem computes the engine speed (N) and crank angle using the load torque Tload and the generated torque Teng. Tload is computed using step functions in the Drag Torque subsystem. Engine speed is computed using the equation JN˙=Torqueeng-Torqueload, where J is the engine rotational moment of inertia (kgm2).

Engine Dynamics subsystem computes crank angle and engine speed

Simulate the Model and Visualize the Results

Simulate the model and visualize the results using plot function.


The default input values are used for simulation:

Throttle=8.97 (deg) if t<5

Throttle=11.93 (deg) if t5

Load=25 (Nm) if t2 or t8

Load=20 (Nm) if 2<t8

Simulink® returns the simulated engine speed, the throttle commands that drive the simulation, and the load torque that disturbs it.

The model logs this data to the base workspace in a structure, sldemo_engine_output.

PlotHandle = plot(sldemo_engine_output.get('LoadTorque').Values.Time, ...
               sldemo_engine_output.get('LoadTorque').Values.Data, 'g', ...
               sldemo_engine_output.get('ThrottleAngle').Values.Time, ...
               sldemo_engine_output.get('ThrottleAngle').Values.Data, 'b'  );
title('Open-Loop Simulation Inputs: Load Torque and Throttle Angle vs Time');
xlabel('Time (sec)'); ylabel('Engine Speed (rad/sec)');
set(gca,'Color','w','XGrid','On','XColor',[0 0 0],...
                    'YGrid','On','YColor',[0 0 0]);
axis([0 10 5 30]);
h= legend('Load Torque (Nm)','Throttle Angle (deg)','Location','northeast');

PlotHandle = plot(sldemo_engine_output.get('EngineSpeed').Values.Time, ...
                  sldemo_engine_output.get('EngineSpeed').Values.Data,'g'  );
title('Open-Loop Simulation Results: Engine Speed Control');
xlabel('Time (sec)'); ylabel('Engine Speed (rad/sec)');
set(gca,'Color','w','XGrid','On','XColor',[0 0 0],...
                    'YGrid','On','YColor',[0 0 0]);
axis([0 10 1500 3500]);
h = legend('Engine Speed (rpm)','Location','northeast');

See Also

| | | | | |

Related Topics


[1] Crossley, P. R., and J. A. Cook. “A Nonlinear Engine Model for Drivetrain System Development.” International Conference on Control 1991. Control ’91 1991, pp. 921–25 vol.2. IEEE Xplore, (Crossref),

[2] The Simulink Model. Developed by Ken Butts, Ford Motor Company. Modified by Paul Barnard, Ted Liefeld and Stan Quinn, MathWorks®, 1994 — 7."

[3] Moskwa, John J., and J. Karl Hedrick. “Automotive Engine Modeling for Real Time Control Application.” 1987 American Control Conference, 1987, pp. 341–46. IEEE Xplore, DOIː 10.23919/ACC.1987.4789343.

[4] Powell, B. K., and J. A. Cook. “Nonlinear Low Frequency Phenomenological Engine Modeling and Analysis.” 1987 American control conference, 1987, pp. 332–40. IEEE Xplore, DOIː 10.23919/ACC.1987.4789342.

[5] Weeks, Robert W., and John J. Moskwa. “Automotive Engine Modeling for Real-Time Control Using MATLAB/SIMULINK.” SAE transactions, vol. 104, 1995, pp. 295–309. JSTOR,