IoT and Embedded Systems

Chapter 12
AI, TinyML and Intelligent Embedded Systems

Bachelors Program in Electronics and Communication
IoT and Embedded Systems   •   Post Graduate

AI, TinyML and Intelligent Embedded Systems

Introduction and Context

The Internet of Things (IoT) increasingly depends on devices that can interpret data locally rather than merely sense, store, and transmit it. A temperature sensor that reports a value is useful; a device that detects overheating, predicts failure, and initiates a safe response is substantially more intelligent. This transformation is enabled by the integration of artificial intelligence (AI), machine learning (ML), embedded computing, communication networks, and control systems.

TinyML refers to the execution of machine-learning inference on highly resource-constrained devices such as microcontrollers, low-power digital signal processors, and sensor nodes. These devices commonly operate with kilobytes or megabytes of memory, limited computational throughput, restricted energy budgets, and intermittent connectivity. TinyML is therefore not simply “small AI.” It requires co-design of the sensing process, data representation, model architecture, software runtime, hardware, energy supply, and system-level response.

An intelligent embedded system is an embedded system that uses data-driven or knowledge-based methods to perceive its environment, infer its state, make decisions, and sometimes adapt its behaviour. It may combine deterministic algorithms with statistical learning. In safety-critical applications, learned models generally complement rather than replace verified control logic.

Learning Objectives

After completing this chapter, the reader should be able to:

  1. Explain the relationship between AI, ML, deep learning, TinyML, and intelligent embedded systems.
  2. Analyse the constraints governing on-device inference.
  3. Describe the complete TinyML development lifecycle.
  4. Select suitable model architectures, data representations, and deployment strategies.
  5. Quantify memory, latency, energy, and classification performance.
  6. Evaluate privacy, safety, security, fairness, and lifecycle risks.
  7. Design and critically assess an intelligent IoT application.

1. Conceptual Foundations

1.1 AI, machine learning, and deep learning

AI is the broad discipline concerned with systems that perform tasks requiring perception, reasoning, learning, planning, or decision-making. ML is a subfield of AI in which a system derives a predictive relationship from examples rather than relying entirely on manually written rules. Deep learning is ML based primarily on multilayer neural networks.

A supervised classifier receives labelled examples of the form (xi, yi), where xi is an input vector and yi is its target label. Training seeks model parameters θ that minimize a loss function:

θ* = arg min_θ (1/N) ∑i=1N L(f_θ(xi), yi)

Here, N is the number of training examples, f_θ is the model, and L measures prediction error. This expression describes empirical-risk minimization. It does not guarantee good performance on unseen data; generalization depends on data quality, model capacity, regularization, and the similarity between deployment and training conditions.

For multiclass classification, a commonly used cross-entropy loss is:

L = −∑k=1K yk log(pk)

where K is the number of classes, yk is 1 for the true class and 0 otherwise, and pk is the predicted probability for class k. Probabilities must be non-negative and sum to one.

1.2 Edge AI and TinyML

Cloud AI transmits data to a remote server for processing. Edge AI places inference near the data source, for example on a gateway, industrial computer, or smartphone. TinyML pushes inference further toward the sensor, often onto a microcontroller.

ApproachMain computationStrengthLimitation
Cloud AIRemote serverHigh computational capacityNetwork dependence, latency, privacy exposure
Edge AILocal gateway or edge computerLower latency and local operationMore hardware and maintenance
TinyMLMicrocontroller or sensor nodeVery low power, privacy, rapid responseSevere memory and compute constraints

TinyML normally performs inference locally, while model training is conducted offline on more capable hardware. Federated learning and continual learning can reduce dependence on centralized raw data, but they introduce additional communication, security, and validation challenges.

1.3 Intelligence as a closed loop

An intelligent embedded system can be represented as a closed loop:

Sense → preprocess → infer → decide → act → observe outcome

The inference output is only one part of the system. A high-accuracy classifier may still be unsuitable if its sensor placement is poor, its decision threshold is unsafe, or its actuator response is unreliable. System intelligence must therefore be evaluated at the level of the complete loop.

2. Constraints of Intelligent Embedded Systems

2.1 Memory and storage

A model occupies memory for weights, biases, intermediate activations, runtime code, and metadata. For a dense layer with nin inputs and nout outputs, the number of weights is:

Nw = nin × nout

If each weight uses bw bytes, weight storage is approximately:

Mw = Nw × bw

This excludes biases and implementation overhead. For an 8-bit model with 20,000 weights, the weights require approximately 20,000 bytes, or 19.5 KiB using 1 KiB = 1024 bytes. Activation memory can exceed weight memory, particularly in convolutional networks, so peak live memory—not only model-file size—must be measured.

