---
url: /dyad/stable/stdlib/DiscreteComponents/components/Sampler.md
description: Dyad Sampler docs.  Clock-agnostic sampler block.
---

# `Sampler` {#Sampler}

Clock-agnostic sampler block.

Samples the continuous-time input signal `u` onto the clock of the output `y`, so that `y` takes the value of `u` at every tick of that clock. The clock of `y` is inferred from the discrete-time context that `y` is connected to; the block declares no sample interval of its own.

Before the clock of `y` has ticked, `y` equals `initial_condition`.

## Usage {#Usage}

`DiscreteComponents.Sampler(initial_condition=0)`

## Parameters: {#Parameters:}

|                Name |                                         Description | Units | Default value |
| -------------------:| ---------------------------------------------------:| -----:| -------------:|
| `initial_condition` | The value of `y` before the clock of `y` has ticked |     – |             0 |

## 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))

## Behavior {#Behavior}

Behavior of this component cannot be rendered because it includes `path` variables.

## Source {#Source}

```dyad
"""
Clock-agnostic sampler block.

Samples the continuous-time input signal `u` onto the clock of the output `y`, so that
`y` takes the value of `u` at every tick of that clock. The clock of `y` is inferred
from the discrete-time context that `y` is connected to; the block declares no sample
interval of its own.

Before the clock of `y` has ticked, `y` equals `initial_condition`.
"""
component Sampler@[input inclk extends Continuous, input outclk extends Discrete]
  "The continuous-time input signal"
  u = RealInput@[inclk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -40, "y1": 450, "x2": 60, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "The sampled, clocked output signal"
  y = RealOutput@[outclk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 960, "y1": 450, "x2": 1060, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "The value of `y` before the clock of `y` has ticked"
  parameter initial_condition::Real = 0
relations
  y@outclk = sample(u)
  initial sample(u) = initial_condition
metadata {
  "Dyad": {
    "icons": {"default": "dyad://DiscreteComponents/Sampler.svg"},
    "doc": {"behavior": false}
  }
}
end
```

```dyad
"""
Clock-agnostic sampler block.

Samples the continuous-time input signal `u` onto the clock of the output `y`, so that
`y` takes the value of `u` at every tick of that clock. The clock of `y` is inferred
from the discrete-time context that `y` is connected to; the block declares no sample
interval of its own.

Before the clock of `y` has ticked, `y` equals `initial_condition`.
"""
component Sampler
  "The continuous-time input signal"
  u = RealInput@[inclk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -40, "y1": 450, "x2": 60, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "The sampled, clocked output signal"
  y = RealOutput@[outclk]() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 960, "y1": 450, "x2": 1060, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "The value of `y` before the clock of `y` has ticked"
  parameter initial_condition::Real = 0
relations
  y@outclk = sample(u)
  initial sample(u) = initial_condition
metadata {
  "Dyad": {
    "icons": {"default": "dyad://DiscreteComponents/Sampler.svg"},
    "doc": {"behavior": false}
  }
}
end
```

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`IntegratorFEwInitialTest`](Sampler.md)

  * [`ResetValueTrackerTest`](Sampler.md)

  * [`SimpleRelayControl`](Sampler.md)

  * [`TestClockPropagator`](Sampler.md)

  * [`TestDiscreteCascadeServoController`](Sampler.md)

  * [`TestDiscreteCascadeServoControllerDrive`](Sampler.md)

  * [`TestDiscreteCascadeServoControllerFF`](Sampler.md)

  * [`TestDiscreteIntegrator`](Sampler.md)

  * [`TestNDelay`](Sampler.md)

  * [`TestPeriodicClock`](Sampler.md)

  * [`TestUnitDelay`](Sampler.md)

  * [`TestUnitDifference`](Sampler.md)

  * [`TestZeroOrderHold`](Sampler.md)
