vDSP.correlate(_:withKernel:) — meaning of output

My clients are medical researchers researching methods for characterizing patients' gait from raw accelerometry by matching the data stream against a set of "templates." for the various characteristics.

Their (labyrinthine) pseudocode appears to slide a snippet ("template;" kernel?) across a data stream looking for goodness-of-fit by correlation coefficient. This is for each of several templates, so performance is at a premium.

As I read the name and the 13-word description, vDSP.correlate(_:withKernel:) does this — in some way. However, the set of numbers that emerge from my playground experiments don't make sense: Identical segments are scored 0.0 (should be 1.0, right?). Merely similar matches show values barely distinguishable from the rest, and are often well outside the range -1.0 ... 1.0.

Clearly I'm doing it wrong. Web searches don't tell me anything, but I'm naïve on the subject.
  1. Am I mistaken in hoping this vDSP function does what I want? "Yes, you're mistaken" is an acceptable answer. Bonus if you can point me to a correct solution.

  2. If I'm on the right track, how can I generate inputs so I can interpret the output as fits my needs?

Note: Both streams are normalized to µ = 0.0 and σ = 1.0, by vDSP, and validated by all the unit tests I've done so far.

Replies

Hi fritza, sorry about being a little late for answering.


Their (labyrinthine) pseudocode appears to slide a snippet ("template;" kernel?) across a data stream looking for goodness-of-fit by correlation coefficient. This is for each of several templates, so performance is at a premium.

In the way you describe it, looks like a convolution of two signals. Since you are trying to find a cross-correlation when sliding both signals, you must perform a cross-correlation.

It's similar to a convolution process. Theoretically, a cross-correlation is a convolution without reversing one of the signals before sliding it (the point is that, in my experience, there are more already-written code for convolution than for cross-correlation).

You must consider some situations:
  • in most algorithms, the length of both discrete-time signals must be the same, so you may need to append zeros in the end to match it.

  • you can reverse one of the signals and use the convolution function from vDSP.

For future viewers of this question, there is a more detailed description of the correlate method here: https://developer.apple.com/documentation/accelerate/vdsp/1d_correlation_and_convolution