2.2 Computation and latency

The number of multiply–accumulate operations (MACs) is a useful, but incomplete, complexity indicator. A one-dimensional convolution with input length L, kernel size k, input channels Ci, and output channels Co requires approximately:

MACs ≈ (L − k + 1) × k × Ci × Co

This assumes a valid convolution, unit stride, and no dilation. Padding, stride, depthwise convolution, recurrent operations, memory transfers, and activation functions alter the actual workload.

For a periodic sensing system, end-to-end latency includes acquisition, preprocessing, inference, postprocessing, communication, and actuation. A model that executes quickly but waits for a large input window may still violate application deadlines.

2.3 Energy

Dynamic energy is often approximated by:

E = P × t

where E is energy in joules, P is power in watts, and t is time in seconds. For a battery-operated device, average power over a duty cycle is more informative than peak power:

Pavg = (1/T) ∫0T P(t) dt

where T is the observation interval. Sleep current, sensor warm-up, radio transmission, flash writes, and voltage-regulator losses must be included. Local inference may save energy by avoiding radio transmission, but this is not universal; the result depends on model cost, sampling rate, communication protocol, and duty cycle.

2.4 Reliability and operating conditions

Embedded models encounter sensor drift, temperature changes, vibration, electromagnetic interference, missing samples, ageing, and distribution shift. A test accuracy measured on a clean laboratory dataset is not a sufficient reliability claim. Evaluation should include environmental variation, abnormal inputs, latency bounds, power states, and recovery behaviour.

3. The TinyML Development Lifecycle

3.1 Problem formulation

The first question is not “Which neural network should be used?” but “What decision must the device support?” A useful specification identifies:

  • the physical phenomenon and sensing modality;
  • the required response time;
  • acceptable false-positive and false-negative rates;
  • energy and memory budgets;
  • safety consequences of an incorrect decision;
  • update, audit, and maintenance requirements.

Classification, regression, anomaly detection, keyword spotting, gesture recognition, and predictive maintenance require different labels, metrics, and deployment strategies.

3.2 Data acquisition and labelling

Data should represent the operating population, sensor tolerances, installation positions, environmental conditions, and failure modes. Windowing is common for time-series data. If a signal is sampled at fs samples per second and a window contains N samples, its duration is:

Tw = N / fs

Overlapping windows increase the number of training examples, but randomly splitting overlapping windows can cause leakage: nearly identical portions of one recording may appear in both training and test sets. Splitting by person, machine, session, or site is usually more credible.

3.3 Preprocessing and feature representation

Common preprocessing operations include normalization, filtering, calibration, resampling, windowing, and spectral transformation. For a value x, standardization is:

z = (x − μ) / σ

where μ and σ are calculated from the training set only, and σ must be non-zero. The same stored parameters must be used during inference.

Feature engineering can reduce computation. Examples include root-mean-square amplitude, zero-crossing rate, statistical moments, frequency-band energy, and cepstral coefficients. Learned features from small convolutional or recurrent networks may be more robust, but generally require greater computational resources.

3.4 Model selection

Suitable model families include:

  • decision trees and small forests for interpretable tabular features;
  • linear and logistic regression for simple, low-cost boundaries;
  • small multilayer perceptrons for compact feature vectors;
  • one-dimensional convolutional networks for time-series signals;
  • depthwise-separable convolutions for reduced computation;
  • recurrent or temporal convolutional models for sequential dependence;
  • autoencoders and statistical models for anomaly detection.

A model should be selected jointly with preprocessing and hardware. A slightly less accurate model that fits deterministic memory and timing limits is often preferable to a larger model that occasionally fails deployment constraints.

3.5 Quantization

Quantization represents values with fewer bits. In uniform affine quantization, a real value r is mapped approximately to an integer q by:

q = round(r/s) + z

where s is a positive scale and z is a zero-point. Dequantization is approximately:

r ≈ s(q − z)

The scale and zero-point depend on the chosen real-value range and integer range. Quantization-aware training simulates quantization during training; post-training quantization applies it after training. The latter is simpler, while the former can preserve accuracy better when precision reduction is severe.

Quantization does not automatically reduce every cost. It can reduce memory and enable integer arithmetic, but kernels, alignment, conversion operations, and hardware support determine the actual benefit.

3.6 Pruning, distillation, and architecture optimization

Pruning removes weights, channels, or neurons judged less important. Unstructured sparsity may reduce parameter count but provide little speed improvement unless the processor supports sparse execution. Structured pruning removes entire filters or channels and is more likely to reduce regular hardware workload.

