Phillip Stanley-Marbell
Foundations of
Embedded Systems
Physical Constraints, Sensor Uncertainty, Error Propagation,
Low-Level C on RISC-V, and Open-Source FPGA Tools
Draft Version of Michaelmas 2020
13
How Physics Constrains Sensor Data
in Embedded Systems
Figure 13.1: Because not all
sequences of measurand
values are physically
plausible, not all sequences
of sensor readings are
physically plausible.
When you know . . . that some symbols represent
forces, others masses, inertia, and so on, then you
can use a lot of commonsense, seat-of-the-pants feeling
about the world. But the poor mathematician translates
it into equations, and as the symbols do not mean
anything to him he has no guide but precise mathematical
rigor and care in the argument . . . But one should not
criticize the mathematician on this score.
—Richard Feynman, The Character of Physical Law,
MIT Press, 1965.
Table 13.1: Concepts.
Concept
Physical plausibility § 13.2.
Generalized coordinates §
13.3.
Generalized velocity §
13.3.
Generalized momentum §
13.3.
Function §
13.3.
Functional §
13.3.
Extremality §
13.3.
Lagrangians §
13.3.
Equations of motion §
13.4.
Euler-Lagrange §
13.5.
Noether’s theorem §
13.6.
Coordinate systems are central to how we describe physical systems. An
object at a given coordinate in a coordinate space may have additional prop-
erties such as mass, temperature, and so on. Figure
13.2 illustrates an object
(the red cube) within a three dimensional Cartesian coordinate space. As
such an object moves, its Cartesian coordinates change. But other properties
of the object such as its temperature may also be changing at the same time.
We will refer to the set of all measurable properties of interest for an object as
2 phillip stanley-marbell
its generalized coordinates. In this course, we will implicitly always assume the
components of a generalized coordinate correspond to sensor readings. Thus,
for example, for object in Figure
13.2 we might have a GPS together with a
temperature sensor inside the depicted red box, so the generalized coordi-
nates of interest will be tuples of {latitude, longi tude, elevation, temperature}.
Given this set of generalized coordinates, an example generalized path through
the coordinate space might be:
1 ...
2 52.2 deg, 0.103 deg, 0 m, 20 C
3 52.2 deg, 0.101 deg, 1 m, 15 C
4 52.2 deg, 0.098 deg, 2 m, 15 C
5 52.2 deg, 0.098 deg, 1 m, 15 C
6 52.2 deg, 0.097 deg, 1 m, 15 C
7 52.2 deg, 0.096 deg, 1 m, 15 C
8 52.2 deg, 0.098 deg, 2 m, 15 C
9 52.2 deg, 0.090 deg, 3 m, 17 C
10 52.2 deg, 0.090 deg, 4 m, 19 C
11 52.2 deg, 0.089 deg, 0 m, 19 C
12 ...
z
x
y
Figure 13.2: An object de-
picted at a location within
a Cartesian coordinate
space may have additional
properties such as a given
mass, temperature, and so
on.
We can treat any set of sensors as a generalized coordinate space. For
example, for the SensorTag system described in Chapter
11, the generalized
coordinate space is 15-dimensional with dimensions:
{θ, a
x
, a
y
, a
z
, g
x
, g
y
, g
z
, m
x
, m
y
, m
z
, h, p, l, M, spl},
corresponding to sensors for temperature, 3-axis acceleration, 3-axis angular
rate, 3-axis magnetic flux, humidity, atmospheric pressure, ambient light,
magnet presence, and sound pressure level.
Let n be the number of sensors in a system and let c be the set of sensors for
the measurands we are interested in. We will refer to c as a configuration. For
example, for a system capable of measuring acceleration in x-, y-, and z-axes,
n = 3 and the configuration is x-, y-, and z-acceleration. We will refer to the
set of possible configurations as the configuration space. Some sensors making
up a configuration may provide redundant information. We will refer to the
smallest number of sensors that are needed to recreate a given configuration
as the dimension or degrees of freedom of the configuration space.
Let r(t) denote a sequence of measurand values
1
for a set of n sensors. We
1
Note that we are talking
about measurand values.
Measured sensor readings,
in contrast to the true value
of the measurand, could
take on any value as a
sensor may be noisy or
even faulty.
will refer to the set of possible measurand values as the coordinate space and
to a particular sequence of points (r (t)) in the coordinate space as a path in
the coordinate space. Given a path through a coordinate space, we will refer
to the rate of change of coordinates along the path as the generalized velocity.
For a given set of sensors, not all forms of r(t) are physically realizable, that
is, not sequences n-tuples of measurand values are physically possible.
This chapter introduces a conceptual tools and analytic techniques for rea-
soning about which sequences of measurand values are physically possible.
foundations of embedded systems 3
The methods we discuss in this chapter will apply to systems without dissi-
pation, which obey conservation laws. The presentation in this chapter will
follow closely the derivations given by Feynman
2
and the terminology and
2
Feynman and Wilczek
2017; Feynman, Leighton,
and Sands
2011.
notation used by Sussman and Wisdom.
3
3
Sussman and Wisdom
2015.
13.1 Intended Learning Outcomes
By the end of this chapter, you should be able to:
1. Define generalized coordinates for a system.
2. Define generalized velocity for a system.
3. Define the action and Lagrangian for a system.
4. Derive equations of motion for a system defined in terms of generalized
coordinates from first-principles or using the Euler-Lagrange equations.
5. Apply the concept of generalized coordinate, generalized velocities and
momenta, equations of motion, and conservation laws, to the measurand
values for an embedded sensor-driven system.
13.1.1 Learning outcomes pre-assessment
Complete the following
quiz to evaluate your prior knowledge of the material
for this chapter.
13.1.2 Things to think about
Complete the following
thinking exercise to stimulate your thoughts about
the contents of this chapter before proceeding with the material.
13.1.3 Things to look out for
Concepts people sometimes get confused by in this chapter include:
1. Why the ideas in this chapter are directly applicable to all embedded sens-
ing systems.
13.1.4 The muddiest point
As you go through the material in this chapter, think about the following two
questions and note your responses for yourself or using the annotation tools
of the online version of the chapter. You will have the opportunity to submit
your responses to these questions at the end of the chapter:
1. What is least clear to you in this chapter? (You can simply list the section
numbers or write a few words.)
4 phillip stanley-marbell
2. What is most clear to you in this chapter? (You can simply list the section
numbers or write a few words.)
13.2 Example
Let’s consider the case where an embedded sensor system is measuring 3-
axis acceleration inside a ball (or a projectile). Figure
13.3 shows the behavior
we expect if we were to measure the elevation and vertical velocity of the ball
as a function of time.
time
time
y-velocity height, h(t)
Figure 13.3: Height and
vertical velocity of bounc-
ing ball as a function of
time.
For this example, one example of a sequence of x-, y-, and z-acceleration
values (in gs) measured for an actual ball at 100 Hz sampling rate, is:
1 ...
2 -1.0 0.1 0.2
3 -1.0 0.0 0.2
4 -0.9 0.0 0.2
5 -0.9 0.0 0.2
6 -1.0 0.0 0.2
7 -1.0 -0.1 0.1
8 -1.0 -0.1 0.1
9 -1.0 -0.2 0.0
10 -0.9 -0.2 -0.1
11 -0.9 -0.3 -0.2
12 -0.8 -0.2 -0.2
13 -0.9 -0.3 -0.3
14 ...
Figure
13.4 shows two plots of timeseries data for the ball under two differ-
ent scenarios. Given any such sequence of sensor readings, it would be useful
to be able to know which sequences of measurand values are possible based
on the laws of physics and conditions on this planet, and which sequences of
sensor measurand values are not feasible. Such information would allow us,
for example, to determine whether a sensor is malfunctioning: If the sensor
readings imply a measurand that is not obeying the laws of physics, chances
are that our sensor is malfunctioning or that our interpretation of the data
from the sensor is incorrect. In this example, we expect certain relations be-
tween the x -, y-, and z-acceleration values. As we will see in this chapter, we
can generalize the question of what is physically possible for measurand values
beyond mechanical systems to any collection of measurands. To do this, we
will treat a set of measurands as generalized coordinates.
13.3 Feasible Paths in a Generalized Coordinate Space
For a given set of generalized coordinates, the generalized velocity is the rate of
movement between points in the generalized coordinate space. The general-
ized velocity therefore represents the rate of change of the set of measurands
relevant to a given system. Similarly, we can define the generalized momentum
foundations of embedded systems 5
(a)
(b)
Figure 13.4: 3-axis ac-
celerometer data from a
ball (a) thrown in the air
and (b) being repeatedly
bounced off the floor. We
will refer to the true values
of the measurands cor-
responding to each such
sequence of readings as
a path, r(t), through the
generalized coordinate
space.
for a system in a given generalized coordinate space in terms of its config-
uration independent of coordinate location and in terms of its generalized
velocity. For such a system the kinetic energy will depend on the generalized
velocity and configuration and the potential energy will depend only on the
configuration.
Let K(t) be the generalized kinetic energy for a system whose generalized
coordinates are defined by a set of measurands and let U(t) be its generalized
potential energy, both as functions of time. It turns out that the only valid
sequences of measurand values will be those that obey the property that for
some path r(t ) through the generalized coordinate space
S =
Z
r
[
K(t) U(t)
]
dt (13.1)
=
Z
t
2
t
1
[
K(t) U(t)
]
dt.
is stationary (i.e., a minimum, maximum, or saddle point). The quantity S is
called the action.
The action, S, is an example of what is formally known as a functional: a
mapping from functions to real values. When, given some input function,
a functional is stationary, the functional is said to be extremal. For a given
6 phillip stanley-marbell
functional, the input function which make the functional extremal is called
the Lagrangian of the functional. For our functional of interest, the action S,
Equation
13.1 says that the Lagrangian, L(t, r,
dr
dt
)
4
, is the difference between
4
We will also write the
Lagrangian as L(t, r, ˙r).
the kinetic energy K(t) and the potential energy U(t).
But what does it mean for the functional to be stationary? Unlike station-
ary points such as maxima or minima of a function, stationary points for a
functional are themselves functions (e.g., of time). To illustrate, of the three
sets of 3-axis accelerometer data below all have the same starting and ending
points in the generalized coordinate space. Only one of the three is actually
taken from the same physical system as in the example of Section
13.2. Over
each of these three paths through the generalized coordinate space, the action
S of the system of Section 13.2 will be smallest for the one of the three paths
that is physically feasible for that example system:
1 /
*
Sequence 1
*
/
2
3 0.1 0.5 -0.1
4 ...
5 0.4 0.7 -0.1
6 0.5 0.7 -0.2
7 0.6 0.8 -0.2
8 0.6 0.8 -0.2
9 0.9 0.5 -0.1
10 0.6 0.7 -0.3
1 /
*
Sequence 2
*
/
2
3 1.1 1.5 -0.1
4 ...
5 1.4 0.7 -0.1
6 1.5 0.7 -0.2
7 0.6 0.8 -0.2
8 0.6 1.8 -0.2
9 -0.9 0.5 -0.7
10 0.6 0.7 -0.3
1 /
*
Sequence 3
*
/
2
3 0.1 0.5 -0.1
4 ...
5 0.4 0.7 -0.1
6 0.5 0.7 -0.2
7 0.6 0.8 -0.2
8 0.6 0.8 -0.2
9 0.9 0.5 -0.1
10 0.6 0.7 -0.3
13.4 Deriving Equations of Motion from the Action
Given the generalized coordinates of a system, we’ve seen how to define the
Lagrangian (difference between kinetic and potential energy). So, if we could
define the a nalogs of kinetic energy and potential energy for a generalized
coordinate system representing a set of measurands, we could formulate the
Lagrangian for a set of measurands in a sensing system.
We said (so far, without proof) that the action functional S is extremal
(stationary) when applied to the Lagrangian. This gives us a way to deter-
mine the partial differential equations governing how our measurand values
change in time and with respect to each other.
time
height, h(t)
true h(t)
h
1
(t)
h
2
(t)
t
0
t
1
t*
ζ
1
(t*)
Figure 13.5: Height and
vertical velocity of bounc-
ing ball as a function of
time.
Returning to the example of the bouncing ball, let’s restrict ourselves to
looking at the height h(t) of the ball above the ground. Figure
13.5 shows
possible paths of the ball with the same starting and ending positions at
times t
0
and t
1
. Let h
¯
(t) be the true path that the ball takes from starting at
time t
0
and ending at time t
1
and let the difference in height between a path
h
n
(t) and the true path h
¯
(t) be
ζ
n
(t) = h
n
(t) h
¯
(t). (13.2)
foundations of embedded systems 7
Figure
13.5 shows ζ
1
(t
) for the alternative path h
1
(t) at t = t
.
time
height, h(t)
path, h(t), that
minimizes the
functional S
h
1
(t)
t
0
t
1
h
2
(t)
x
f(x)
x
min
x
min
x
x
min
+x
value of x that
minimizes the
function f(x)
Figure 13.6: Stationary
points of functionals and
functions.
Figure 13.6 illustrates how h
¯
(t) minimizes (or maximizes) the action func-
tional S analogous to how a value x
min
minimizes the value of a function
f (x). At the value x
min
that minimizes f (x), small changes x in x lead to
small changes in the function f (x). In the same way, small changes ζ(t) away
from h
¯
(t) lead to small changes in the functional S. Thus, if we knew h
¯
(t),
our value for S would not change much if we only added small powers of
derivatives of ζ(t) to it before applying the functional S
5
.
5
In other words h
¯
(t) +
dζ
dt
would not lead to a value
of the action functional S
that is very different from S
applied to h
¯
(t), but h
¯
(t) +
dζ
dt
2
would lead to a
value of the functional that
is appreciably different.
We can work out what the action functional S is when applied to h(t) =
h
¯
(t) + ζ(t). For the ball system, the kinetic energy is
1
2
m
dh
¯
dt
2
and the
potential energy is mgh
¯
(t). The action,
ˆ
S for the path h(t) = h
¯
(t) + ζ(t) is
therefore:
ˆ
S =
Z
t
1
t
0
1
2
m
dh
¯
dt
+
dζ
dt
!
2
mg
h
¯
(t) + ζ(t)
dt (13.3)
=
Z
t
1
t
0
1
2
m
dh
¯
dt
!
2
+ m
dh
¯
dt
dζ
dt
!
+ m
dζ
dt
2
mg
h
¯
(t) + ζ(t)
dt.
Since, as argued above, low powers of derivatives of ζ(t) make no dif-
ference when added to h
¯
(t), if we keep only the low powers of derivatives
of ζ(t) then
ˆ
S should be very close to S. Our goal now is to rearrange the
expression for
ˆ
S to get it into the form
ˆ
S = S + δS. To help get
ˆ
S into that
form, we take the Taylor series expansion of the potential energy term in
ˆ
S.
We take this Taylor series expansion of potential energy with respect to h
¯
, not
with respect to t. The potential energy term in term in
ˆ
S is
mg
h
¯
(t) + ζ(t)
,
and its Taylor series expansion is
mgh
¯
(t) + mgζ
dh
¯
dh
+ mg
ζ
2
2
d
2
h
¯
dh
2
+ . . .
8 phillip stanley-marbell
Plugging in the Taylor series expansion into the expression for
ˆ
S, we have
ˆ
S =
Z
t
1
t
0
1
2
m
dh
¯
dt
!
2
mgh
¯
(t) + m
dh
¯
dt
dζ
dt
!
mgζ
dh
¯
dh
+ m
dζ
dt
2
mg
ζ
2
2
d
2
h
¯
dh
2
+ . . .
dt.
(13.4)
Dropping the second order and higher terms, we get
ˆ
S =
Z
t
1
t
0
1
2
m
dh
¯
dt
!
2
mgh
¯
(t) + m
dh
¯
dt
dζ
dt
!
mgζ
dh
¯
dh
dt. (13.5)
Since we’ve left out the higher-order terms,
ˆ
S should equal S
¯
, the action for
the true path h
¯
(t). Let δS =
ˆ
S S
¯
be the variation in the action S, that is
δS =
Z
t
1
t
0
"
m
dh
¯
dt
dζ
dt
!
mgζ
dh
¯
dh
#
dt. (13.6)
The quantity δS must equal zero no matter what the deviation ζ(t) from
the true path is. We could guarantee that δS will be zero regardless of ζ(t)
if we could get δS expressed as a product δS = (expression)ζ(t) and if we
could then ensure that (expression) is always zero. The barrier to achieving
this objective with the current form of
ˆ
S is the factor
dζ
dt
in the first term of
Equation
13.6.
We can get around the problem posed by the factor
dζ
dt
in the first term of
Equation
13.6 by using the property of integrating by parts:
d
dt
(g f ) = g
d f
dt
+ f
dg
dt
,
or, after rearranging,
Z
f
dg
dt
dt = g f
Z
g
d f
dt
dt.
If we let f = m
dh
¯
dt
and let g = ζ, and let h
0
and h
1
be the heights of the ball at
the start and end of the path, then we can rewrite Equation
13.6 as
δS = m
dh
¯
dt
ζ(t)
h
1
h
0
Z
h
1
h
0
m
d
2
h
¯
dt
2
ζ(t)dt
Z
h
1
h
0
mgζ(t)
dh
¯
dh
dt. (13.7)
The first term of Equation
13.7 is zero since we have consistently made sure
that we only consider paths that start and end at the same points as the true
path hence ζ(t) is 0 at h
0
and h
1
, by definition. Simplifying, we get
δS =
Z
h
1
h
0
m
d
2
h
¯
dt
2
mg
dh
¯
dh
ζ(t)dt. (13.8)
foundations of embedded systems 9
We now have δS in the form we wanted. For δS to be zero regardless of the
deviation in path ζ(t) we must therefore have
m
d
2
h
¯
dt
2
= mg
dh
¯
dh
. (13.9)
Equation
13.9 is therefore an invariant which much hold for the bouncing
ball system whose action S we defined in terms of the difference between
kinetic and potential energy.
13.5 Euler-Lagrange Equations
Given the Lagrangian L(t, r, ˙r), there is a simpler way than doing the deriva-
tion of Section
13.4 to obtain the differential equations governing the mo-
tion along the path in the generalized coordinate space: The Euler-Lagrange
Equations:
d
dt
L(t, w,
˙
w)
˙
w
i
w=r(t)
˙
w= ˙r (t)
=
L(t, w,
˙
w)
w
i
w=r(t)
˙
w= ˙r (t)
(13.10)
where i = 0, . . . , n 1 are the dimensions of r.
13.6 The Noether Theorem
A given Lagrangian L(t, r, ˙r) might remain unchanged even as we vary t
or as we vary one of the coordinates positions in r. Noether’s theorems
link invariance of the Lagrangian under changes in t or in one or more of
the coordinates in r, to statements about conserved quantities such as the
conservation of energy, conservation of momentum, and so on.
We have so far been discussing the action functional S, which we saw
takes as input a function and outputs a real value. We also saw that the
Lagrangian L(t, r, ˙r) was the function that made the action functional S sta-
tionary or extremal. A fascinating theorem, due to Emmy Noether,
6
links
6
Trautman
1967; Trautman
1962; Noether 1918; Rund
1972; Neuenschwander
2014; Neuenschwander
2017.
properties of functionals and their Lagrangians to properties that are con-
served by the system with a given Lagrangian and corresponding equations
of motion through the generalized coordinate space. Recall that in our con-
text the generalized coordinated are tuples r of measurand values. And, in
our context, motion refers to how these tuples of measurand values change
over time: The system in question need not by physically moving.
Consider a system in which we introduce a small amount ε of noise into
N of the time- and generalized-coordinate values.
10 phillip stanley-marbell
Theorem 1 (Noethers first theorem) If under the transformation
t
= t +
N
i=1
ετ
i
r
= r +
N
i=1
εζ
i
the functional
Γ =
Z
b
a
L(t, r, ˙r)dt
is both invariant and extremal, then the value
C =
L
˙r
ζ
L
˙r
dr
dt
L(t, r, ˙r)
τ
remains constant (i.e., the quantity C is conserved) throughout the motion of the
system through the generalized coordinate space .
foundations of embedded systems 11
13.7 Relevant Books Available in the Moore Library
1. Structure and Interpretation of Classical Mechanics, ISBN: 978-0262028967.
12 phillip stanley-marbell
13.8 The Muddiest Point
Think about the following two questions and submit your responses through
this
link.
1. What was least clear to you in this chapter? (You can simply list the section
numbers or write a few words.)
2. What was most clear to you in this chapter? (You can simply list the
section numbers or write a few words.)
Bibliography
1. Feynman, Richard and Frank Wilczek (2017). The character of physical law.
MIT press (cit. on p.
3).
2. Feynman, Richard P, Robert B Leighton, and Matthew Sands (2011). The
Feynman lectures on physics, Vol. II: Mainly electromagnetism and matter. Vol. 2.
Basic books (cit. on p.
3).
3. Neuenschwander, Dwight E (2014). “Resource letter NTUC-1: Noether’s
theorem in the undergraduate curriculum”. In: American Journal of Physics
82.3, pp. 183188 (cit. on p. 9).
4. Neuenschwander, Dwight E (2017). Emmy Noethers wonderful theorem. JHU
Press (cit. on p.
9).
5. Noether, E (1918). “Invariante Variationsprobleme Nachr. D. König. Gesellsch.
D. Wiss. Zu Göttingen, Math-phys. Klasse 1918: 235-257”. In: English Reprint:
physics/0503066, http://dx. doi. org/10.1080/00411457108231446, p. 57 (cit. on
p.
9).
6. Rund, H (1972). “A direct approach to Noether’s theorem in the calculus
of variations”. In: Utilitas Math 2, pp. 205214 (cit. on p. 9).
7. Sussman, Gerald Jay and Jack Wisdom (2015). Structure and interpretation
of classical mechanics. Mit Press (cit. on p.
3).
8. Trautman, Andrzej (1962). “Conservation laws in general relativity”. In:
Gravitation: An introduction to current research 89, pp. 319336 (cit. on p.
9).
9. Trautman, Andrzej (1967). “Noether equations and conservation laws”. In:
Communications in Mathematical Physics 6.4, pp. 248261. issn: 1432-0916.
doi:
10.1007/BF01646018. url: https://doi.org/10.1007/BF01646018
(cit. on p. 9).
Index
A direct approach to Noethers theorem
in the calculus of variations,
9
Conservation laws in general relativity,
9
Emmy Noethers wonderful theorem, 9
Feynman, Richard, 3
Feynman, Richard P, 3
Invariante Variationsprobleme Nachr.
D. König. Gesellsch. D. Wiss.
Zu Göttingen, Math-phys. Klasse
1918: 235-257,
9
Leighton, Robert B, 3
Neuenschwander, Dwight E, 9
Noether equations and conservation
laws,
9
Noether, E, 9
Resource letter NTUC-1: Noethers the-
orem in the undergraduate cur-
riculum,
9
Rund, H, 9
Sands, Matthew, 3
Structure and interpretation of classical
mechanics,
3
Sussman, Gerald Jay, 3
The character of physical law, 3
The Feynman lectures on physics, Vol.
II: Mainly electromagnetism and
matter,
3
Trautman, Andrzej, 9
Wilczek, Frank, 3
Wisdom, Jack, 3