This page will look better in a graphical browser that supports web standards, but is accessible to any browser or internet device.

Served by Samwise.

# Using Delay Lines in MML

This page is for the current JSim version 2.0 and higher. Click here for the earlier JSim 1.6 version.

## Introduction

This document describes construction of delay lines in JSim MML. A delay line is a mechanism for delaying the delivery of a signal. Mathematically, this may be thought of as querying the value of a variable v(t) at an earlier time v(t-delay). While MML does not have an explicit "delay()" function currently (one is being planned), delay lines may be created in MML using several alternative methods which are described below.

Prerequisites:

Contents:

## Variable Function (VF) Delay Lines

This form of delay line uses MML VF syntax, which treats a dynamic variable v as a function v(expression). For a simple delay line, the appropriate VF call is v(t-delay) which is described below (those interested if the full generality of VFs, should see Using Variable Functions in MML). Consider the following example:

```// simple variable function delay line
math vf1 {
realDomain t;
t.min=0; t.max=10; t.delta=0.25;
real delay = 1;   // user-specified time delay
real u(t);        // the normal state variable
real udelayed(t); // the delayed state variable
when (t=t.min) u=1;
u:t = -udelayed;
udelayed = if (t<delay) 0 else u(t-delay);
}
```

Note that the definition of udelayed uses an "if" clause to prevent u() queries for t less than 0. Such queries would cause a out-of-range error when the model is run.

While the above delay implementation is adequate in most circumstances, there are some subtleties that can sometimes cause problems:

1. JSim calculates u(t-delay) by linearly interpolating u(t) values calculated from previous time points, that is, u's values on the defined time grid. This means the accuraccy of u(t-delay) depends upon the pseudo-linear behaviour of u. Normally, specifying an appropriately small time step (t.delta) will address this problem.
2. The above interpolation behaviour means that if delay is less than t.delta, then u(t-delay) will return a NaN because the interpolated values will include u values not yet calculated. This means you must specify a delay value greater that t.delta to get acceptable results. In any case, delay must normally be large compared to t.delta in order to achieve acceptable interpolation accuraccy.
3. Third, the "if" clause above is, strictly speaking, correct only for t.min=0. If t.min is not necessarily zero in your model, the correct "if" clause should be "if (t-t.min < delay) ..."

The following model incorporates two refinements of the previous one's "if" clause. First, udelayed is set equal to u if the delay is too small, allowing the case of the delay=0 to be handled correctly. Second, the case of non-zero t.min is handled correctly.

```// refined variable function delay line
math vf2 {
realDomain t;
t.min=0; t.max=10; t.delta=0.25;
real delay = 1;   // user-specified time delay
real u(t);        // the normal state variable
real udelayed(t); // the delayed state variable
when (t=t.min) u=1;
u:t = -udelayed;
udelayed = if (delay < t.delta) u else
( if (t-t.min < delay) 0 else u(t-delay));
}
```
(Java required)

## PDE Delay Lines

To understand this section, you should first read Using PDEs in MML.

This section is currently under development.

## ODE Series Delay Lines

To understand this section, you should first read Using ODEs in MML.

This section is currently under development.

06Jul12, 3:11 pm.]

Model development and archiving support at physiome.org provided by the following grants: NIH U01HL122199 Analyzing the Cardiac Power Grid, 09/15/2015 - 05/31/2020, NIH/NIBIB BE08407 Software Integration, JSim and SBW 6/1/09-5/31/13; NIH/NHLBI T15 HL88516-01 Modeling for Heart, Lung and Blood: From Cell to Organ, 4/1/07-3/31/11; NSF BES-0506477 Adaptive Multi-Scale Model Simulation, 8/15/05-7/31/08; NIH/NHLBI R01 HL073598 Core 3: 3D Imaging and Computer Modeling of the Respiratory Tract, 9/1/04-8/31/09; as well as prior support from NIH/NCRR P41 RR01243 Simulation Resource in Circulatory Mass Transport and Exchange, 12/1/1980-11/30/01 and NIH/NIBIB R01 EB001973 JSim: A Simulation Analysis Platform, 3/1/02-2/28/07.