NOTES¶
Convolution — Foundation of Signal Processing
Flip the kernel, slide it across the signal, multiply and accumulate at each position. FIR filtering is convolution by definition.
Algorithm¶
Full Convolution¶
\[ y[n] = \sum_{k=0}^{M-1} h[k] \cdot x[n - k], \quad n = 0, \dots, L+M-2 \]
\(L\) = signal length, \(M\) = kernel length.
Output Modes¶
| Mode | Output length | Description |
|---|---|---|
CONV_FULL | \(L + M - 1\) | Full, including transients |
CONV_CENTER | \(L\) | Same length as input |
CONV_HEAD | \(L\) | First \(L\) points (real-time) |
CONV_TAIL | \(L\) | Last \(L\) points (trailing) |
Padding¶
| Mode | Behavior | Use case |
|---|---|---|
PAD_ZERO | Zero outside | Default |
PAD_SYMMETRIC | Mirror at edges | DWT, reduce artifacts |
PAD_PERIODIC | Periodic extension | Periodic signals |
Convolution vs Correlation
Convolution flips the kernel; correlation does not. This flip is what makes convolution the natural operation for system response (FIR filtering).
FFT acceleration
Direct convolution \(O(LM)\). For long signals, use FFT: \(\text{conv}(x, h) = \text{IFFT}(\text{FFT}(x) \cdot \text{FFT}(h))\), \(O(N \log N)\).
API Reference¶
// Basic convolution (full mode + zero padding)
tiny_error_t tiny_conv_f32(const float *Signal, int siglen,
const float *Kernel, int kernlen,
float *convout);
// Extended convolution (configurable padding + output mode)
tiny_error_t tiny_conv_ex_f32(const float *Signal, int siglen,
const float *Kernel, int kernlen,
float *convout,
tiny_padding_mode_t padding_mode,
tiny_conv_mode_t conv_mode);
Notes¶
Output buffer size
Full mode: at least \(L+M-1\). Buffer overflow is a silent bug.
ESP32: longer signal should come first
The implementation assumes Signal is the longer array. Order still works if reversed but performance degrades.