convolution: Discrete-time convolution product of two sequences

View source: R/convolution.R

convolutionR Documentation

Discrete-time convolution product of two sequences

Description

Computes the discrete-time convolution product f * g of two sequences f and g defined on \mathbb{N} (Barbu and Limnios, 2008, Definition 2.2, p. 20):

(f * g)(k) = \sum_{l = 0}^{k} f(k - l)\, g(l), \quad k \in \mathbb{N}.

Usage

convolution(f, g)

Arguments

f

A numeric vector giving the values f(0), \dots, f(k).

g

A numeric vector of the same length as f giving the values g(0), \dots, g(k).

Details

Notation (see smmR-package for the complete description of the models): the sequences are indexed by the time k \in \mathbb{N}, and the element l + 1 of a vector is the value at time l.

The vectors f and g contain the values of the sequences at times 0, 1, \dots, k. Only the values up to the time horizon k (the common length of f and g minus one) are needed to compute (f * g)(0), \dots, (f * g)(k), so that the result is exact (it is not a truncation of a longer convolution).

The convolution product is commutative and associative, and its neutral element is the sequence \delta defined by \delta(0) = 1 and \delta(k) = 0 for k > 0. If f and g are the distributions of two independent random variables with values in \mathbb{N}, f * g is the distribution of their sum. For matrix-valued sequences, see matrixConvolution.

Value

A numeric vector of the same length as f giving the values (f * g)(0), \dots, (f * g)(k).

References

V. S. Barbu, N. Limnios. (2008). Semi-Markov Chains and Hidden Semi-Markov Models Toward Applications - Their Use in Reliability and DNA Analysis. New York: Lecture Notes in Statistics, vol. 191, Springer.

See Also

matrixConvolution

Examples

# delta is the neutral element
convolution(f = c(0.2, 0.5, 0.3), g = c(1, 0, 0))

# Distribution of the sum of two independent random variables
# with values in {0, 1, 2} (the result is given up to k = 2)
convolution(f = c(0.5, 0.5, 0), g = c(0.5, 0.5, 0))

# Distribution of the sum of two sojourn times (geometric on {1, 2, ...}),
# i.e. of the time of the second jump of a renewal chain
k <- 0:20
f <- c(0, dgeom(k[-1] - 1, prob = 0.4))
f2 <- convolution(f, f)
all.equal(f2, c(0, 0, dnbinom(k[-(1:2)] - 2, size = 2, prob = 0.4)))


smmR documentation built on Nov. 28, 2026, 1:06 a.m.