Computing & Programming with Matlab
2014 S1 Assignment
This assignment requires some programming and plotting activities. The assignment requires some
understanding of the discrete maths implementation of integration and differentiation (which will
be explained)
SCENARIO
:
Your assignment is based around data collected from some kind of sensor measuring 3D
displacement or velocity or acceleration. You are required to convert from one of these kinematic
types to the other types eg: if you are given displacement, then you would be converting to velocity
AND acceleration. If you were given velocity then you would be converting to both acceleration
AND displacement. If you were given acceleration then you would be converting to both velocity
AND displacement
BACKGROUND MATH / PHYSICS
The position vector,
r
(or
s
), the velocity vector,
v
, and the acceleration vector,
a
are expressed
using rectangular coordinates in the following way:
How are these related :
If
r
or
v
or
a
are described by functions then each is either the integral or the differentiation of
another, as below, calculating
v
from the derivative of
r
and
a
from the derivative of
v
.
Conversely, as below,
v
is calculated as the integral of
a
,
r
is calculated as the integral of
v
.
BUT
: in sensor based data, these are not continuous functions but discrete samples and the maths is
completely simplified.
v
i
=
(
r
i
–
r
i
–
1
)
?
t
=
(
r
i
–
r
i
–
1
)
*
samplerate
In the above, the average velocity at a point in time, is the change in position (
?
r
) divided by
the change in time (
?
t
). The change in time is simply the inverse of the samplerate
(eg 1/samplerate). Using matlab, if the displacement samples are loaded in a vector, then to generate
the velocity the vector is subtracted from a one sample shifted copy of itself and the resultant
matlab vector multiplied by the samplerate (eg
?
t
= 1/samplerate and dividing by
?
t
is the
same as multiplying by samplerate.
Eg: for a samplerate of 10 samples / sec
r=[0.15, 0.3, 0.45, 0.61, 0.77, 0.94, 1.1 ]
(metres)
then we assume for the moment that
r
0
is zero and get:
v=[0.15-0, 0.3-0.15, 0.45-0.3, 0.61-0.45, 0.77-0.61, 0.94-0.77, 1.1-0.94]*samplerate
v=[1.5, 1.5, 1.5, 1.6, 1.6, 1.7, 1.6]
BUT: subtracting zero from the first sample can cause the first velocity (or acceleration) calculation
to be anomalous. It is better to generate the differences between each pair of samples and the
resultant data set will be one sample shorter than the source data.
To calculate the integral requires the summing of successive samples and multiplying by
?
t
(or
divide by the samplerate)
r
i
=
?
1
i
(
v
n
?
t
)
=
?
1
i
v
n
samplerate
for example, if the velocity vector was:
v=[ 1.5, 1.5, 1.5, 1.6, 1.6, 1.7, 1.6 ]
then
r=[1.5, 3.0, 4.5, 6.1, 7.7, 9.4, 11 ] /samplerate.