Knowledge distillation trains a compact student model to reproduce useful information from a larger teacher model. Neural architecture search can explore model structures under explicit constraints, but the search objective should include measured latency, energy, and memory on the target device rather than relying only on desktop estimates.

3.7 Deployment and verification

Deployment commonly involves converting a trained model into a microcontroller-compatible representation, linking an optimized inference library, allocating tensor memory, and integrating sensor drivers and application logic. Verification should include:

  1. numerical comparison between reference and deployed inference;
  2. peak RAM and flash measurement;
  3. worst-case execution-time testing;
  4. energy measurement under realistic duty cycles;
  5. environmental and adversarial testing;
  6. update rollback and fault-recovery testing.

4. Performance Evaluation

Accuracy alone is inadequate, especially with imbalanced classes. For a binary classifier:

Precision = TP / (TP + FP)
Recall = TP / (TP + FN)
F1 = 2 × (Precision × Recall) / (Precision + Recall)

Here, TP, FP, and FN denote true positives, false positives, and false negatives. Precision answers how often positive alarms are correct; recall answers how many actual positives are detected. The F1 score is useful when both matter, but it hides the application-specific cost of errors.

For anomaly detection, threshold selection should reflect operational costs. If missing a dangerous failure is much worse than generating a service alert, the threshold may be set to favour recall. Receiver operating characteristic and precision–recall curves help examine thresholds, but the final choice must be made using field consequences, not only a summary metric.

A useful deployment scorecard includes model quality, memory, latency, energy per inference, false-alarm rate, robustness, explainability, updateability, and security. These dimensions frequently involve trade-offs rather than a single optimum.

5. System Architecture and Communication

An intelligent IoT node may include a sensor interface, signal-conditioning circuit, microcontroller, non-volatile memory, radio, power-management circuit, actuator interface, and secure boot mechanism. Processing may be divided as follows:

FunctionTypical locationReason
Filtering and feature extractionSensor nodeReduces data volume and latency
Immediate classificationSensor nodeSupports privacy and rapid response
Fleet analyticsGateway or cloudUses larger datasets and models
Model trainingCloud or workstationRequires substantial compute
Safety interlockLocal deterministic controllerRemains available during network failure

The intelligent node should not depend on a cloud connection for a response that must occur within a strict safety deadline. Conversely, long-term trend analysis and fleet-level retraining are often better performed centrally.

6. Security, Privacy, Safety, and Governance

TinyML creates security risks at several layers: physical access to firmware, extraction of model parameters, spoofed sensor signals, malicious model updates, insecure debug interfaces, and compromised gateways. Essential practices include secure boot, signed firmware, encrypted or authenticated updates, key protection, disabled production debug access, least-privilege software, and audit logs.

Local inference can reduce the transmission of raw personal data, but it does not eliminate privacy risk. Features, predictions, timestamps, and device identifiers may still reveal sensitive information. Data minimization, purpose limitation, retention control, access control, and transparent user communication remain necessary.

Safety requires a distinction between statistical confidence and physical certainty. A model output is an estimate, not a proof. Safety architectures should define safe states, confidence thresholds, watchdog behaviour, sensor-failure detection, manual override, and fallback logic. In regulated domains, traceability of data, model versions, calibration, test evidence, and field changes is essential.

Fairness can be affected by unequal sensor placement, demographic under-representation, environmental bias, and unequal error costs. Testing should be stratified across relevant operating groups and conditions. Governance should assign responsibility for model approval, monitoring, incident response, and retirement.

7. Illustrative Case: TinyML-Based Motor-Bearing Monitoring

Background

Consider a fictional manufacturing plant operating induction motors. Bearing damage produces changes in vibration before catastrophic failure, but continuously transmitting high-frequency vibration to the cloud is expensive and vulnerable to network outages.

Problem

The plant needs an on-device system that detects three states: normal operation, developing bearing fault, and severe abnormality. The device must operate for long periods from an industrial power budget, issue an alert within one second, and continue local monitoring when connectivity is unavailable.

Analysis

An accelerometer samples vibration at 4 kHz. The system forms windows of 1024 samples, so:

Tw = 1024 / 4000 = 0.256 s

A four-window decision cycle therefore covers 1.024 s if windows are non-overlapping. In practice, overlapping windows can reduce response delay, but they increase computation and must be handled carefully during model evaluation.

A baseline system computes time-domain statistics and selected frequency-band energies. A compact one-dimensional convolutional model is then compared with a gradient-boosted tree using engineered features. The tree may be preferable if its measured latency, memory, and robustness are superior, even if the neural model has slightly higher laboratory accuracy.

