Engee documentation

cconv

Circular convolution modulo n.

Library

EngeeDSP

Syntax

Function call

  • c = cconv(a,b) — performs cyclic convolution of vectors a and b.

  • c = cconv(a,b,n) — performs cyclic convolution of vectors a and b. The argument n — the length of the resulting vector. Function cconv It can also be used to calculate the circular cross-correlation of two sequences.

Arguments

Input arguments

# a, b — input arrays

+ vectors

Details

Input arrays specified as vectors.

Типы данных

Float32, Float64

Support for complex numbers

Yes

# n is the length of the convolution

+ positive integer

Details

The length of the convolution, given as a positive integer. If the argument n if not specified, then the convolution will have length length(a) + length(b) − 1.

Output arguments

# c — circular convolution

+ vector

Details

Circular convolution of input vectors, returned as a vector.

Examples

Circular convolution and linear convolution

Details

We will generate two signals of different lengths. Let’s compare their circular and linear convolutions. Use the value of the argument n by default.

import EngeeDSP.Functions: cconv, conv, norm

a = [1 2 -1 1]
b = [1 1 2 1 2 2 1 1]

c = cconv(a, b)            # Circular convolution
cref = conv(a, b)          # Linear convolution

dif = norm(c - cref)
3.770748636149785e-15

The resulting norm is almost zero, which shows that both convolutions give the same result with machine accuracy.

Circular convolution

Details

Generate two vectors and calculate their circular convolution modulo 4.

import EngeeDSP.Functions: cconv

a = [2 1 2 1]
b = [1 2 3 4]
c = cconv(a, b, 4)
1×4 Matrix{Float64}:
 14.0  16.0  14.0  16.0

Tips

For long sequences, circular convolution can be faster than linear convolution.

Literature

  1. Orfanidis, Sophocles J. Introduction to Signal Processing. Englewood Cliffs, NJ: Prentice-Hall, 1996, pp. 524–529.