heat.signal

Provides a collection of signal-processing operations

Module Contents

convolve(a: heat.core.dndarray.DNDarray, v: heat.core.dndarray.DNDarray, mode: str = 'full') heat.core.dndarray.DNDarray

Returns the discrete, linear convolution of two one-dimensional `DNDarray`s or scalars.

Parameters:
  • a (DNDarray or scalar) – One-dimensional signal DNDarray of shape (N,) or scalar.

  • v (DNDarray or scalar) – One-dimensional filter weight DNDarray of shape (M,) or scalar.

  • mode (str) –

    Can be ‘full’, ‘valid’, or ‘same’. Default is ‘full’. ‘full’:

    Returns the convolution at each point of overlap, with an output shape of (N+M-1,). At the end-points of the convolution, the signals do not overlap completely, and boundary effects may be seen.

    ’same’:

    Mode ‘same’ returns output of length ‘N’. Boundary effects are still visible. This mode is not supported for even-sized filter weights

    ’valid’:

    Mode ‘valid’ returns output of length ‘N-M+1’. The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.

Examples

Note how the convolution operator flips the second array before “sliding” the two across one another:

>>> a = ht.ones(10)
>>> v = ht.arange(3).astype(ht.float)
>>> ht.convolve(a, v, mode='full')
DNDarray([0., 1., 3., 3., 3., 3., 2.])
>>> ht.convolve(a, v, mode='same')
DNDarray([1., 3., 3., 3., 3.])
>>> ht.convolve(a, v, mode='valid')
DNDarray([3., 3., 3.])
>>> a = ht.ones(10, split = 0)
>>> v = ht.arange(3, split = 0).astype(ht.float)
>>> ht.convolve(a, v, mode='valid')
DNDarray([3., 3., 3., 3., 3., 3., 3., 3.])

[0/3] DNDarray([3., 3., 3.]) [1/3] DNDarray([3., 3., 3.]) [2/3] DNDarray([3., 3.]) >>> a = ht.ones(10, split = 0) >>> v = ht.arange(3, split = 0) >>> ht.convolve(a, v) DNDarray([0., 1., 3., 3., 3., 3., 3., 3., 3., 3., 3., 2.], dtype=ht.float32, device=cpu:0, split=0)

[0/3] DNDarray([0., 1., 3., 3.]) [1/3] DNDarray([3., 3., 3., 3.]) [2/3] DNDarray([3., 3., 3., 2.])