8.1. Feature Extraction
Feature extraction transforms raw sensor data into a representation that helps the neural network learn patterns more effectively. The same transforms run on the PC during training and on the MCU during inference, so training and deployment see identical features.
Reduced input size: compress long time series.
Better patterns: move to a domain (for example frequency) where patterns are clearer.
Faster inference: smaller inputs mean smaller and faster models.
Domain knowledge: reuse signal processing expertise.
8.1.1. Pipeline
Raw data flows through two stages, data processing and then feature extraction:
Raw signal --> Data processing --> Feature extraction --> Model input
(data_proc_transforms) (feat_ext_transform)
e.g. SimpleWindow, e.g. FFT_FE, BINNING,
Downsample ABS, LOG_DB, CONCAT
Important
data_proc_transforms run only on the training side (on the PC). feat_ext_transform runs on
the PC during training and on the device during inference.
There are two ways to configure it: pick a preset with feature_extraction_name, or define a
custom pipeline with a Custom_* name and your own feat_ext_transform list. The section of
the config YAML is data_processing_feature_extraction.
8.1.2. Configuration parameters
Core parameters (time series)
Option |
Description |
|---|---|
|
Preset name (for example |
|
Data processing steps run before feature extraction: |
|
Ordered list of feature extraction transforms (see the tables below). |
|
Input channels. An integer (first N columns), a list of column indices ( |
|
Samples per frame. |
|
Output features per frame after the transform. |
|
Frames concatenated into one model input. Total features = |
|
Window stride as a fraction of |
|
Original and target sampling rate for |
|
Scaling factor applied to the input data. |
|
Frame overlap control (see Frame offset). |
|
Number of frames skipped between selected frames. |
|
|
|
Bin normalization and the first frequency bin to include. |
|
Fraction of the signal bandwidth to analyse (1 = full). |
|
Parameters of |
|
Bit-shift scale for the Q15 transforms. |
|
Per-class gain augmentation (see Gain variation augmentation). |
|
Run the Goodness of Fit test on the extracted features; see Goodness of Fit. |
|
Store the extracted features to disk. |
|
Stop after data processing and feature extraction (see Feature extraction only mode). |
|
Use a neural network for feature extraction. |
|
Forecasting only: number of future steps and the columns to forecast. |
8.1.3. Presets
Presets in 1.5.0 are defined in ModelMaker (tinyml_modelmaker/ai_modules/timeseries/constants.py).
Use a preset by name and set variables:
data_processing_feature_extraction:
feature_extraction_name: 'Generic_1024Input_FFTBIN_64Feature_8Frame'
variables: 1
The generic presets follow the pattern Generic_<InputSize>Input_<Transform>_<Features>Feature_<Frames>Frame. For
example, Generic_1024Input_FFTBIN_64Feature_8Frame takes 1024 samples, applies an FFT with binning to 64
features per frame, and concatenates 8 frames (512 features to the model).
Generic presets
Preset |
Transform |
|---|---|
|
FFT with binning, 8 frames |
|
FFT, single frame |
|
Raw time-domain samples |
|
Absolute value of 8 samples |
Application presets
Preset |
Application |
|---|---|
|
FFT with full, half or quarter bandwidth |
|
Arc fault |
|
Motor fault, 3-axis vibration |
|
PIR detection |
|
Fall detection |
|
WiFi CSI presence detection |
|
ECG classification |
|
Starting points for custom pipelines ( |
The preset list is the one in the source; other presets exist per task type (audio presets are described
below). To see the preset an example uses, open its config in examples/<name>/.
8.1.4. Data processing transforms
SimpleWindow segments continuous data into fixed-size windows:
data_processing_feature_extraction:
data_proc_transforms: ['SimpleWindow']
frame_size: 256
stride_size: 0.01
variables: 1
Downsample reduces the sampling rate (sampling_rate to new_sr). Transforms run in the order given:
data_processing_feature_extraction:
data_proc_transforms: ['Downsample', 'SimpleWindow']
sampling_rate: 313000
new_sr: 3130
frame_size: 256
stride_size: 0.01
variables: 1
8.1.5. Feature extraction transforms
feat_ext_transform is an ordered list. Each step processes the output of the previous one.
Transform |
Description |
|---|---|
|
FFT of each frame. |
|
Keep the positive-frequency half of the FFT. |
|
Apply a window function. |
|
Group frequency bins to reduce the feature count. |
|
Normalize features ( |
|
Absolute value. |
|
Logarithmic (dB) scale. |
|
Remove the DC component. |
|
Concatenate frames into the final feature vector. |
|
Mean of the wave in each frame; removes DC if |
|
Round the values (used by the |
|
Column-wise real FFT across the variables axis, per window. |
|
L2 norm across rows. |
|
Statistical features per frame: kurtosis, spectral entropy, zero-crossing rate, dominant frequency, slope changes. |
|
PIR sensor features (float and fixed-point). |
Q15 fixed-point transforms mirror the float pipeline with 16-bit fixed-point math, so the same operations run
on MCUs without a floating-point unit. Q15 maps [-1, +1] to [-32768, +32767].
Transform |
Description |
|---|---|
|
Convert float to Q15 with saturation. |
|
Fixed-point real FFT (equivalent of |
|
Bit-shift scaling by |
|
Magnitude of the complex Q15 FFT output (equivalent of |
|
Average per bin, optionally normalized by |
Example: FFT with binning
data_processing_feature_extraction:
feat_ext_transform: ['FFT_FE', 'FFT_POS_HALF', 'DC_REMOVE', 'ABS', 'BINNING', 'LOG_DB', 'CONCAT']
frame_size: 1024
feature_size_per_frame: 64
num_frame_concat: 4
variables: 1
Example: Q15 pipeline for MCUs
data_processing_feature_extraction:
feat_ext_transform: ['FFT_Q15', 'Q15_SCALE', 'Q15_MAG', 'DC_REMOVE', 'BIN_Q15', 'CONCAT']
frame_size: 256
feature_size_per_frame: 16
num_frame_concat: 8
q15_scale_factor: 5
normalize_bin: True
variables: 1
8.1.6. Custom feature extraction
Use a Custom_* name and define the pipeline yourself:
data_processing_feature_extraction:
data_proc_transforms: ['SimpleWindow']
feature_extraction_name: 'Custom_Default'
feat_ext_transform: ['FFT_FE', 'FFT_POS_HALF', 'WINDOWING', 'BINNING', 'NORMALIZE', 'ABS', 'LOG_DB', 'CONCAT']
frame_size: 32
feature_size_per_frame: 8
num_frame_concat: 8
variables: 5
Add the fine-grained keys (normalize_bin, stacking, offset, scale, frame_skip, log_mul,
log_base, log_threshold) when you need them.
8.1.7. Windowing and framing
8.1.7.1. Frame offset
offset controls the overlap between consecutive frames. offset: 0 means no overlap. With offset: n the
step is 1/n of a frame: offset: 2 gives 50% overlap and offset: 4 gives 75%. More overlap produces more
training samples from the same data.
data_processing_feature_extraction:
offset: 2
frame_size: 256
variables: 3
8.1.7.2. Stacking modes
stacking controls how multi-channel features are arranged for the model.
'1D': features of all channels are concatenated into one flat sequence ([a1, a2, a3, b1, b2, b3, ...]). Good for fully connected models.'2D1'(default): a 2D matrix with one row per channel. Good for convolutional models.
8.1.7.3. Analysis bandwidth
analysis_bandwidth: 1 analyses the full spectrum; 0.5 only the lower half. Use it when only part of the
spectrum matters.
8.1.7.4. Gain variation augmentation
gain_variations multiplies the raw data of each class by a random gain drawn from U(min, max), which makes the
model robust to amplitude changes. It is applied before feature extraction, with Downsample or SimpleWindow.
data_processing_feature_extraction:
data_proc_transforms: [Downsample, SimpleWindow]
gain_variations:
arc: [0.9, 1.1]
normal: [0.8, 1.2]
sampling_rate: 313000
new_sr: 3130
frame_size: 256
stride_size: 0.01
variables: 1
8.1.7.5. Forecasting
Forecasting needs SimpleWindow plus the forecasting keys:
data_processing_feature_extraction:
data_proc_transforms: [SimpleWindow]
frame_size: 32
stride_size: 0.1
forecast_horizon: 2
variables: 1
target_variables: [0]
8.1.8. Audio front-ends
Audio classification (target_module: audio) selects the front end with audio_feature and a preset. The
audio parameters and their defaults are:
Option |
Description |
|---|---|
|
|
|
Audio sampling rate (default 16000) and clip length (default 1000 ms). |
|
Analysis frame length and step (defaults 30 and 20 ms). |
|
MFCC settings (defaults 10 and 40). |
|
LPC settings (defaults 70 and 10). |
|
Learned filterbank settings (defaults 64, 64, 4, 20, 8 and 16). |
|
FFT front-end settings (defaults 512, 32, 1, 8 and 1). |
|
Normalize the waveform (default true) and mix to mono (default true). |
Audio presets:
Preset |
Front end |
|---|---|
|
MFCC (10 coefficients, 40 mel bands). |
|
LPC front end that matches the MSPM0G5187 firmware pipeline (8000 Hz, and 8820 Hz from the I2S path), used by cough detection. |
|
Learned filterbank: a Conv1D filter bank that is trained jointly with the model ( |
|
Q15 FFT, binning and concatenation (512 point FFT, 32 features per frame), used with |
See Audio Classification, Wake Word Detection and Glass Break Detection.
8.1.9. Radar and image inputs
Radar classification uses image-style parameters instead of the transforms above. The Mnist_Default preset
sets image_height, image_width, image_num_channel, image_mean and image_scale. See
Radar Classification.
8.1.10. Evaluating feature extraction quality
Before training, ModelMaker writes PCA plots of the extracted features for classification tasks
(pca_on_feature_extracted_train_data.png and ..._validation_data.png in the training/base folder of the run).
Clusters that are visibly separable are easier for the model to learn.
PCA of the extracted features on training data
PCA of the extracted features on validation data
Tight, well-separated clusters: the features represent the classes well.
Overlapping clusters: try a different feature extraction.
Scattered points: high variance, possibly noisy data.
No single feature extraction is best for every dataset. Frequency-domain presets (FFT with binning) usually do better on periodic signals like vibration, and raw presets on waveform-shape problems. Compare several presets.
8.1.10.1. Feature extraction only mode
Set dont_train_just_feat_ext: True to run only data processing and feature extraction. Combine with
store_feat_ext_data: True to export the features. This is a fast way to compare presets by their PCA plots:
data_processing_feature_extraction:
dont_train_just_feat_ext: True
store_feat_ext_data: True
feature_extraction_name: 'Input256_FFTBIN_16Feature_8Frame_3InputChannel_removeDC_2D1'
variables: 3
8.1.11. Memory cost on the device
Feature extraction runs on the MCU before inference and needs its own RAM and Flash. Since 1.5.0 you can see
this cost before training: the compile step reports a Feature Extraction Library memory block next to the
model, and the standalone estimate_memory tool prints it in seconds. See Memory Estimation.
8.1.12. Best practices
Match the transform to the signal: FFT for periodic signals, raw for transient ones.
Start from a standard preset and customize only if needed.
Mind the device: fewer features give smaller models and faster inference.
Compare several options with
dont_train_just_feat_extand the PCA plots.
8.1.13. Next steps
Goodness of Fit to analyze dataset quality
Quantization for model compression