Approach and solution

Data are collected from healthy motors and controlled bearing faults at different loads, speeds, temperatures, and mounting conditions. Splits are made by motor and operating session, preventing recordings from the same physical event from appearing in both training and test sets. The model is trained offline, quantized to 8-bit arithmetic, and tested on the target microcontroller.

The local firmware performs sensor-health checks, windowing, feature extraction, inference, temporal smoothing, and a rule-based alarm decision. For example, an alarm may require two abnormal predictions within a specified interval rather than reacting to one noisy window. The rule is independently tested because smoothing changes both false alarms and detection delay.

The radio transmits event summaries and selected diagnostic features rather than continuous raw vibration. A signed update mechanism permits a validated model replacement, while the previous model remains available for rollback.

Outcome

In an illustrative evaluation, the local node reduces communication volume substantially and continues to detect faults during network interruption. The plant gains faster alerts and improved privacy, but it must still periodically inspect motors, recalibrate sensors, monitor model drift, and verify that the model does not confuse load changes with bearing damage.

Learning points

  1. The sensing and windowing design can dominate response time.
  2. Dataset separation by machine and session is more credible than random sample splitting.
  3. Local inference is valuable only when the complete energy and reliability budget is satisfied.
  4. A deterministic safety and alarm layer should supervise the learned prediction.
  5. Deployment monitoring is part of the ML system, not an optional postscript.

8. Contemporary Developments and Research Directions

Research is progressing in ultra-low-power accelerators, event-based sensing, mixed-precision inference, neuromorphic computing, federated learning, adaptive sensing, and continual learning. Tiny transformers and attention mechanisms are being investigated, but their suitability depends on memory access and sequence length; a model that is efficient on a server may be inappropriate for a microcontroller.

Continual learning is attractive for changing environments, yet uncontrolled adaptation can cause catastrophic forgetting or allow corrupted data to alter behaviour. A safe design requires bounded updates, validation gates, version control, rollback, and human or supervisory approval for high-consequence systems.

Digital twins and edge–cloud collaboration can combine local response with system-level diagnosis. Open research questions include trustworthy uncertainty estimation on constrained hardware, formal assurance of hybrid learned-control systems, energy-aware lifelong learning, and methods for detecting distribution shift at the device.

9. Best-Practice Design Principles

  • Begin with a measurable operational decision and a failure-cost analysis.
  • Collect representative data, including abnormal and inconvenient operating conditions.
  • Prevent leakage through group- or session-based dataset splitting.
  • Establish memory, latency, energy, and reliability budgets before model selection.
  • Benchmark on the target hardware, not only on a workstation.
  • Prefer the simplest model that satisfies the complete system requirement.
  • Treat calibration, uncertainty, sensor health, and fallback behaviour as first-class functions.
  • Secure the full lifecycle: provisioning, inference, logging, update, rollback, and retirement.
  • Monitor drift and field performance after deployment.
  • Document data provenance, model versions, assumptions, test results, and known limitations.

Chapter Summary

AI-enabled embedded systems combine sensing, computation, learning, decision-making, and actuation. TinyML places ML inference on highly constrained devices, creating benefits in latency, privacy, resilience, and communication efficiency while imposing strict memory, energy, timing, and reliability constraints. Effective design requires an end-to-end lifecycle: formulate the decision, acquire representative data, prevent leakage, select and compress a model, deploy it on target hardware, and verify its behaviour under realistic conditions.

Important quantitative considerations include memory required by weights and activations, operation count, window duration, average power, energy per inference, and classification metrics such as precision, recall, and F1 score. Quantization, pruning, distillation, and efficient architectures can reduce resource use, but their benefits must be measured on the actual device. Intelligent systems also require secure updates, privacy protection, safety interlocks, fairness assessment, lifecycle governance, and monitoring for drift. The central engineering principle is that model accuracy is only one component of trustworthy embedded intelligence.

Key Terms

AI: The discipline of building systems capable of perception, reasoning, learning, or decision-making.

Machine learning: Methods that learn predictive relationships from data.

Deep learning: Machine learning using multilayer neural networks.

TinyML: Machine-learning inference on highly resource-constrained embedded devices.

Edge AI: AI computation performed near the source of data.

Inference: Use of a trained model to produce a prediction.

Training: Optimization of model parameters using data.

Quantization: Representation of numerical values with reduced precision.

Pruning: Removal of parameters, neurons, filters, or connections.

Knowledge distillation: Training a compact student model using information from a larger teacher model.

Concept drift: Change in the relationship between inputs and desired outputs over time.

