Lecture 2 - Part 2

Contents

Sensor Data

The form and the nature of data provided by sensors differ based on their type. A few data formats that are commonly encountered in Edge AI applications are as follows:

Time Series

  1. Time series data represents how a variables of interest changes over time. A single sensor can produce multiple time-series data streams. For instance consider an environmental sensor (e.g. BME680) it may provides measurement for temperature, humidity, pressure, and gas levels.
  2. Typically, time series data is collected by polling the sensors with a certain frequency. Ironically, this frequency is also called sampling frequency and the rate of polling, i.e. number of samples collected per second is known as sampling rate.
  3. Note that this sampling rate is not same as the sampling rate we discussed in A/D conversion. Key differences have been articulated in table below.
  4. Some time series are aperiodic, meaning samples are not taken at fixed intervals. This occurs with sensors that respond to specific events, such as a proximity sensor that triggers when an object enters a defined range. In such cases, it is common to record the exact timestamp along with the sensor reading.
  5. Time series can also represent aggregated information, such as the number of occurrences of an event within a given time interval.

Key Differences: Time Series Sampling vs Physical Signal Sampling

AspectPhysical Signal Sampling (ADC)Time Series Sampling (Digital)
DomainContinuous-time, continuous-amplitudeDiscrete-time, already digital
PurposeConvert real-world signal to digitalReduce, resample, or analyze data
Sampling ConstraintMust satisfy Nyquist criterionNo strict Nyquist limit
Data SourceSensor measuring physical quantitiesPre-recorded or generated digital data
Sampling RateDetermined by highest frequency in signalDetermined by analysis or polling requirements
ExamplesMicrophone recording sound at 44.1 kHzStock prices sampled daily or hourly
Event HandlingTypically continuous measurementCan be periodic or aperiodic (event-driven)
ToolsSensor + ADC hardwareSoftware or algorithms

Signal Modality

Audio Signals

An audio signal captures oscillation of sound waves traveling in a certain medium (air, water, vacuum, etc.). Audio signals are also example of time series data. Audio signals capture changes in air pressure over time. Generally, audio signals are sampled with very high frequency. The upper limits to human hearing are around 20 kHz. Consequently, from Nyquist Theorem, audio signals must be captured at twice the rate, i.e., 40 kHz. With each sample, using ADC N=8N=8, we have 320Kbps. The Ultrasonic signals which can be used to measure density of liquid or other liquid properties go beyond this audible range. Audio signals can also yield multiple time series, specially for stereo audio. However, for sake of simplicity, let us restrict ourselves to mono-audio. Then the discrete-time audio signal can be represented as a column vector:

x=[x[0]x[1]x[2]x[N1]]\mathbf{x} = \begin{bmatrix} x[0] \\ x[1] \\ x[2] \\ \vdots \\ x[N-1] \end{bmatrix}

where:

  • x\mathbf{x} is the vector of audio samples,
  • x[n]x[n] is the amplitude of the nn-th sample,
  • NN is the total number of samples.

Image Signals

An image sensor is a device that captures light from a scene and converts it into electrical signals. Common types include CCD (Charge-Coupled Device) and CMOS (Complementary Metal-Oxide-Semiconductor). The sensor consists of a 2D array of photosensitive elements called pixels, where each pixel measures the intensity of light hitting it and converts it into a digital value. The digital output of an image sensor can be represented as a matrix where each element corresponds to a pixel value. For a grayscale image, the matrix is written as:

I=[I[0,0]I[0,1]I[0,N1]I[1,0]I[1,1]I[1,N1]I[M1,0]I[M1,1]I[M1,N1]]I = \begin{bmatrix} I[0,0] & I[0,1] & \cdots & I[0,N-1] \\ I[1,0] & I[1,1] & \cdots & I[1,N-1] \\ \vdots & \vdots & \ddots & \vdots \\ I[M-1,0] & I[M-1,1] & \cdots & I[M-1,N-1] \end{bmatrix}

