convolve#

sionna.phy.signal.convolve(inp: torch.Tensor, ker: torch.Tensor, padding: Literal['full', 'same', 'valid'] = 'full', axis: int = -1, precision: Literal['single', 'double'] | None = None) torch.Tensor[source]#

Filters an input inp of length N by convolving it with a kernel ker of length K.

The length of the kernel ker must not be greater than the one of the input sequence inp.

The dtype of the output is torch.float only if both inp and ker are torch.float. It is torch.complex otherwise. inp and ker must have the same precision.

Three padding modes are available:

  • “full” (default): Returns the convolution at each point of overlap between ker and inp. The length of the output is N + K - 1. Zero-padding of the input inp is performed to compute the convolution at the border points.

  • “same”: Returns an output of the same length as the input inp. The convolution is computed such that the coefficients of the input inp are centered on the coefficient of the kernel ker with index (K-1)/2 for kernels of odd length, and K/2 - 1 for kernels of even length. Zero-padding of the input signal is performed to compute the convolution at the border points.

  • “valid”: Returns the convolution only at points where inp and ker completely overlap. The length of the output is N - K + 1.

Parameters:
  • inp (torch.Tensor) – Input to filter with shape […, N] (torch.complex or torch.float)

  • ker (torch.Tensor) – Kernel of the convolution with shape [K] (torch.complex or torch.float)

  • padding (Literal['full', 'same', 'valid']) – Padding mode. One of “full” (default), “valid”, or “same”.

  • axis (int) – Axis along which to perform the convolution

  • precision (Literal['single', 'double'] | None) – Precision used for internal calculations and outputs. If set to None, precision is used.

Outputs:

out – […, M], torch.complex or torch.float. Convolution output. The length M of the output depends on the padding.

Examples

import torch
from sionna.phy.signal import convolve

inp = torch.randn(64, 100)
ker = torch.randn(10)
out = convolve(inp, ker, padding="same")
print(out.shape)
# torch.Size([64, 100])