 Convolution - Maple Help

SignalProcessing

 Convolution
 compute the finite linear convolution of two arrays of samples Calling Sequence Convolution( A, B, options ) Parameters

 A - Array, Vector, or list of real or complex numeric sample values for first signal B - Array, Vector, or list of real or complex numeric sample values for second signal Options

 • algorithm : keyword auto, direct, or fft for the algorithm to use for computation; default is direct
 • container : Array or Vector, predefined container for holding result
 • shape : keyword full, same, or valid for the shape of the convolution; default is full
 • subtype : keyword Array, Vector, Vector[column], or Vector[row] for the subtype of the output; default is Array Description

 • The Convolution(A, B) command computes the full convolution of the signals A and B of length $M$ and $N$ respectively, storing the result in a container C of length $M+N-1$ and having datatype float or complex, which is then returned.
 • The full convolution is defined by the formula

${C}_{k}={\sum }_{i=1}^{k}{A}_{i}{B}_{k-i+1}$

 for each $k$ from $1$ to $M+N-1$, with ${A}_{j}=0$ for $M and ${B}_{j}=0$ for $N.
 • For all choices of shape, the full convolution of size $P=M+N-1$ is computed. When shape=same, the full convolution is trimmed on both sides so that the result is of length $Q=M$. Note that when the number of elements to be trimmed is odd, one more element will be trimmed from the left side than the right. When shape=valid, the final convolution will be found in a similar manner to the shape=same case, but the value of the size $Q$ will be $M$ when $N=0$, and $\mathrm{max}\left(M-N+1,0\right)$ otherwise. The valid convolution effectively discards the elements which involve padded zeros for the signals.
 • Before the code performing the computation runs, A and B are converted to datatype float (if the values are all real-valued) or complex (if all the values are complex-valued, but not all real-valued) if they do not have that datatype already. For this reason, it is most efficient if A and B have one of these datatypes beforehand.
 • If either A or B is an rtable that is not a 1-D Array, it is accepted by the command and converted to an Array. Should this not be possible, an error will be thrown.
 • If the container=C option is provided, then the results are put into C and C is returned. With this option, no additional memory is allocated to store the result. The container must be a 1-D rtable of appropriate size having datatype float (for two real signals) or complex (for one or two complex signals).
 • The algorithm=name option can be used to specify the algorithm used for computing the convolution. Supported algorithms:
 – auto - automatically choose the fastest algorithm based on input.
 – direct - use direct convolution formula for computation. This is the default.
 – fft - use an algorithm based on the Fast Fourier Transform (FFT). This is a much faster algorithm than the direct formula for large samples, but numerical roundoff can cause significant numerical artifacts, especially when the result has a large dynamic range. • The SignalProcessing[Convolution] command is thread-safe as of Maple 17. Examples

 > $\mathrm{with}\left(\mathrm{SignalProcessing}\right):$ Example 1

 > $\mathrm{Convolution}\left(\mathrm{Array}\left(\left[5,7\right]\right),\mathrm{Array}\left(\left[-2,6,10\right]\right)\right)$
 $\left[\begin{array}{cccc}{-10.}& {16.}& {92.}& {70.}\end{array}\right]$ (1) Example 2

 > $a≔\mathrm{Array}\left(\left[1,2,3\right],'\mathrm{datatype}'={'\mathrm{float}'}_{8}\right)$
 ${a}{≔}\left[\begin{array}{ccc}{1.}& {2.}& {3.}\end{array}\right]$ (2)
 > $b≔\mathrm{Array}\left(\left[1,-1,1,-1\right],'\mathrm{datatype}'={'\mathrm{float}'}_{8}\right)$
 ${b}{≔}\left[\begin{array}{cccc}{1.}& {-1.}& {1.}& {-1.}\end{array}\right]$ (3)
 > $\mathrm{Convolution}\left(a,b,'\mathrm{algorithm}'='\mathrm{auto}'\right)$
 $\left[\begin{array}{cccccc}{1.}& {1.}& {2.}& {-2.}& {1.}& {-3.}\end{array}\right]$ (4)
 > $c≔\mathrm{Array}\left(1..\mathrm{numelems}\left(a\right)+\mathrm{numelems}\left(b\right)-1,'\mathrm{datatype}'={'\mathrm{float}'}_{8}\right):$
 > $\mathrm{Convolution}\left(a,b,'\mathrm{container}'=c,'\mathrm{algorithm}'='\mathrm{direct}'\right)$
 $\left[\begin{array}{cccccc}{1.}& {1.}& {2.}& {-2.}& {1.}& {-3.}\end{array}\right]$ (5)
 > $c$
 $\left[\begin{array}{cccccc}{1.}& {1.}& {2.}& {-2.}& {1.}& {-3.}\end{array}\right]$ (6) Example 3

 > $A≔{\mathrm{Vector}}_{\mathrm{row}}\left(\left[2-I,0,5+3I,0,4I\right]\right)$
 ${A}{≔}\left[\begin{array}{ccccc}{2}{-}{I}& {0}& {5}{+}{3}{}{I}& {0}& {4}{}{I}\end{array}\right]$ (7)
 > $B≔{\mathrm{Vector}}_{\mathrm{row}}\left(\left[-7,3+10I,9-2I,1\right]\right)$
 ${B}{≔}\left[\begin{array}{cccc}{-7}& {3}{+}{10}{}{I}& {9}{-}{2}{}{I}& {1}\end{array}\right]$ (8)
 > $\mathrm{C1}≔\mathrm{Convolution}\left(A,B,'\mathrm{algorithm}'='\mathrm{fft}'\right)$
 ${\mathrm{C1}}{≔}\left[\begin{array}{cccccccc}{-14.}{+}{7.}{}{I}& {16.0000000000000}{+}{17.}{}{I}& {-19.}{-}{34.}{}{I}& {-13.}{+}{58.}{}{I}& {51.}{-}{11.}{}{I}& {-35.}{+}{15.0000000000000}{}{I}& {8.}{+}{36.}{}{I}& {0.}{+}{4.00000000000000}{}{I}\end{array}\right]$ (9)
 > $\mathrm{C2}≔{\mathrm{~}}_{\mathrm{round}}\left(\mathrm{C1}\right)$
 ${\mathrm{C2}}{≔}\left[\begin{array}{cccccccc}{-14.}{+}{7.}{}{I}& {16.}{+}{17.}{}{I}& {-19.}{-}{34.}{}{I}& {-13.}{+}{58.}{}{I}& {51.}{-}{11.}{}{I}& {-35.}{+}{15.}{}{I}& {8.}{+}{36.}{}{I}& {0.}{+}{4.}{}{I}\end{array}\right]$ (10) Example 4

 > $A≔{\mathrm{Vector}}_{'\mathrm{row}'}\left(\left[2,3,5,7,11\right]\right)$
 ${A}{≔}\left[\begin{array}{ccccc}{2}& {3}& {5}& {7}& {11}\end{array}\right]$ (11)
 > $B≔{\mathrm{Vector}}_{'\mathrm{row}'}\left(\left[13,17,19,23\right]\right)$
 ${B}{≔}\left[\begin{array}{cccc}{13}& {17}& {19}& {23}\end{array}\right]$ (12)
 > $\mathrm{Convolution}\left(A,B,'\mathrm{shape}'='\mathrm{full}','\mathrm{subtype}'='{\mathrm{Vector}}_{\mathrm{row}}'\right)$
 $\left[\begin{array}{cccccccc}{26.}& {73.}& {154.}& {279.}& {426.}& {435.}& {370.}& {253.}\end{array}\right]$ (13)
 > $\mathrm{Convolution}\left(A,B,'\mathrm{shape}'='\mathrm{same}','\mathrm{subtype}'='{\mathrm{Vector}}_{\mathrm{row}}'\right)$
 $\left[\begin{array}{ccccc}{154.}& {279.}& {426.}& {435.}& {370.}\end{array}\right]$ (14)
 > $\mathrm{Convolution}\left(A,B,'\mathrm{shape}'='\mathrm{valid}','\mathrm{subtype}'='{\mathrm{Vector}}_{\mathrm{row}}'\right)$
 $\left[\begin{array}{cc}{279.}& {426.}\end{array}\right]$ (15) Compatibility

 • The SignalProcessing[Convolution] command was introduced in Maple 17.