Skip to content

Latest commit

 

History

History
64 lines (42 loc) · 1.21 KB

convolve.md

File metadata and controls

64 lines (42 loc) · 1.21 KB

convolve

Convolve a signal with a kernel using discrete convolution.

API

Numeric.math.convolve(signal, kernel, method)

Computes discrete convolution over the signal entries.

  • Parameters:
    • signal: Input signal samples to convolve
    • kernel: Kernel weights applied across the signal
    • method: Output length method for the convolution
  • Returns: Convolved signal values
  • NumPy: Equivalent to np.convolve.

Examples

Convolve a signal with a kernel

import Numeric from '@neabyte/numerix'

const values = Numeric.math.convolve([1, 2, 3], [0, 1, 0.5])

console.log(values)
// [0,1,2.5,4,1.5]

Same mode matches the signal length

import Numeric from '@neabyte/numerix'

const values = Numeric.math.convolve([1, 2, 3], [0, 1, 0.5], 'same')

console.log(values)
// [1,2.5,4]

Valid mode drops the overlapping edges

import Numeric from '@neabyte/numerix'

const values = Numeric.math.convolve([1, 2, 3], [0, 1, 0.5], 'valid')

console.log(values)
// [2.5]

Convolve with a moving average kernel

import Numeric from '@neabyte/numerix'

const values = Numeric.math.convolve([1, 2, 3, 4], [0.25, 0.5, 0.25], 'same')

console.log(values)
// [1,2,3,2.75]