Skip to content

NOTES

Correlation — Similarity as a Function of Shift

Measures how similar two signals are at different relative shifts. Key difference from convolution: the kernel is NOT flipped.


Algorithm

Sliding Correlation (Template Matching)

\[ y[n] = \sum_{k=0}^{M-1} p[k] \cdot s[n + k], \quad n = 0, \dots, L-M \]

Template \(p\) (length \(M\)) slides over signal \(s\) (length \(L\)). Output: \(L-M+1\) points. Peak location = best match offset.

Use: template matching, pattern recognition.

Full Cross-Correlation (Signal Alignment)

\[ y[n] = \sum_{k=0}^{L-1} s[k] \cdot t[n + k], \quad n = -(L-1), \dots, L-1 \]

Output: \(2L-1\) points (bilateral). Peak = delay estimate between the two signals.

Use: signal alignment, delay estimation.

Correlation vs Convolution

Correlation Convolution
Kernel Not flipped Flipped
Meaning Similarity vs shift System response vs time
Commutative No Yes

FFT acceleration

\(\text{corr}(s, t) = \text{IFFT}(\text{FFT}(s) \cdot \overline{\text{FFT}(t)})\)

Auto-correlation detects periodicity

Signal correlated with itself → peak at lag 0, subsequent peak spacing = period.


API Reference

// Sliding correlation (template matching)
tiny_error_t tiny_corr_f32(const float *Signal, int siglen,
                           const float *Pattern, int patlen,
                           float *corrout);

// Full cross-correlation (signal alignment)
tiny_error_t tiny_ccorr_f32(const float *Signal, int siglen,
                            const float *Pattern, int patlen,
                            float *corrout);

Notes

Output buffer size

Sliding: \(L - M + 1\); Full: \(L + M - 1\).

\(siglen < patlen\)?

Sliding correlation requires \(L \geq M\); output is empty otherwise. Full correlation has no such limit.

Correlation ≠ Convolution

Mathematically they differ only by a sign flip: \(\text{corr}(s, p)[n] = \text{conv}(s, p_{\text{flipped}})[n]\).