# discretize_stf

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/discretize_stf

```python
Graph.discretize_stf(stf, duration, segment_count, sample_count_per_segment=1, *, name=None)
```

Create a piecewise-constant function by discretizing a sampleable function.

Use this function to create a piecewise-constant approximation to a sampleable
function (obtained, for example, by filtering an initial
piecewise-constant function).

### Parameters
* **stf** ([*Stf*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.Stf)) – The sampleable function $v(t)$ to discretize. The values of the
  function can have any shape. You can also provide a batch of
  functions, in which case the discretization is applied to each
  element of the batch.
* **duration** (*float*) – The duration $\tau$ over which discretization should be
  performed. The resulting piecewise-constant function has this
  duration.
* **segment_count** (*int*) – The number of segments $N$ in the resulting piecewise-constant
  function.
* **sample_count_per_segment** (*int* *,* *optional*) – The number of samples $M$ of the sampleable function to take when
  calculating the value of each segment in the discretization. Defaults
  to 1.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
The piecewise-constant function $w(t)$ obtained by discretizing
the sampleable function (or batch of piecewise-constant functions, if
you provided a batch of sampleable functions).
### Return type
[Pwc](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc)

### SEE ALSO
[`Graph.convolve_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/convolve_pwc.md#boulderopal.graph.Graph.convolve_pwc)
: Create an Stf by convolving a Pwc with a kernel.

[`Graph.filter_and_resample_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/filter_and_resample_pwc.md#boulderopal.graph.Graph.filter_and_resample_pwc)
: Filter a Pwc with a sinc filter and resample it.

[`Graph.identity_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/identity_stf.md#boulderopal.graph.Graph.identity_stf)
: Create an Stf representing the identity function.

[`Graph.sample_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/sample_stf.md#boulderopal.graph.Graph.sample_stf)
: Sample an Stf at given times.

## Notes

The resulting function $w(t)$ is piecewise-constant with $N$
segments, meaning it has segment values $\{w_n\}$ such that
$w(t)=w_n$ for $t_{n-1}\leq t\leq t_n$, where $t_n= n \tau/N$.

Each segment value $w_n$ is the average of samples of $v(t)$
at the midpoints of $M$ equally sized subsegments between
$t_{n-1}$ and $t_n$:

$$
w_n = \frac{1}{M}
\sum_{m=1}^M v\left(t_{n-1} + \left(m-\tfrac{1}{2}\right) \frac{\tau}{MN} \right).
$$

For more information on Stf nodes see the [Working with time-dependent functions in
Boulder Opal](https://docs.q-ctrl.com/boulder-opal/topics/working-with-time-dependent-functions-in-boulder-opal) topic.

## Examples

Create discretized Gaussian signal.

```pycon
>>> times = graph.identity_stf()
>>> gaussian_signal = graph.exp(- (times - 5e-6) ** 2 / 2e-6 ** 2) / 2e-6
>>> discretized_gamma_signal = graph.discretize_stf(
...     stf=gaussian_signal, duration=10e-6, segment_count=256, name="gamma"
... )
>>> discretized_gamma_signal
<Pwc: name="gamma", operation_name="discretize_stf", value_shape=(), batch_shape=()>
```

Refer to the [How to create dephasing and amplitude robust single-qubit gates](https://docs.q-ctrl.com/boulder-opal/user-guides/how-to-create-dephasing-and-amplitude-robust-single-qubit-gates) user guide to find the example in context.
