# conv

## Purpose

Convolution and polynomial multiplication.

## Synopsis

    c = conv(a,b)

## Description

`c = conv(a,b)` convolves vectors `a` and `b`. Convolution can be thought of as multiplying the polynomials whose coefficients are the elements of `a` and `b` since, algebraically, this is the same operation.

Let `m = length(a)` and `n = length(b)`. Then `c` is the vector of `length m+n-1` whose `k`-th element is

The sum is over all the values of `j` which lead to legal subscripts for `a(j)` and `b(k+1-j)`, specifically `j = max(1,k+1-n)`: `min(k,m)`. When `m = n`, this gives

    c(1) = a(1)*b(1)
    c(2) = a(1)*b(2)+a(2)*b(1)
    c(3) = a(1)*b(3)+a(2)*b(2)+a(3)*b(1)
    ...
    c(n) = a(1)*b(n)+a(2)*b(n-1)+ ... +a(n)*b(1)
    ...
    c(2*n-1) = a(n)*b(n)

## Algorithm

The convolution theorem says, roughly, that convolving two sequences is the same as multiplying their Fourier transforms. In order to make this precise, it is necessary to pad the two vectors with zeros and ignore roundoff error. Thus, if

    X = fft([x zeros(1,length(y)-1)])

and

    Y = fft([y zeros(1,length(x)-1)])

then

    conv(x,y) = ifft(X.*Y)

## Examples

Let `a = [1 2 3 4]` and`b = [10 20 30],` then `c = conv(a,b)` is

    c =
        10    40    100    160    170    120

The vectors `a` and `b` represent the polynomials

Then the product `c = conv(a,b)` is the polynomial

## See Also

`deconv`, `residue`, `filter`

`convmtx`,`xconv2` in the Signal Processing Toolbox

(c) Copyright 1994 by The MathWorks, Inc.