Data leakage: Unintended use of information from evaluation data during training.

Latency: Time between input acquisition and system response.

Duty cycle: Fraction of time a device or subsystem is active.

Precision: Proportion of predicted positives that are true positives.

Recall: Proportion of actual positives that are detected.

Federated learning: Collaborative model training without centrally collecting all raw data.

Secure boot: Startup process that verifies the authenticity and integrity of firmware.

Uncertainty: A measure of limited confidence or incomplete knowledge in a prediction.

Model drift: Degradation caused by changes between training and deployment conditions.

Review Questions

Short Answer Questions

  1. Distinguish AI, machine learning, deep learning, and TinyML.
  2. Why can activation memory be more important than model-file size?
  3. State two advantages and two limitations of local inference.
  4. Define precision and recall in a binary classification problem.
  5. Why is random splitting of overlapping time-series windows potentially misleading?

Long Answer Questions

  1. Explain the complete TinyML development lifecycle from problem formulation to field monitoring.
  2. Discuss how quantization, pruning, and knowledge distillation affect model deployment.
  3. Analyse the design trade-offs between cloud AI, edge AI, and TinyML.
  4. Explain the security, privacy, safety, and governance requirements of intelligent IoT devices.
  5. Describe how an intelligent embedded system should be evaluated beyond classification accuracy.

Analytical / Application Questions

  1. A device samples at 8 kHz and processes windows of 2048 samples. Calculate the window duration and discuss how overlapping windows might affect latency and energy consumption.
  2. Design a TinyML architecture for detecting abnormal household energy consumption. Specify sensors, features, model type, local actions, cloud functions, and evaluation metrics.
  3. A deployed fault detector shows excellent laboratory recall but many field false alarms during seasonal temperature changes. Diagnose likely causes and propose a data, model, threshold, and monitoring strategy.

Multiple Choice Questions with Answers

Question 1

Which statement best describes TinyML?

A. Training very large models exclusively in cloud data centres

B. Running machine-learning inference on highly resource-constrained embedded devices

C. Replacing all deterministic control systems with neural networks

D. Using only symbolic rules in sensor networks

Correct Answer: B. Running machine-learning inference on highly resource-constrained embedded devices

Question 2

A sensor samples at 4 kHz and collects 1024 samples per window. What is the window duration?

A. 0.0256 s

B. 0.256 s

C. 2.56 s

D. 4.096 s

Correct Answer: B. 0.256 s

Question 3

In the quantization relation q = round(r/s) + z, what does s represent?

A. The zero-point

B. The integer output

C. The scale factor

D. The number of classes

Correct Answer: C. The scale factor

Question 4

Which metric answers how many actual positive cases were detected?

A. Precision

B. Recall

C. Specificity

D. Latency

Correct Answer: B. Recall

Question 5

Why can random splitting of overlapping time-series windows cause data leakage?

A. It removes all abnormal samples

B. It makes the sensor sample at a lower rate

C. Nearly identical portions of one recording may occur in training and test sets

D. It converts floating-point values to integers

Correct Answer: C. Nearly identical portions of one recording may occur in training and test sets

Question 6

Which deployment property must be measured on the target microcontroller?

A. Only desktop training accuracy

B. Only the number of training epochs

C. Peak RAM, execution time, and energy behaviour

D. The cloud provider’s storage capacity

Correct Answer: C. Peak RAM, execution time, and energy behaviour

Question 7

For a binary classifier, precision is calculated as:

A. TP ÷ (TP + FP)

B. TP ÷ (TP + FN)

C. FP ÷ (TP + FP)

D. FN ÷ (TN + FN)

Correct Answer: A. TP ÷ (TP + FP)

Question 8

Which practice most directly protects against unauthorized firmware replacement?

A. Increasing the sensor sampling rate

B. Secure boot and signed firmware updates

C. Using a larger classification window

D. Removing all diagnostic logs

Correct Answer: B. Secure boot and signed firmware updates

Question 9

Why may a deterministic safety layer supervise a learned model?

A. Statistical confidence is not a physical safety guarantee

B. It always increases neural-network accuracy

C. It eliminates the need for testing

D. It guarantees zero energy consumption

Correct Answer: A. Statistical confidence is not a physical safety guarantee

Question 10

What is a major risk of uncontrolled continual learning in an embedded device?

A. The device will always use less memory

B. The model may adapt to corrupted data or forget earlier capabilities

C. The radio will become physically larger

D. Quantization will become mathematically impossible

Correct Answer: B. The model may adapt to corrupted data or forget earlier capabilities

IoT and Embedded Systems
Chapter 12 of 12