# Creating Embedded Algorithms

> A Guide to create embedded ML algorithms

## Background

Traditionally, embedded sensor nodes collect raw data and transmit it to the cloud for processing.
While this keeps the sensor node simple, wireless communication is often one of the largest contributors to power
consumption which is fine for nodes tethered to a wall outlet, but impractical in battery-powered embedded systems.

As a result ultra-low-power design can move this processing closer to the sensor node, reducing the volume of data that
has to be transmitted. Instead of sending continuous raw data,
the device can extract useful information locally and transmit only relevant results.

This is challenging because embedded systems have strict limits on system resources and computational capability.
Designing embedded ML algorithms are a good way to perform that processing, by carefully designing models that can
extract useful information from sensor data while operating within these constraints.

While this can be quite difficult in practice, Infuse-IoT can be used to make many of the steps easier, accelerating design and deployment.

## Demonstration

This guide will follow a similar demonstration as the Nordic Edge AI Lab's
[Gesture Recognition demo](https://nrfconnectdocs.nordicsemi.com/addons/addon-edge-ai/latest/applications/gesture_recognition/README.html).
This consists of creating a model to classify accelerometer motion as one of several gestures such as taps, swipes and rotation.
Not particularly useful model in practice, but it serves as a good starting point.

However, by using Infuse, there are a number of improvements that and simplifications that can be made.

## Approach

At a high level creating an embedded ML algorithm consists of:

- Data collection: Collecting raw, representative data used to train a classifier or ML model
- Preprocessing and Feature extraction: pre-process the data to increase the concentration of relevant information in the raw data.
- Model selection, training and evaluation: Creating a classifier, tuning behaviour and evaluating its performance.
- Model deployment: Taking a model and deploying it on-device.

Each of these steps can be quite time consuming which is why Infuse-IoT can be used as a tool to accelerate the process.
Additionally, the Preprocessing, feature extraction, model architecture can be quite complex.
As a result, Nordic Semiconductor's [Nordic Edge AI Lab](https://www.nordicsemi.com/Products/Technologies/Edge-AI/Edge-AI-Lab)
simplifies these steps a lot and will be used to rapidly speed up the development process.
It's free to use for personal and commercial purposes on Nordic hardware. As for compatibility, the models produced are limited to M33 or M4 devices with Float Support.

This guide will use Nordic Development Kit hardware to demonstrate how to create an accelerometer classifier to identify movement gestures.

## Prerequisites

For this exercise the standard Infuse-IoT Embedded development environment is required.
This assumes the following are setup and functional:

- Signed up for an account on Infuse-IoT Portal
- Installed Infuse-IoT Embedded SDK, and
- Installed and setup Infuse-IoT Python tools.

These can be found in the [embedded-iot](./) guides section.

In addition to these, there are some required steps:

- Sign up to an account for Nordic Edge AI Lab.
- Install additional Python libraries

  - [numpy](https://numpy.org/)
  - [pandas](https://pandas.pydata.org/)

## Next Steps

Next work through creating a dataset.
