The CONVOL function convolves an array with a kernel, and returns the result. Convolution is a general process that can be used for various types of smoothing, signal processing, shifting, differentiation, edge detection, etc. The CENTER keyword controls the alignment of the kernel with the array and the ordering of the kernel elements. If CENTER is explicitly set to 0, convolution is performed in the strict mathematical sense, otherwise the kernel is centered over each data point.
Assume R = CONVOL(A, K, S), where A is an n-element vector, K is an m-element vector (m < n), and S is the scale factor. If the CENTER keyword is omitted or set to 1:
where the value m/2 is determined by integer division. This means that the result of the division is the largest integer value less than or equal to the fractional number.
If CENTER is explicitly set to 0:
In the two-dimensional, zero CENTER case where A is an m by n-element array, and K is the l by l element kernel; the result R is an m by n-element array:
The centered case is similar, except the t-i and u-j subscripts are replaced by t+i-l/2 and u+j-l/2.
Result = CONVOL( Array, Kernel [, Scale_Factor] [, /CENTER] [, /EDGE_WRAP] [, /EDGE_TRUNCATE] [, MISSING=value] [, /NAN] )
Returns the result of the array convolution.
An array of any basic type except string. The result of CONVOL has the same type and dimensions as Array.
If the Array parameter is of byte type, the result is clipped to the range of 0 to 255. Negative results are set to 0, and values greater than 255 are set to 255.
An array of any type except string. If the type of Kernel is not the same as Array, a copy of Kernel is made and converted to the appropriate type before use. The size of the kernel dimensions must be smaller than those of Array.
| Note |
A scale factor that is divided into each resulting value. This argument allows the use of fractional kernel values and avoids overflow with byte or integer arguments. If omitted, a scale factor of 1 is used.
Set or omit this keyword to center the kernel over each array point. If CENTER is explicitly set to zero, the CONVOL function works in the conventional mathematical sense. In many signal and image processing applications, it is useful to center a symmetric kernel over the data, thereby aligning the result with the original array.
Note that for the kernel to be centered, it must be symmetric about the point K(FLOOR(m/2)), where m is the number of elements in the kernel.
Set this keyword to make CONVOL compute the values of elements at the edge of Array by "wrapping" the subscripts of Array at the edge. For example, if CENTER is set to zero:
where n is the number of elements in Array. The mod operator in the formula above is defined as a mod b = a - b * floor(a/b). For example, -1 mod 5 is 4. If neither EDGE_WRAP nor EDGE_TRUNCATE is set, CONVOL sets the values of elements at the edges of Array to zero.
Set this keyword to make CONVOL compute the values of elements at the edge of Array by repeating the subscripts of Array at the edge. For example, if CENTER is set to zero:
where n is the number of elements in Array. The "<" and ">" operators in the above formula return the smaller and larger of their operands, respectively. If neither EDGE_WRAP nor EDGE_TRUNCATE is set, CONVOL sets the values of elements at the edges of Array to zero.
Set this keyword to the numeric value to return for elements that contain no valid points within the kernel. The default is the IEEE floating-point value NaN. This keyword is only used if the NAN keyword is set.
Set this keyword to cause the routine to check for occurrences of the IEEE floating-point values NaN or Infinity in the input data. Elements with the value NaN or Infinity are treated as missing data. (See Special Floating-Point Values for more information on IEEE floating-point values.) Elements with the value NaN are treated as missing data, and are ignored when computing the convolution for neighboring elements. In the Result, missing elements are replaced by the convolution of all other valid points within the kernel. If all points within the kernel are missing, then the result at that point is given by the MISSING keyword.
| Note |
This routine is written to make use of IDL's thread pool, which can increase execution speed on systems with multiple CPUs. The values stored in the
Convolve a vector of random noise and a one-dimensional triangular kernel and plot the result. Create a simple vector as the original dataset and plot it by entering:
A = RANDOMN(SEED, 100) & PLOT, A
Create a simple kernel by entering:
K = [1, 2, 3, 2, 1]
Convolve the two and overplot the result by entering:
OPLOT, CONVOL(A, K, TOTAL(K))
Introduced: Original