Skip to content

Convolution & Cross Correlation

Sambit Paul edited this page Jun 2, 2020 · 12 revisions

Convolution

Convolution works in 3 modes:

  1. Full: This returns the convolution at each point of overlap between kernel and signal.
  2. Same: This returns the convolution such that it maintains the same size as the original signal.
  3. Valid: This returns the convolution for the point where the kernel and the signal overlap completely.

The parameters for this filter are as follows:

  • Mode of Operation ⇨ Can be "full", "same", "valid"
  • Kernel ⇨ 1-D Array the signal is convolved with

Signal used: [2, 8, 0, 4, 1, 9, 9, 0]
Kernel used: [1, 3, 1, 3]
Code
String mode = "full"; //Can be "valid", "same"
Convolution con = new Convolution(signal, kernel);
double[] out = con.convolve("full");
Output: [2, 14, 26, 18, 37, 16, 49, 39, 36, 27, 0]

Cross-Correlation

Works in the exact same way as convolve.

The parameters for this filter are as follows:

  • Mode of Operation ⇨ Can be "full", "same", "valid"
  • Kernel ⇨ 1-D Array the signal is cross-correlated with

Signal used: [2, 8, 0, 4, 1, 9, 9, 0]
Kernel used: [1, 3, 1, 3]
Code
String mode = "full"; //Can be "valid", "same"
CrossCorrelation cc = new CrossCorrelation(signal, kernel);
double[] out = cc.cross_correlate("full");
Output: [6, 26, 14, 38, 15, 40, 43, 37, 36, 9, 0]
Clone this wiki locally