where I[m,n]I[m,n] is the intensity of the pixel at row mm and column nn, MM is the number of rows, and NN is the number of columns. For color images, each pixel contains multiple components (e.g., RGB), so the image can be represented as a 3D array I[m,n,c]I[m,n,c] where c{R,G,B}c \in \{R, G, B\}.Similarly, Radio detection and ranging (radar) and LiDAR systems generate spatial imaging data, which can also be represented as matrices or 3D arrays, where each element corresponds to a measured intensity, distance, or reflectivity value at a specific spatial location.

The image will be available in Python as window.imgData.

Image Channels

Loading editor...
No output yet. Click "Run Python" to execute.

video

The Video data is essentially a collection of images sampled at what is known as frame rate. Videos can be encoded through efficient encoding scheme to reduce the storage size. Such encoding schemes also utilise temporal variations across the frames.

Types of Sensors

CategoryWhat it doesExample
Acoustic & Vibration

• Measure vibrations traveling through a medium

  • air (microphones)
  • water (hydrophones)
  • ground (geophones and seismometers)
    • Provides a time series describing the variation of pressure
    • Acoustic signals contain info across frequencies
    • High-frequency signals require high sample rates

Shure SM58 Microphone

Geosense GS-11VT Seismometer

Visual and Scene

• Capture light using sensor arrays
• Color channels: grayscale or RGB
• Spectral response: visible and infrared
• Pixel size: larger = more sensitive
• Sensor resolution: more elements = finer detail
• Frame rate: captures images per second

Sony IMX586 Image Sensor

FLIR Lepton Thermal Camera

Motion and Position

• Tilt sensor: detects orientation
• Accelerometer: measures acceleration
• Gyroscope: measures rotation
• Time of Flight: measures distance via EM emission
• IMU: combines sensors to find position
• GPS: uses satellites to locate device

Tilt Ball Switch ADXL345

MPU-6050 VL53L0X

BNO055

u-blox NEO-6M

Force and Tactile

• Button & Switch: binary signal
• Capacitive Touch: detects touch
• Strain & Flex: measures deformation
• Load Cells: measure applied load
• Pressure Sensors: gas/liquid pressure
• Flow Sensors: rate of flow

CherryMX

MPR121 (NXP) Flex Sensor

TAL220B

BMP280

Honeywell AWM1700

Environmental & Others

• Temperature
• Particulate Matter
• Gas concentrations
• Photo sensor: detects light
• Bio signals: heart, brain, etc.
• Chemical: measures specific chemicals

DS18B20

PMS5003

MQ-135

TSL2561

AD8232

Atlas Scientific pH Sensor

Regression in Time-Series Analysis

Having sampled the time-series data, we want to develop some basic understanding of physical phenomenon. Regression is a statistical method used to model the relationship between a dependent variable and one or more independent variables. In time-series analysis, regression can help us understand trends, make predictions, and quantify the influence of time or other factors on a variable.

Example:
We have daily temperature measurements over a month. We want to model the trend of temperature over time and potentially predict future values.

Time-Series Data

Suppose we have:

DayTemperature (°C)
115
216
316.5
......
3021
  • Independent variable xx: Day number (1 to 30)
  • Dependent variable yy: Temperature

We want a simple regression:

y=β0+β1x+ϵy = \beta_0 + \beta_1 x + \epsilon

Where:

  • β0\beta_0 = intercept (temperature at day 0)
  • β1\beta_1 = slope (rate of change of temperature per day)
  • ϵ\epsilon = error term

Least Squares Regression

Goal: Find β0\beta_0 and β1\beta_1 that minimize the sum of squared errors:

S(β0,β1)=i=1n(yi(β0+β1xi))2S(\beta_0, \beta_1) = \sum_{i=1}^{n} \big(y_i - (\beta_0 + \beta_1 x_i)\big)^2

