Skip to content

End-to-end projects

Recognise gestures with motion sensors

Build a model that tells idle, wave and shake apart, from recording the data to downloading a package.

Try it in Studio
On this page

What you will build

A Motion model that recognises three gestures made with a sensor board in your hand:

LabelMovement
idleHold the board still, or move it slowly
waveWave slowly from side to side, about once per second
shakeShake quickly, several times per second

These three differ mostly in rhythm, so the tutorial uses the Spectral Analysis block and the Classification learning block.

What you need

  • A PetalEdge account.
  • A way to record 3-axis accelerometer data:
  • About 30 minutes.

1. Create the project

  1. In Studio, choose Create new project.
  2. Name it Gesture tutorial, choose Motion: Gesture Recognition and the Sensor device input.
  3. Select Create Project.

2. Record the data

Record 15 to 20 recordings per label, each about 3 to 5 seconds long.

  • With a connected device: on Data acquisition, use Collect from device with Length (ms) 5000 and Frequency (Hz) 100.
  • With a USB board: on Data labeling, select Connect Device, create the labels idle, wave and shake in Gesture labels, then use Record a sample.
  • With CSV files: name them idle.01.csv, wave.01.csv, … and upload them with Infer from filename and Automatically split between training and testing.

Record about 80 % into Training and 20 % into Testing. Vary how you hold the board a little between recordings.

3. Check the data

Open Data labeling. Check that every label has recordings in both Training and Testing, open a few recordings in the signal viewer, and delete any that went wrong.

4. Design the impulse

Open Create impulse and set:

SettingValue
Input axesThe three accelerometer axes (e.g. accX, accY, accZ)
Window (ms)1000
Increase (ms)500
  1. Add a processing block → Spectral Analysis.
  2. Add a learning block → Classification.
  3. Select Save Impulse.

A 1-second window is long enough to hold at least one full wave.

5. Generate features

  1. Open Spectral Analysis in the left menu.
  2. Keep the default parameters and select Save parameters.
  3. On the Generate features tab, select Generate features.
  4. In the feature explorer, idle, wave and shake should form three groups.

6. Train

  1. Open Classification in the left menu.
  2. Keep the defaults: Training cycles 60, Learning rate 0.001.
  3. Select Start training and wait for Training output to finish.

7. Evaluate and test

  1. Open Evaluation. Look at Per window and Per recording accuracy and the confusion matrix.
  2. Open Model testing and select Classify all.
  3. If you have a connected device, open Live classification, select Start Session, and try each gesture. Watch the Prediction timeline.

If wave and shake get mixed up, record more examples of both, with a clearer difference in speed, and retrain.

8. Deploy

  1. Open Deployment.
  2. Choose Generic tf lite (or Raspberry Pi) as the target.
  3. Choose a Precision. Compare the scores of Unoptimized (float32) and Quantized (int8).
  4. Select Build Deployment Package, then Download Latest Build.

What you learned

  • How to record and label motion data.
  • How windows turn recordings into training examples.
  • Why Spectral Analysis suits rhythmic gestures.
  • How to read per-window and per-recording results.
  • How to build a deployment package.