# convolve_pwc

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

```python
Graph.convolve_pwc(pwc, kernel)
```

Create the convolution of a piecewise-constant function with a kernel.

### Parameters
* **pwc** ([*Pwc*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc)) – The piecewise-constant function $\alpha(t)$ to convolve. You
  can provide a batch of functions, in which case the convolution is
  applied to each element of the batch.
* **kernel** ([*ConvolutionKernel*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/ConvolutionKernel.md#boulderopal.graph.ConvolutionKernel)) – The node representing the kernel $K(t)$.
### Returns
The sampleable function representing the signal $(\alpha * K)(t)$
(or batch of signals, if you provide a batch of functions).
### Return type
[Stf](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.Stf)

### SEE ALSO
[`Graph.discretize_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/discretize_stf.md#boulderopal.graph.Graph.discretize_stf)
: Discretize an Stf into a Pwc.

[`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.gaussian_convolution_kernel`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/gaussian_convolution_kernel.md#boulderopal.graph.Graph.gaussian_convolution_kernel)
: Create a convolution kernel representing a normalized Gaussian.

[`Graph.pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/pwc.md#boulderopal.graph.Graph.pwc)
: Create piecewise-constant functions.

[`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.

[`Graph.sinc_convolution_kernel`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/sinc_convolution_kernel.md#boulderopal.graph.Graph.sinc_convolution_kernel)
: Create a convolution kernel representing the sinc function.

## Notes

The convolution is

$$
(\alpha * K)(t) \equiv
\int_{-\infty}^\infty \alpha(\tau) K(t-\tau) d\tau.
$$

Convolution in the time domain is equivalent to multiplication in the
frequency domain, so this function can be viewed as applying a linear
time-invariant filter (specified via its time domain kernel $K(t)$)
to $\alpha(t)$.

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

Filter a piecewise-constant signal using a Gaussian convolution kernel.

```pycon
>>> gaussian_kernel = graph.gaussian_convolution_kernel(std=1.0, offset=3.0)
>>> gaussian_kernel
<ConvolutionKernel: operation_name="gaussian_convolution_kernel">
>>> pwc_signal
<Pwc: name="alpha", operation_name="pwc_signal", value_shape=(), batch_shape=()>
>>> filtered_signal = graph.convolve_pwc(pwc=pwc_signal, kernel=gaussian_kernel)
>>> filtered_signal
<Stf: operation_name="convolve_pwc", value_shape=(), batch_shape=()>
```

Refer to the [How to add smoothing and band-limits to optimized controls](https://docs.q-ctrl.com/boulder-opal/user-guides/how-to-add-smoothing-and-band-limits-to-optimized-controls)
user guide to find the example in context.