This is called Ordinary Least Squares (OLS).

The closed-form solution for simple linear regression:

β1=(xixˉ)(yiyˉ)(xixˉ)2,β0=yˉβ1xˉ\beta_1 = \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sum (x_i - \bar{x})^2}, \quad \beta_0 = \bar{y} - \beta_1 \bar{x}

Where xˉ\bar{x} and yˉ\bar{y} are the sample means.

Solution Approach

To find the minimum, take derivatives with respect to β0\beta_0 and β1\beta_1 and set them to zero:

Sβ0=2i=1n(yiβ0β1xi)=0\frac{\partial S}{\partial \beta_0} = -2 \sum_{i=1}^n \big(y_i - \beta_0 - \beta_1 x_i\big) = 0 Sβ1=2i=1nxi(yiβ0β1xi)=0\frac{\partial S}{\partial \beta_1} = -2 \sum_{i=1}^n x_i \big(y_i - \beta_0 - \beta_1 x_i\big) = 0

Normal Equations

Simplifying the derivatives gives the normal equations:

{nβ0+(xi)β1=yi(xi)β0+(xi2)β1=xiyi\begin{cases} n \beta_0 + (\sum x_i)\beta_1 = \sum y_i \\ (\sum x_i)\beta_0 + (\sum x_i^2)\beta_1 = \sum x_i y_i \end{cases}

Solve for Slope β1\beta_1 by defining the means:

xˉ=1nxi,yˉ=1nyi\bar{x} = \frac{1}{n} \sum x_i, \quad \bar{y} = \frac{1}{n} \sum y_i

Then the slope is:

β1=i=1n(xixˉ)(yiyˉ)i=1n(xixˉ)2\beta_1 = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2}

Once β1\beta_1 is known, the intercept is:

β0=yˉβ1xˉ\beta_0 = \bar{y} - \beta_1 \bar{x} β1=i=1n(xixˉ)(yiyˉ)i=1n(xixˉ)2,β0=yˉβ1xˉ\boxed{ \beta_1 = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2}, \quad \beta_0 = \bar{y} - \beta_1 \bar{x} }

Types of Regression

Regression is a statistical technique used to model the relationship between a dependent variable (y) and one or more independent variables (x).


1. Linear Regression

  • Models the relationship as a straight line:
y=β0+β1x+ϵy = \beta_0 + \beta_1 x + \epsilon
  • Goal: Find coefficients β0,β1\beta_0, \beta_1 that minimize the error.
  • Can be simple (one predictor) or multiple (many predictors).
y=β0+β1x1+β2x2++βpxp+ϵy = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \dots + \beta_p x_p + \epsilon

2. Polynomial Regression

  • Models the relationship using polynomials of degree nn:
y=β0+β1x+β2x2++βnxn+ϵy = \beta_0 + \beta_1 x + \beta_2 x^2 + \dots + \beta_n x^n + \epsilon
  • Captures non-linear trends.
  • Still solved with least squares.
  • Imagine a solar panel on your roof. Early in the morning, with just a little sunlight, it barely produces any power. As the sun rises, output grows faster and faster, but after a point it starts to level off. The pattern isn’t a straight line, it curves

3. Logistic Regression

  • Used when the dependent variable is categorical (binary):
P(y=1x)=11+e(β0+β1x)P(y=1|x) = \frac{1}{1 + e^{-(\beta_0 + \beta_1 x)}}
  • Models probabilities, not continuous outcomes.

Conclusion

Regression

Time-series Processing

A/D Acquisition

optional

optional

optional

training

inference

Sensor (analog)

Analog-to-Digital Converter
(A/D sampling)

Acquired Samples
(time-series buffer)

Pre-processing

Feature Extraction / Windowing

Regression Model

Output: Prediction / Trend / Alert

Filtering (low-pass / detrend)

Resampling / Interpolation

Normalization / Scaling

Fit coefficients (least squares)