Edge Analytics, TinyML and Intelligent DevicesIntroduction and ContextInternet of Things (IoT) devices continuously generate data from sensors measuring temperature, vibration, sound, light, pressure, motion, chemical concentration and electrical variables. Sending all raw data to a cloud platform is often impractical. Communication consumes energy, networks may be unreliable, sensitive data may leave the operating environment, and cloud round-trip latency may be too high for safety-critical decisions. Edge analytics addresses these limitations by processing data near the sensor or actuator. A device may clean a signal, extract useful features, detect an abnormal condition and initiate a response without transmitting every sample. TinyML extends this approach by running machine-learning inference on resource-constrained embedded hardware such as microcontrollers. An intelligent IoT device is therefore not simply a sensor with an internet connection. It is a cyber-physical component that observes a physical process, transforms observations into information, makes decisions under resource constraints and, in some cases, acts on the environment. Learning ObjectivesAfter completing this chapter, a learner should be able to: - Explain the role of edge analytics and TinyML in IoT systems.
- Apply basic filtering and windowing techniques to sensor data.
- Extract suitable time-domain and frequency-domain features.
- Distinguish thresholding, statistical anomaly detection and machine-learning classification.
- Describe the deployment workflow for lightweight models on microcontrollers.
- Evaluate accuracy, latency, memory, energy, bias, privacy and explainability.
- Design a responsible intelligent-device solution for a practical IoT application.
1. Edge Analytics as an IoT Design PatternA conventional cloud-centred pipeline is: Sensor → Network → Cloud storage and analytics → Command or alert An edge-oriented pipeline is: Sensor → Local preprocessing → Local inference → Immediate action, with selected summaries sent to the cloud. Processing can occur at several levels: | Level | Typical capability | Example |
|---|
| Sensor node | Filtering and simple inference | Detecting a vibration threshold | | Edge gateway | Aggregation and more complex models | Classifying machine states | | Fog or local server | Multi-device analytics | Coordinating a production cell | | Cloud | Large-scale training and historical analysis | Fleet-wide predictive maintenance |
Edge processing does not eliminate the cloud. A strong architecture usually divides responsibilities: devices perform rapid, privacy-sensitive and bandwidth-saving operations, while cloud systems perform model training, fleet management, long-term storage and comparative analysis. Reasons for processing at the edge- Latency: A local decision avoids network transmission and remote processing delay.
- Bandwidth: Only events, features or summaries need to be transmitted.
- Energy: Radio communication can consume substantial energy relative to a local arithmetic operation.
- Reliability: A device can continue operating during network interruption.
- Privacy: Raw audio, images or biometric signals may remain local.
- Safety: Immediate local responses are preferable when delay could cause harm.
However, edge deployment introduces limitations. A microcontroller may have only tens or hundreds of kilobytes of RAM, limited flash storage, modest clock frequency and no operating system. Models must therefore be selected and optimized according to the complete device budget rather than predictive performance alone. 2. From Raw Samples to DecisionsA practical edge-analytics pipeline contains the following stages: - Sensing: Convert a physical quantity into electrical or digital samples.
- Calibration: Correct offset, gain and known sensor non-linearity.
- Filtering: Reduce noise or reject unwanted frequency components.
- Segmentation: Divide the stream into analysis windows.
- Feature extraction: Convert samples into informative numerical descriptors.
- Inference: Apply a rule, statistical detector or trained model.
- Decision logic: Confirm, suppress or prioritize an event.
- Action and communication: Operate an actuator and transmit appropriate information.
- Monitoring: Record confidence, health indicators and model performance.
A raw signal is often represented as a sequence x[n], where n is the sample index. If the sampling frequency is fs samples per second, the sampling interval is: Ts = 1/fs Here, Ts is measured in seconds. The sampling frequency must be sufficiently high for the signal of interest. For a band-limited signal with highest relevant frequency fmax, the classical Nyquist condition is fs > 2fmax. This condition assumes appropriate anti-aliasing filtering. In real systems, a higher rate is often selected to provide a transition band for the analogue filter and to accommodate non-ideal signals. Calibration and normalizationA simple affine calibration is: y = ax + b where x is the sensor output, y is the calibrated quantity, a is a scale factor and b is an offset. The units of a and b must make the equation dimensionally consistent. For machine-learning input, standardization is sometimes used: z = (x − μ)/σ where μ is the training-set mean and σ is the training-set standard deviation. The same training values must be stored and used during deployment; calculating new normalization values independently on each device can create inconsistent inputs and data leakage. 3. Filtering and WindowingSensor measurements include useful variation, environmental interference, quantization effects and sometimes sensor faults. Filtering should be designed from the physical meaning of the signal, not applied automatically. Moving-average filterFor a window of N samples, the moving average is: y[n] = (1/N) ∑_(k=0)^(N−1) x[n−k] It reduces rapid random variation when the desired signal changes more slowly than the window. Its output is delayed and its response to sudden changes is softened. Increasing N improves smoothing but increases delay and may hide short events. For a sampling rate fs, a window containing N samples spans approximately: Tw = N/fs This is the window duration, assuming uniformly spaced samples. Exponential moving averageAn exponential moving average can be written as: y[n] = αx[n] + (1 − α)y[n−1] where 0 < α ≤ 1. A larger α responds faster but smooths less. The initial value y[0] must be specified, commonly as the first sample or an initial measured baseline. This filter requires little memory because only the previous output is retained. Digital filter selection- A low-pass filter suppresses rapid changes and is useful for slowly varying temperature or orientation signals.
- A high-pass filter suppresses slow drift and can emphasize sudden movement.
- A band-pass filter retains a selected frequency range, often useful for vibration or physiological signals.
- A notch filter rejects a narrow interference frequency, such as mains interference.
Filtering can be implemented in floating-point or fixed-point arithmetic. Fixed-point implementation can reduce hardware requirements but requires careful scaling, overflow protection and quantization analysis. A filter must also be evaluated for phase delay: in a control or alarm system, a mathematically good filter may be operationally unsuitable if it delays detection. 4. Feature ExtractionFeature extraction reduces a window of samples to a smaller representation. A good feature is informative, stable under expected variation and inexpensive to compute. For samples x1, x2, …, xN, common time-domain features include: Mean: μ = (1/N) ∑_(i=1)N xi Variance: For a sample estimate of variance, when N > 1: s² = (1/(N−1)) ∑_(i=1)N (xi − x̄)² Here, x̄ is the sample mean. The denominator N−1 estimates the variance of the underlying process from a sample; using N instead is a population-style or mean-square calculation and should not be confused with the unbiased sample estimate. Root mean square (RMS): xRMS = √[(1/N) ∑_(i=1)N xi²] RMS is useful for vibration, current and signal energy-like measurements. It has the same units as xi. Peak-to-peak value: xpp = max(xi) − min(xi) Range: The peak-to-peak value measures spread between observed extremes but is sensitive to outliers. Zero-crossing rate: The number of sign changes in a window, often useful for classifying vibration or audio, provided the signal is appropriately centred and noise is controlled. Frequency-domain featuresThe discrete Fourier transform (DFT) represents a finite window as frequency components. For N samples, a common definition is: X[k] = ∑_(n=0)^(N−1) x[n]e^(−j2πkn/N) where k indexes frequency bins and j = √(−1). The frequency associated with bin k is fk = kfs/N, for the standard unshifted DFT interpretation. The frequency spacing is therefore ∆f = fs/N. A longer window improves frequency resolution but increases memory, computation and response time. Window functions such as Hann windows reduce spectral leakage when the captured signal does not contain an integer number of cycles. Useful spectral features include dominant frequency, spectral energy in a selected band and spectral centroid. These features are meaningful only when sampling rate, windowing and sensor placement are controlled. Feature engineering principlesFeatures should be selected using both domain knowledge and validation data. Highly correlated features may increase memory and computation without adding information. Features calculated using future samples must not be used in a real-time decision unless the resulting delay is acceptable. Training and test data should be separated by machine, person or time where appropriate; randomly mixing adjacent samples can produce unrealistically high accuracy because nearly identical windows appear in both sets. 5. Anomaly DetectionAn anomaly is an observation that differs materially from an expected operating pattern. It may represent a fault, an unusual but valid state, a sensor error or an environmental change. An anomaly detector is not automatically a fault diagnosis system. Threshold methodsA threshold rule is simple and explainable: Alarm if x > τ where τ is selected from engineering limits, safety requirements or validated historical data. Two-sided limits may be written as |x − μ| > τ. Thresholds should include hysteresis where noise could cause rapid switching. For example, an alarm may activate above a high limit and clear only below a lower limit. Statistical scoringA standardized score is: z = (x − μ)/σ Large absolute values can indicate unusual observations if the baseline distribution is reasonably stable and approximately represented by its mean and standard deviation. A robust alternative uses the median and median absolute deviation (MAD), which is less sensitive to outliers. Statistical thresholds must be calibrated to the cost of false positives and false negatives rather than copied from a generic rule. Model-based and machine-learning detectionA model can learn normal behaviour and flag observations with large reconstruction error or low likelihood. Alternatively, a supervised classifier can learn labelled states such as normal, bearing fault and imbalance. Supervised models generally require representative labelled examples, while unsupervised or semi-supervised methods may be useful when faults are rare but normal data is abundant. Performance should be described using a confusion matrix. Important measures include: Accuracy = (TP + TN)/(TP + TN + FP + FN) Precision = TP/(TP + FP) Recall = TP/(TP + FN) Here, TP, TN, FP and FN denote true positives, true negatives, false positives and false negatives. Accuracy can be misleading for rare faults. A detector that labels every observation as normal may achieve high accuracy while having zero recall for the fault class. In safety-related applications, the costs of missed detections and false alarms should be explicitly compared. 6. TinyML Model Development and DeploymentTinyML normally refers to machine learning performed on highly constrained devices. The model-development workflow is: - Define the operational decision and acceptable error.
- Select sensors, sampling rates and window duration.
- Collect data covering users, devices, environments and operating conditions.
- Label data using a documented protocol.
- Split data into training, validation and test sets without leakage.
- Establish a simple baseline, such as a threshold or decision tree.
- Train a compact model.
- Quantize, prune or otherwise optimize it.
- Convert it to an embedded representation.
- Measure accuracy, latency, memory, energy and robustness on target hardware.
- Deploy with versioning, monitoring and a rollback plan.
Suitable model families- Decision trees: Compact and interpretable for tabular features.
- Linear and logistic models: Efficient where relationships are approximately linear.
- Small multilayer perceptrons: Useful for feature vectors with moderate non-linearity.
- Convolutional neural networks: Effective for local patterns in images, spectrograms or sensor windows, but potentially more demanding.
- One-dimensional convolutional models: Suitable for temporal sensor signals.
- Autoencoders: Can learn a representation of normal data for reconstruction-based detection.
The smallest model is not necessarily the best model. A slightly larger model may reduce false alarms enough to lower total energy use by preventing unnecessary communication or maintenance. The correct objective is system-level performance. QuantizationQuantization represents parameters or activations with fewer bits. In 8-bit integer inference, a real value is commonly mapped using a scale and zero-point: q = round(r/S) + Z where r is a real value, q is the quantized integer, S is a positive scale and Z is the zero-point. Dequantization is approximately r = S(q − Z). The exact supported range depends on the implementation. Quantization reduces memory and can accelerate inference on hardware with integer instructions, but it may reduce accuracy, especially when feature ranges are poorly calibrated. Quantization-aware training or representative calibration data can reduce this loss. Memory and latencyA deployment budget includes: - Program flash for code and model parameters.
- Static RAM for buffers, activations and operating data.
- Stack and heap requirements.
- Temporary memory used by preprocessing.
- Time for sampling, feature extraction, inference and communication.
The device must complete processing within the required deadline. If a window lasts Tw and inference plus preprocessing takes Tp, real-time operation generally requires Tp ≤ Tw for a non-overlapping pipeline. With overlapping windows, the computational deadline is determined by the interval between consecutive decisions, not merely the window length. Energy per operation depends on hardware and implementation. A useful measurement is: E = VIt where E is energy in joules, V is voltage in volts, I is current in amperes and t is time in seconds, assuming approximately constant voltage and current. For varying current, energy is obtained by integrating power over time: E = ∫V(t)I(t)dt. Measurements should include sensor, processor, memory and radio activity rather than inference alone. 7. Evaluation Beyond AccuracyA professional evaluation reports multiple dimensions: | Dimension | Questions |
|---|
| Accuracy | Does the model generalize to unseen devices and conditions? | | Latency | Does it respond before the required deadline? | | Memory | Does peak RAM and flash usage fit the device? | | Energy | How does inference affect battery life? | | Robustness | What happens with noise, drift, missing samples or sensor replacement? | | Fairness and bias | Does performance vary across relevant people, locations or operating conditions? | | Privacy | Are raw or identifiable data retained or transmitted? | | Explainability | Can an operator understand and challenge a decision? | | Maintainability | Can models be updated securely and safely? |
A model should be tested under distribution shift. For example, a vibration model trained on one machine may perform poorly on another machine with different mounting, load or mechanical structure. Test sets should include realistic environmental variation and edge cases. Bias and fairnessBias can arise from unbalanced data, sensor placement, unequal data quality, proxy variables or labels created under inconsistent conditions. A model may show high overall accuracy while systematically underperforming for a particular group or operating regime. Evaluation should report subgroup metrics where legally and ethically appropriate, investigate causes and avoid using sensitive data without a legitimate purpose. Privacy and securityEdge processing can reduce privacy risk but does not guarantee privacy. Devices may still store raw data, expose model outputs or be physically captured. Good practice includes data minimization, encryption in transit and at rest, secure boot, signed firmware, access control, key protection and authenticated model updates. A model update is a supply-chain event and should be versioned, tested and auditable. ExplainabilityA threshold can usually be explained directly. A neural network may require feature attribution, saliency methods, prototype examples or counterfactual analysis. Explanations should be treated as aids to investigation, not proof that the model is correct. If an output affects safety, employment, health or access to services, human review and an escalation procedure may be required. 8. Illustrative Case: Edge-Based Motor Condition MonitoringBackgroundA small manufacturing cell uses a three-axis accelerometer attached to an induction motor. The existing system sends continuous vibration data to a cloud server. This causes network congestion and cannot reliably detect faults during connectivity interruptions. ProblemThe plant wants early detection of imbalance and bearing degradation. A missed fault can cause production loss, while excessive false alarms cause unnecessary inspection. The device is battery-powered during temporary deployments and has limited RAM. AnalysisEngineers first characterize the motor’s normal vibration under several loads and speeds. Sampling frequency is chosen to capture the relevant vibration band, with analogue anti-aliasing before digitization. The device forms overlapping windows, applies calibration and extracts RMS, variance, peak-to-peak value and selected spectral-band energies. A threshold baseline is developed first. It is transparent and provides a reference against which a machine-learning model can be judged. A compact classifier is then trained using data from multiple motors, operators and loads. The test set contains complete operating sessions from motors not used in training, avoiding leakage between neighbouring windows. Approach and solutionThe deployed pipeline is: Accelerometer → calibration → low-pass and band-pass processing → feature extraction → 8-bit classifier → persistence rule → local indicator and event message The persistence rule requires abnormal predictions in several consecutive windows before an alarm is raised. This reduces one-window false positives. The device transmits the event type, confidence, timestamp, selected features and firmware/model version rather than continuous raw vibration. Before deployment, engineers measure peak RAM, flash use, inference time and current in sleep, sampling, inference and radio modes. They also test missing samples, sensor orientation changes, motor speed variation and communication loss. OutcomeThe edge design continues to generate alerts during network outages and greatly reduces transmitted data. The cloud receives event summaries for fleet analysis. The system is not treated as an autonomous maintenance authority: an alert schedules inspection, and a qualified technician confirms the mechanical condition. Learning points- A simple baseline is essential for judging whether TinyML adds value.
- Data collection must represent operating diversity, not merely produce many windows.
- Latency, energy and memory are acceptance criteria, not afterthoughts.
- Persistence logic and human inspection can make a classifier safer.
- Model and firmware versions must accompany event records for traceability.
9. Best Practices and LimitationsBegin with the physical decision, not with a preferred neural-network architecture. Measure the signal and identify what information is genuinely needed. Use the lowest adequate sampling rate and model complexity. Preserve raw data temporarily during development for debugging, but apply retention limits in production. Keep preprocessing identical between training and deployment. Test on target hardware, because desktop performance does not predict microcontroller performance. Important limitations remain. Sensor drift can invalidate a model. A model trained on normal conditions may interpret a new but safe condition as a fault. Quantization can change decision boundaries. Firmware bugs can affect both data collection and inference. Adversaries may inject sensor values, replay observations or extract model information. Cloud retraining can also introduce silent changes unless governance controls are in place. For higher-risk applications, use defence in depth: independent physical limits, watchdogs, safe actuator states, redundant sensing where justified, secure updates, event logging and human escalation. Machine learning should not conceal a failure of basic engineering controls. Contemporary DevelopmentsCurrent edge-AI development includes hardware accelerators for integer inference, neural processing units in embedded systems, federated learning, continual adaptation, event-based sensing and TinyML for audio, gesture and industrial monitoring. These developments create opportunities but also raise new questions: Can a model update be verified on a device? How can local learning avoid catastrophic forgetting? How should a fleet detect that its data distribution has changed? How can privacy-preserving learning be audited when raw data is unavailable? A responsible development process treats these as engineering and governance questions, not merely model-accuracy questions. Chapter SummaryEdge analytics moves appropriate computation from centralized services toward sensors, gateways and local servers. Its benefits include lower latency, reduced bandwidth, improved resilience and potentially stronger privacy. A complete pipeline includes calibration, filtering, windowing, feature extraction, inference, decision logic and monitoring. Moving averages and exponential filters provide practical noise reduction, while time-domain and frequency-domain features summarize sensor behaviour. Anomaly detection may use thresholds, statistical scores or trained models. Accuracy must be interpreted through precision, recall, false alarms and missed detections, particularly for rare faults. TinyML deployment requires model selection, representative data, leakage-free evaluation, quantization and target-hardware testing. Memory, latency and energy are as important as predictive accuracy. Bias, privacy, security and explainability must be assessed because intelligent devices influence people and physical systems. The most reliable design combines machine learning with engineering limits, secure operation, human oversight and explicit maintenance procedures. Key TermsEdge analytics: Processing and interpreting data near its source. TinyML: Machine learning inference on highly resource-constrained devices. Sampling frequency: Number of measurements acquired per second. Aliasing: Misrepresentation of signal frequencies caused by inadequate sampling. Calibration: Conversion of sensor output into a more accurate physical quantity. Windowing: Dividing a continuous signal into finite segments for analysis. Moving average: Filter that averages samples over a defined window. Exponential moving average: Recursive filter weighted toward recent observations. Feature extraction: Conversion of raw data into informative numerical descriptors. RMS: Root mean square magnitude of a signal over a window. DFT: Discrete Fourier transform, which represents finite samples by frequency components. Anomaly: Observation or behaviour that differs from an expected pattern. Precision: Fraction of predicted positives that are actually positive. Recall: Fraction of actual positives that are detected. Quantization: Representation of numerical values using a smaller or discrete numerical format. Inference: Applying a trained model to new data. Data leakage: Unintended use of information from evaluation data during training. Distribution shift: Change between the data used for development and deployment data. Explainability: Ability to provide understandable reasons or evidence for a model output. Model drift: Decline in performance as operating conditions or data patterns change. Review QuestionsShort Answer Questions- State three reasons why IoT analytics may be performed at the edge.
- What is the purpose of an anti-aliasing filter?
- Distinguish precision from recall.
- Why must training normalization values be retained for deployment?
- Name four resource or quality measures that should be evaluated in addition to accuracy.
Long Answer Questions- Explain a complete edge-analytics pipeline from sensing to actuation, including the purpose of each stage.
- Compare moving-average and exponential moving-average filters, including their memory, responsiveness and delay characteristics.
- Describe a responsible TinyML development workflow from data collection to secure deployment.
- Explain how data leakage can occur in time-series sensor projects and how it can be prevented.
- Discuss privacy, bias, security and explainability concerns in intelligent IoT devices.
Analytical / Application Questions- Design an edge pipeline for detecting abnormal vibration in a motor. Specify sampling considerations, windowing, features, decision logic and evaluation metrics.
- A device has a 2-second analysis window and produces a decision every 0.5 seconds. Explain the implications of overlap for memory, computation, latency and correlated test samples.
- A classifier has high overall accuracy but low recall for faults occurring under high temperature. Analyse possible causes and propose data, model and deployment changes.
Multiple Choice Questions with AnswersQuestion 1Which activity is most characteristic of edge analytics? A. Sending every raw sample to a remote server before any decision B. Processing sensor data near the device and transmitting selected results C. Replacing all sensors with cloud databases D. Disabling local decision logic during network failure Correct Answer: B. Processing sensor data near the device and transmitting selected results Question 2If a sensor samples at 1,000 Hz, what is the sampling interval? A. 0.001 seconds B. 0.01 seconds C. 0.1 seconds D. 1 second Correct Answer: A. 0.001 seconds Question 3What is a principal disadvantage of increasing the window length of a moving-average filter? A. It always increases high-frequency noise B. It eliminates the need for calibration C. It can increase delay and hide short events D. It guarantees higher classification accuracy Correct Answer: C. It can increase delay and hide short events Question 4Which metric is TP divided by TP plus FN? A. Accuracy B. Precision C. Specificity D. Recall Correct Answer: D. Recall Question 5Why is a random split of adjacent time-series windows potentially misleading? A. It prevents all feature extraction B. Nearly identical windows may appear in both training and test sets C. It converts integer data into floating-point data D. It guarantees too few training samples Correct Answer: B. Nearly identical windows may appear in both training and test sets Question 6What is a major benefit of 8-bit quantization in TinyML? A. It guarantees no loss of accuracy B. It removes the need for test data C. It can reduce memory use and accelerate suitable hardware D. It eliminates sensor noise Correct Answer: C. It can reduce memory use and accelerate suitable hardware Question 7Which measurement is needed to evaluate energy used during a constant-current inference period? A. Voltage, current and time B. Sampling frequency only C. Model accuracy and recall only D. Window length without hardware measurements Correct Answer: A. Voltage, current and time Question 8For a rare-fault detection problem, why can accuracy be misleading? A. Accuracy cannot be calculated for binary models B. A model can label almost everything normal and still appear highly accurate C. Accuracy always equals recall D. Accuracy measures only memory use Correct Answer: B. A model can label almost everything normal and still appear highly accurate Question 9Which practice best supports privacy in an edge audio application? A. Transmit all raw recordings indefinitely B. Store identifiable recordings without access controls C. Process locally and transmit only necessary event summaries D. Disable firmware authentication Correct Answer: C. Process locally and transmit only necessary event summaries Question 10What is the purpose of a persistence rule in an anomaly detector? A. To require repeated abnormal evidence before raising an alarm B. To increase the sensor sampling frequency automatically C. To remove all model features D. To guarantee that every anomaly is a mechanical fault Correct Answer: A. To require repeated abnormal evidence before raising an alarm
|