---
url: /dyad/dev/stdlib/BlockComponents/components/Math.ContinuousMean.md
description: >-
  Dyad Math.ContinuousMean docs.  Calculates the empirical expectation (mean)
  value of its input signal.
---

# `Math.ContinuousMean` {#Math.ContinuousMean}

Calculates the empirical expectation (mean) value of its input signal.

This block continuously calculates the mean value of its input signal using:

```
     integral(u over time)
y = --------------------------
       time - actualStartTime
```

where `actualStartTime = max(t_0, startTime)` and `t_0` is the simulation start time. This can be used to determine the empirical expectation value of an arbitrary signal.

The parameter `t_eps` is used to avoid large fluctuations; the mean value computation starts at `actualStartTime` but the averaged output is only returned after an additional `t_eps`. Before that time instant, `y = u`.

By default `startTime = -Inf`, so the mean is computed from the simulation start time `t_0`. Set `startTime` to begin the averaging after the simulation start.

This component extends from [`BlockComponents.Interfaces.SISO`](../types/Interfaces.SISO.md)

## Usage {#Usage}

`BlockComponents.Math.ContinuousMean(t_eps=1e-7, startTime=-Inf)`

## Parameters: {#Parameters:}

|        Name |                                              Description | Units | Default value |
| -----------:| --------------------------------------------------------:| -----:| -------------:|
|     `t_eps` | Mean value calculation starts at actualStartTime + t_eps |     – |          1e-7 |
| `startTime` |  Starting point for mean if after simulation start-point |     – |          -Inf |

## Connectors {#Connectors}

* `u` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

* `y` - This connector represents a real signal as an output from a component ([`RealOutput`](/stdlib/Dyad/connectors/RealOutput#RealOutput))

## Variables {#Variables}

|              Name |                               Description | Units |
| -----------------:| -----------------------------------------:| -----:|
|              `mu` |              Internal integrator variable |     – |
|             `t_0` |            Captured simulation start time |     – |
| `actualStartTime` | Effective start time: max(t_0, startTime) |     – |

## Behavior {#Behavior}

$$ \begin{align}
\frac{\mathrm{d}\mathtt{t_0}\left( t \right)}{\mathrm{d}t} &= 0 \\
\mathtt{actualStartTime}\left( t \right) &= max\left( \mathtt{t_0}\left( t \right), \mathtt{startTime} \right) \\
\frac{\mathrm{d}\mathtt{mu}\left( t \right)}{\mathrm{d}t} &= ifelse\left( t \geq \mathtt{actualStartTime}\left( t \right), u\left( t \right), 0 \right) \\
y\left( t \right) &= ifelse\left( \mathtt{actualStartTime}\left( t \right) + \mathtt{t_eps} < t, \frac{\mathtt{mu}\left( t \right)}{ - \mathtt{actualStartTime}\left( t \right) + t}, u\left( t \right) \right)
\end{align}
$$

## Source {#Source}

````dyad
"""
Calculates the empirical expectation (mean) value of its input signal.

This block continuously calculates the mean value of its input signal using:

```
     integral(u over time)
y = --------------------------
       time - actualStartTime
```

where `actualStartTime = max(t_0, startTime)` and `t_0` is the simulation start
time. This can be used to determine the empirical expectation value of an arbitrary
signal.

The parameter `t_eps` is used to avoid large fluctuations; the mean value computation
starts at `actualStartTime` but the averaged output is only returned after an additional
`t_eps`. Before that time instant, `y = u`.

By default `startTime = -Inf`, so the mean is computed from the simulation start time
`t_0`. Set `startTime` to begin the averaging after the simulation start.
"""
component ContinuousMean
  extends BlockComponents.Interfaces.SISO
  "Mean value calculation starts at actualStartTime + t_eps"
  parameter t_eps::Real(min = 0) = 1e-7
  "Starting point for mean if after simulation start-point"
  parameter startTime::Real = -Inf
  "Internal integrator variable"
  variable mu::Real
  "Captured simulation start time"
  variable t_0::Real
  "Effective start time: max(t_0, startTime)"
  variable actualStartTime::Real
relations
  initial mu = 0.0
  initial t_0 = time
  der(t_0) = 0
  actualStartTime = max(t_0, startTime)
  der(mu) = ifelse(time >= actualStartTime, u, 0.0)
  y = ifelse(time > actualStartTime + t_eps, mu / (time - actualStartTime), u)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/ContinuousMean.svg"}
  }
}
end
````

````dyad
"""
Calculates the empirical expectation (mean) value of its input signal.

This block continuously calculates the mean value of its input signal using:

```
     integral(u over time)
y = --------------------------
       time - actualStartTime
```

where `actualStartTime = max(t_0, startTime)` and `t_0` is the simulation start
time. This can be used to determine the empirical expectation value of an arbitrary
signal.

The parameter `t_eps` is used to avoid large fluctuations; the mean value computation
starts at `actualStartTime` but the averaged output is only returned after an additional
`t_eps`. Before that time instant, `y = u`.

By default `startTime = -Inf`, so the mean is computed from the simulation start time
`t_0`. Set `startTime` to begin the averaging after the simulation start.
"""
component ContinuousMean
  "Input signal port"
  u = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "input", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0},
        "diagram": {"iconName": "input", "x1": -100, "y1": 450, "x2": 0, "y2": 550, "rot": 0}
      }
    }
  }
  "Output signal port"
  y = RealOutput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "output", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0},
        "diagram": {"iconName": "output", "x1": 1000, "y1": 450, "x2": 1100, "y2": 550, "rot": 0}
      }
    }
  }
  "Mean value calculation starts at actualStartTime + t_eps"
  parameter t_eps::Real(min = 0) = 1e-7
  "Starting point for mean if after simulation start-point"
  parameter startTime::Real = -Inf
  "Internal integrator variable"
  variable mu::Real
  "Captured simulation start time"
  variable t_0::Real
  "Effective start time: max(t_0, startTime)"
  variable actualStartTime::Real
relations
  initial mu = 0.0
  initial t_0 = time
  der(t_0) = 0
  actualStartTime = max(t_0, startTime)
  der(mu) = ifelse(time >= actualStartTime, u, 0.0)
  y = ifelse(time > actualStartTime + t_eps, mu / (time - actualStartTime), u)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/ContinuousMean.svg"}
  }
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Math.ContinuousMean.md)

  * [`ContinuousMean`](Math.ContinuousMean.md)

  * [`ContinuousMean`](Math.ContinuousMean.md)

  * [`Sine`](Math.ContinuousMean.md)
