based on an earlier version of the Wolfram Language.

# Convolutions and Correlations

Convolution and correlation are central to many kinds of operations on lists of data. They are used in such areas as signal and image processing, statistical data analysis, and approximations to partial differential equations, as well as operations on digit sequences and power series.

In both convolution and correlation the basic idea is to combine a kernel list with successive sublists of a list of data. The *convolution* of a kernel with a list has the general form , while the *correlation* has the general form .

ListConvolve[kernel,list] | form the convolution of kernel with list |

ListCorrelate[kernel,list] | form the correlation of kernel with list |

Convolution and correlation of lists.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

In forming sublists to combine with a kernel, there is always an issue of what to do at the ends of the list of data. By default, ListConvolve and ListCorrelate never form sublists which would "overhang" the ends of the list of data. This means that the output you get is normally shorter than the original list of data.

In[5]:= |

Out[5]= |

In practice one often wants to get output that is as long as the original list of data. To do this requires including sublists that overhang one or both ends of the list of data. The additional elements needed to form these sublists must be filled in with some kind of "padding". By default, *Mathematica* takes copies of the original list to provide the padding, thus effectively treating the list as being cyclic.

ListCorrelate[kernel,list] | do not allow overhangs on either side (result shorter than list) |

ListCorrelate[kernel,list,1] | allow an overhang on the right (result same length as list) |

ListCorrelate[kernel,list,-1] | allow an overhang on the left (result same length as list) |

ListCorrelate[kernel,list,{-1,1}] | allow overhangs on both sides (result longer than list) |

ListCorrelate[kernel,list,{k_{L},k_{R}}] | allow particular overhangs on left and right |

Controlling how the ends of the list of data are treated.

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

In the general case ListCorrelate[kernel, list, {k_{L}, k_{R}}] is set up so that in the first element of the result, the first element of list appears multiplied by the element at position in kernel, and in the last element of the result, the last element of list appears multiplied by the element at position in kernel. The default case in which no overhang is allowed on either side thus corresponds to ListCorrelate[kernel, list, {1, -1}].

In[9]:= |

Out[9]= |

For many kinds of data, it is convenient to assume not that the data is cyclic, but rather that it is padded at either end by some fixed element, often 0, or by some sequence of elements.

ListCorrelate[kernel,list,klist,p] | pad with element p |

ListCorrelate[kernel,list,klist,{p_{1},p_{2},...}] | |

pad with cyclic repetitions of the | |

ListCorrelate[kernel,list,klist,list] | pad with cyclic repetitions of the original data |

Controlling the padding for a list of data.

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

Different choices of kernel allow ListConvolve and ListCorrelate to be used for different kinds of computations.

In[13]:= |

Out[13]= |

In[14]:= |

In[15]:= |

In[16]:= |

Out[16]= |

In[17]:= |

In[18]:= |

Out[18]= |

You can use ListConvolve and ListCorrelate to handle symbolic as well as numerical data.

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

ListConvolve and ListCorrelate work on data in any number of dimensions.

In[21]:= |

In[22]:= |

Out[22]= |

In[23]:= |

In[24]:= |

Out[24]= |