Electrical and Computer Engineering
Electrical and Computer Engineering
The first three chapters of this book provide a fairly complete coverage of
complex numbers, the functions ex and e , and phasors. Our department
jθ
If the users of this book find "Vector Graphics" through "Binary Codes" too
confining, we encourage them to supplement the essential material in
"Complex Numbers" through "Linear Algebra" with their own course notes
on additional topics. Within electrical and computer engineering there are
endless possibilities. Practically any set of topics that can be taught with
conviction and enthusiasm will whet the student's appetite. We encourage
you to write to us or to our editor, Tom Robbins, about your ideas for
additional topics. We would like to think that our book and its subsequent
editions will have an open architecture that enables us to accommodate a
wide range of student and faculty interests.
L. L. Scharf
R. T. Behrens
Boulder, Colorado
To the Teacher:
An incomplete understanding of complex numbers and phasors handicaps
students in circuits and electronics courses, and even more so in advanced
courses such as electromagnetics. optics, linear systems, control, and
communication systems. Our faculty has decided to address this problem as
early as possible in the curriculum by designing a course that drills complex
numbers and phasors into the minds of beginning engineering students. We
have used power signals, musical tones, Lissajous figures, light scattering,
and RLC circuits to illustrate the usefulness of phasor calculus. "Linear
Algebra" through "Binary Codes" introduce students to a handful of modern
ideas in electrical and computer engineering. The motivation is to whet
students' appetites for more advanced problems. The topics we have chosen
– linear algebra, vector graphics, filtering, and binary codes – are only
representative.
n=0
Equation:
2 N −1
1 + z + z + ⋯ + z ,
and then it is evaluated for some specific value of z before we derive the
N
1 − z
analytical result Similarly, an infinite sequence like
1 − z
n
x
lim (1 + ) is written out as
n→∞ n
Equation:
2 3 100
x x x
(1 + x), (1 + ) , (1 + ) , ..., (1 + ) , ...,
2 3 100
and then it is evaluated for some specific x and for several values of n
before the limit is derived. We try to preserve this practice of pedantic
excess until it is clear that every student is comfortable with an idea and the
notation for coding the idea.
To the Student:
These are exciting times for electrical and computer engineering. To
celebrate its silver anniversary, the National Academy of Engineering
announced in February of 1990 the top ten engineering feats of the previous
twenty-five years. The Apollo moon landing, a truly Olympian and protean
achievement, ranked number one. However, a number of other
achievements in the top ten were also readily identifiable as the products of
electrical and computer engineers:
Introduction
It is hard to overestimate the value of complex numbers. They first arose in
the study of roots for quadratic equations. But, as with so many other great
discoveries, complex numbers have found widespread application well
outside their original domain of discovery. They are now used throughout
mathematics, applied science, and engineering to represent the harmonic
nature of vibrating systems and oscillating fields. For example, complex
numbers may be used to study
The most fundamental new idea in the study of complex numbers is the
“imaginary number” j. This imaginary number is defined to be the square
root of −1:
Equation:
j = √ −1
Equation:
2
j = −1.
z = x + jy.
We say that the complex number z has “real part” x and “imaginary part” y:
Equation:
z = Re[z] + j Im[z]
Equation:
Re[z] = x; Im[z] = y.
In MATLAB, the variable x is denoted by real(z), and the variable y is
denoted by imag(z). In communication theory, x is called the “in-phase”
component of z, and y is called the “quadrature” component. We call z =
x + jy the Cartesian representation of z, with real component x and
imaginary component y. We say that the Cartesian pair (x, y)codes the
complex number z.
We may plot the complex number z on the plane as in [link]. We call the
horizontal axis the “real axis” and the vertical axis the “imaginary axis.”
The plane is called the “complex plane.” The radius and angle of the line to
the point z = x + jy are
Equation:
2 2
r = √x + y
Equation:
y
−1
θ =tan ( ).
x
x = rcosθ
Equation:
y = r sin θ.
z = x + jy
= rcosθ + jrsinθ
The complex number cosθ + jsinθ is, itself, a number that may be
represented on the complex plane and coded with the Cartesian pair
(cos θ, sinθ). This is illustrated in [link]. The radius and angle to the point
Equation:
jθ
e =cos θ + jsinθ.
Equation:
jθ
z = re .
that the polar pair r∠θcodes the complex number z. In this polar
representation, we define |z| = r to be the magnitude of z and arg (z) = θ
to be the angle, or phase, of z:
Equation:
|z| = r
Equation:
arg (z) = θ.
With these definitions of magnitude and phase, we can write the complex
number z as
Equation:
jarg(z)
z = |z|e .
Let's summarize our ways of writing the complex number z and record the
corresponding geometric codes:
Equation:
( )
e
jθ
Exercise:
Problem:
Prove e
e
m is an integer.)
Exercise:
Problem:
z =
= (−1)
j[(π/2)+m2π]
n
= j, e
x + jy
(x, y)
=
2n+1
j[(3π/2)+m2π]
re
↓
jθ
r∠θ
= (−1) j
=
∣
, and
= −j, e
z e
jθ
imaginary argument.
Exercise:
Problem:
Prove (j) 2n
and (j)
j arg(z)
is just
the familiar function e evaluated at the imaginary argument x = jθ. We
x
. Evaluate j
j(0+m2π)
a. z = 1 + j0;
b. z = 0 + j1;
c. z = 1 + j1;
d. z = −1 − j1.
= 1
3 4
,j ,j
5
.
jθ
Problem:
a. z = √2e ;
jπ/2
b. z = √2e ;jπ/4
c. z = e ;
j3π/4
d. z = √2e .
j3π/2
a. (0. 7, −0. 1) z = ?
b. (−1. 0, 0. 5) z = ?
c. 1. 6∠π/8 z =?
d. 0. 4∠7π/8 z =?
Exercise:
Problem:
i=1:n,circle(i)=exp(j*2*pi*i/n);end;
axis('square') plot(circle) Replace the explicit for loop
of line 3 by the implicit loop circle=exp(j*2*pi*[1:n]/n);
to speed up the calculation. You can see from [link] that the complex
number e , evaluated at angles θ = 2π/360, 2(2π/360), ..., turns out
jθ
complex number that lies on the unit circle. We will have much more
to say about the unit circle in Chapter 2.
The Complex Numbers e for 0 ≤ θ ≤ 2π (Demo 1.1)
jθ
Complex Numbers: Algebra of Complex Numbers
z1 + z2 = (x 1 + jy 1 ) + (x 2 + jy 2 )
= (x 1 + x 2 ) + j(y 1 + y 2 ).
We say that the real parts add and the imaginary parts add. As illustrated in
[link], the complex number z + z is computed from a “parallelogram
1 2
and z .
2
Exercise:
Problem:
Let z 1 = r1 e
jθ 1
and z = r e . Find a polar formula z =r e for
2 2
jθ 2
3 3
jθ 3
z1 z2 = (x 1 + jy 1 )(x 2 + jy 2 )
= (x 1 x 2 − y 1 y 2 ) + j(y 1 x 2 + x 1 y 2 ).
If the polar representations for z and z are used, then the product may be
1 2
written as [footnote]
We have used the trigonometric identities cos (θ + θ ) =cos θ cos θ −
1 2 1 2
sin θ1 sin θ2 and sin (θ + θ ) =sin θ cos θ + cos θ sin θ2 to derive this
1 2 1 2 1
result.
Equation:
jθ 1 jθ 2
z1 z2 = r1 e r2 e
= r 1 r 2 cos (θ 1 + θ 2 ) + jr 1 r 2 sin (θ 1 + θ 2 )
j(θ 1 +θ 2 )
= r1 r2 e .
We say that the magnitudes multiply and the angles add. As illustrated in
[link], the product z z lies at the angle (θ + θ ).
1 2 1 2
z = e
2 , then the product of z and z is
jθ 2
1 2
Equation:
jθ 2 j(θ 1 +θ 2 )
z1 z2 = z1 e = r1 e .
Exercise:
Problem:
z = −jz .
3 1
Powers. If the complex number z multiplies itself N times, then the result
1
is
Equation:
N N jN θ 1
(z 1 ) = r1 e .
z
k+1
1
k
= z z = r
1 1 e
k+1
1
. Iterate this recursion (or induction) until
j(k+1)θ 1
Equation:
* −jθ
z = x − jy = re .
The complex number z and its complex conjugate are illustrated in [link].
The recipe for finding complex conjugates is to “change jto − j. This
changes the sign of the imaginary part of the complex number.
A Complex Variable and Its Complex Conjugate
Equation:
2 * 2 2 −jθ jθ 2
|z| = z z = (x − jy) (x + jy) = x + y = re re = r .
Write z as z * *
= zw . Find w in its Cartesian and polar forms.
Exercise:
*
Problem: Prove that angle (z 2 z1 ) = θ2 − θ1 .
Exercise:
Problem:
1 *
Re [z] = z + z
2
Equation:
*
Im [z] = 2j z − z .
z1 + z2 = z2 + z1
z1 z2 = z2 z1
Equation:
(z 1 + z 2 ) + z 3 = z 1 + (z 2 + z 3 )
z 1 (z 2 z 3 ) = (z 1 z 2 )z 3
z 1 (z 2 + z 3 ) = z1 z2 + z1 z3 .
z1 = z = 1z.
multiplicative inverse:
Equation:
z + (−z) = 0
−1
zz = 1.
Exercise:
Problem:
Exercise:
−1
1 *
1
z = z = (x − jy).
* 2 2
z z x + y
Show that z *
z is real. Show that z −1
may also be written as
Equation:
−1 −1 −jθ
z = r e .
Plot z and z −1
for a representative z.
Exercise:
Problem: Prove (j) −1
= −j .
Exercise:
Problem: Find z −1
when z = 1 + j1.
Exercise:
Problem:
−1
* 1 *
Prove (z −1
) = z
*
= r
−1
e
jθ
= z . Plot z and (z −1
) for a
*
z z
representative z.
Exercise:
Problem:
Demo 1.2 (MATLAB). Create and run the following script file (name it
Complex Numbers)[footnote]
If you are using PC-MATLAB, you will need to name your file cmplxnos.m.
clear, clg
j=sqrt(-1)
z1=1+j*.5,z2=2+j*1.5
z3=z1+z2,z4=z1*z2
z5=conj(z1),z6=j*z2
avis([-4 4 -4 4]),axis('square'),plot(z1,'0')
hold on
plot(z2,'0'),plot(z3,'+'),plot(z4,'*'),
plot(z2,'0'),plot(z3,'+'),plot(z4,'*'),
plot(z5,'x'),plot(z6,'x')
Complex Numbers (Demo 1.2)
With the help of Appendix 1, you should be able to annotate each line of
this program. View your graphics display to verify the rules for add,
multiply, conjugate, and perp. See [link].
Exercise:
Powers of z
Complex Numbers: Roots of Quadratic Equations
You probably first encountered complex numbers when you studied values
of z (called roots or zeros) for which the following equation is satisfied:
Equation:
2
az + bz + c = 0.
2
b c
z + z + = 0.
a a
2
b c
p (z) = z + z + .
a a
b c
z
2
+ z+ = 0 , we are really looking for roots (or zeros) of the
a a
polynomial p(z). The fundamental theorem of algebra says that there are
two such roots. When we have found them, we may factor the polynomial
p(z) as follows:
Equation:
2
b c
p (z) = z + z + = (z − z 1 ) (z − z 2 ).
a a
In this equation, z1 and z2 are the roots we seek. The factored form p(z) =
(z − z ) (z − z ) shows clearly that p (z ) = p (z ) = 0, meaning that the
1 2 1 2
quadratic equation p(z) = 0 is solved for z = z and z = z . In the process 1 2
of factoring the polynomial p(z), we solve the quadratic equation and vice
versa.
sides of [link], we find that the sum and the product of the roots z and z 1 2
Equation:
2 2
b b c
(z + ) − ( ) + = 0.
2a 2a a
We may take the square root of each side to find the solutions
Equation:
b
b 1
z 1,2 = − ± √ b 2 − 4ac.
2a 2a
Exercise:
Problem:
b c
(z − z 1 ) (z − z 2 ) is, indeed, equal to the polynomial z 2
+ z + .
a a
b c
Check that z 1 + z2 = − and z 1 z2 =
a a
In the equation that defines the roots z and z , the term b − 4ac is critical
1 2
2
(i) Overdamped (b 2
− 4ac > 0) . In this case, the roots z and z are
1 2
Equation:
b 1
z 1,2 = − ± √ b 2 − 4ac.
2a 2a
These two roots are real, and they are located symmetrically about the point
b
− . When b = 0, they are located symmetrically about 0 at the points
2a
1
± √ −4ac . (In this case, −4ac > 0.) Typical solutions are illustrated in
2a
[link].
Exercise:
Problem:
1
a. z 2
+ 2z + = 0 ;
2
1
b. z 2
+ 2a − = 0 ;
2
1
c. z 2
− = 0 .
2
b c
For each equation, check that z 1 + z2 = − and z 1 z2 =
a a
(ii) Critically Damped (b − 4ac = 0). In this case, the roots z and z
2
1 2
b
z1 = z2 = − .
2a
Exercise:
Problem:
a. z 2
+ 2z + 1 = 0;
b. z 2
− 2z + 1 = 0;
c. z 2
= 0.
b c
For each equation, check that z 1 + z2 = − and z 1 z2 =
a a
(iii) Underdamped (b − 4ac < 0). The underdamped case is, by far, the
2
most fascinating case. When b − 4ac < 0, then the square root in the
2
Equation:
b 1
z 1,2 = − ± √ −(4ac − b 2 )
2a 2a
b 1
= − ± j √ 4ac − b 2 .
2a 2a
These complex roots are illustrated in [link]. Note that the roots are
c
z 1,2 = ±j√ .
a
Figure 1.12: Typical Roots in the Underdamped Case; (a)
b/2a > 0, (b)b/2a < 0, and (c) b/2a = 0
Equation:
*
z2 = z1 .
b c
Thus the polynomial p (z) = z 2
+ z + = (z − z 1 ) (z − z 2 ) also
a a
takes the form
Equation:
*
p(z) = (z − z 1 )(z − z )
1
2 2
= z − 2 Re [z 1 ]z + |z 1 | .
and |z
Re[z 1 ] 1|
2
are related to the original coefficients of the polynomial as
follows:
Equation:
b
2 Re [z 1 ] = −
a
Equation:
[link] is now
Equation:
Equation:
Exercise:
p(z)
θ
=
∣
2r cos θ
=
r
z1
(z − re
2
2
± cos
2
jθ
√
1,2
−1
c
Equation:
2
z 1,2 = re
±jθ
(
c
a
−
.
Then [link] for the polynomial p(z) may be written in the “standard form”
Equation:
)(z − re
− 2r cos θz + r .
= re
b
−b
√ 4ac
−jθ
±jθ
).
2
)
Problem:
underdamped case.
Exercise:
Problem:
Exercise:
Problem:
a. z 2
+ 2z + 2 = 0;
b. z 2
− 2z + 2 = 0;
c. z 2
+ 2 = 0.
2
b c
For each equation, check that 2 Re [z 1,2 ] = − and z 1,2 = .
a a
Complex Numbers: Representing Complex Numbers in a Vector Space
Equation:
x
x + jy = z ⇔ z = [ ].
y
x1 + x2
z1 + z2 = [ ]
y1 + y2
Equation:
ax
az = [ ].
ay
z + (−z) = 0
Equation:
lz = z.
0
The vector 0 is 0 = [ ] .
0
Prove that vector addition and scalar multiplication satisfy these properties
of commutation, association, and distribution:
Equation:
z1 + z2 = z2 + z1
Equation:
(z 1 + z 2 ) + z 3 = z 1 + (z 2 + z 3 )
Equation:
a(bz) = (ab)z
Equation:
a (z 1 + z 2 ) = az 1 + az 2 .
Inner Product and Norm. The inner product between two vectors z and 1
Equation:
(z 1 , z 2 ) = x 1 x 2 + y 1 y 2 .
We sometimes write this inner product as the vector product (more on this
in Linear Algebra)
Equation:
T
(z 1 , z 2 ) = z z2
1
x2
= [x 1 y 1 ][ ] = (x 1 x 2 + y 1 y 2 ).
y2
Exercise:
Problem: Prove (z 1
, z 2 ) = (z 2 , z 1 ).
When z = z
1 2 = z , then the inner product between z and itself is the norm
squared of z:
Equation:
2 2 2
||z|| = (z, z) = x + y .
These properties of vectors seem abstract. However, as we now show, they
may be used to develop a vector calculus for doing complex arithmetic.
Equation:
x1 + x2
z1 + z2 ⇔ z1 + z2 = [ ]
y1 + y2
Equation:
x2 x1 x2
x1 z2 ⇔ x1 [ ] = [ ].
y2 x1 y2
y is
1
Equation:
x2 y1 x2
y1 z2 ↔ y1 [ ] = [ ].
y2 y1 y2
x1 x2 − y1 y2
z1 z2 ↔ [ ].
x1 y2 + y1 x2
x2 y2
where v and w are the vectors v = [ ] and w = [ ] . By defining the
−y 2 x2
matrix
Equation:
x2 −y 2
[ ],
y2 x2
x2 −y 2 x1
z1 z2 = z2 z1 ↔ [ ][ ].
y2 x2 y1
cos θ − sin θ x1
jθ jθ
ze = e z ↔ [ ][ ].
sin θ cos θ x2
cos θ − sin θ
We call the matrix [ ] a “rotation matrix.”
sin θ cos θ
Exercise:
cos θ − sin θ
R (θ) = [ ].
sin θ cos θ
Show that R(−θ) rotates by (−θ). What can you say about R(−θ)w
when w = R(θ)z?
Exercise:
a b x
*
z ↔ [ ] [ ]
c d y
:
Equation:
1/2 1/2
2 2
r = x + y = ||z|| = (z, z) .
1 0
If we define the coordinate vectors e 1 = [ ] and e 2 = [ ] , then we can
0 1
z = (z, e 1 )e 1 + (z, e 2 )e 2 .
See [link]. From the figure it is clear that the cosine and sine of the angle θ
are
Equation:
(z, e 1 ) (z, e 2 )
cos θ = ; sin θ =
||z|| ||z||
Representation of z in its Natural Basis
Equation:
(z 2 , e 1 )e 1
T T
(z 1 , z 2 ) = (z 1 , e 1 )e (z 1 , e 2 )e [ ]
1 2
(z 2 , e 2 )e 2
= (z 1 , e 1 ) (z 2 , e 1 ) + (z 1 , e 2 ) (z 2 , e 2 )
This formula shows that the cosine of the angle between two vectors z and 1
*
z , which is, of course, the cosine of the angle of z z , is the ratio of the
2 2 1
Equation:
dE(x) is
Equation:
λdx
|dE (x)| =
2 2
4πϵ 0 (h + x )
Infinitesimal Charge λdx Producing Field dE(x)
But the field strength is directed at angle θ(x), as illustrated in [link]. The
field dE(x) is real with components dE (x) and dE (x), but we code it
1 2
as a complex field. We say that the “complex” field at test point (0, h) is
Equation:
λdx jθ(x)
dE (x) = e
2 2
4πϵ 0 (h + x )
with components dE 1
(x) and dE 2
(x) . That is,
Equation:
λdx
dE 1 (x) = cos θ (x)
2 2
4πϵ 0 (h + x )
Equation:
λdx
dE 2 (x) = sin θ (x).
2 2
4πϵ 0 (h + x )
For charge uniformally distributed with density λ along the x-axis, the total
field at the test point (0, h) is obtained by integrating dE:
Equation:
∞ ∞
λ
∫ dE (x) = ∫ [cos θ (x) + jsinθ (x)]dx.
2 2
−∞ −∞ 4πϵ 0 (h + x )
x h
cos θ (x) = ; sin θ (x) =
1/2 1/2
2 2 2 2
(x + h ) (x + h )
Equation:
∞
λh dx
E = jE 2 = j ∫
3/2
4πϵ 0 2 2
−∞ (x + h )
Equation:
∞
λh x
= j
1/2
4πϵ 0 2 2 2
h (x + h ) −∞
Equation:
λh 1 1 λ
= j + = j
2 2
4πϵ 0 h h 2πϵ 0 h
Equation:
λ
E2 = .
2πϵ 0 h
We emphasize that the field at (0, h) is a real field. Our imaginary answer
simply says that the real field is oriented in the vertical direction because
we have used the imaginary part of the complex field to code the vertical
component of the real field.
Exercise:
Problem:
From the symmetry of this problem, we conclude that the field around the
infinitely long wire of [link] is radially symmetric. So, in polar coordinates,
we could say
Equation:
λ
E (r, θ) =
2πϵ 0 r
There is a version of the quadratic equation that will arise over and over
again in your study of electrical and mechanical systems:
Equation:
2 2
s + 2ξω 0 s + ω 0 = 0.
For reasons that can only become clear as you continue your study of
engineering, the parameter ω is called a resonant frequency, and the
0
, 0 ≤ ξ ≤ ξc
s 1,2 = , ξ = ξc
, ξ ≥ ξc
where ξc is the critically damped value of ξ. Write a MATLAB
program that computes and plots s for ω0 fixed at ω = 1 and ξ
1,2 0
variable between 0.0 and 2.0 in steps of 0.1. Interpret all of your
findings.
section "The Function of ejθ and the Unit Circle and "Numerical
Experiment (Approximating ejθ, must be understood by all students before
proceeding to "Phasors" . The Euler and De Moivre identities provide every
tool that students need to derive trigonometric formulas. The properties of
roots of unity are invaluable for the study of phasors in "Phasors" .
The MATLAB programs in this chapter are used to illustrate sequences and
series and to explore approximations to sin θ and cos θ. The numerical
experiment in "Numerical Experiment (Approximating ejθ illustrates,
geometrically and algebraically, how approximations to e converge.
jθ
Introduction
It is probably not too strong a statement to say that the function e is the
x
Many of you know the number e as the base of the natural logarithm, which
has the value 2.718281828459045. . . . What you may not know is that this
number is actually defined as the limit of a sequence of approximating
numbers. That is,
Equation:
e = lim fn
n→∞
Equation:
n
1
f n = (1 + ) , n = 1, 2, ...
n
for large n.
n
1
Derivatives and the Number e. The number f n = (1 + ) arises in
n
and ask yourself when the derivative of f (x) equals f (x). The function
f (x) is plotted in [link] for a > 1. The slope of the function at point x is
Equation:
df (x) a
x+Δx
−a
x
= lim
dx Δx
Δx→0
Δx
x α −1
= α lim .
Δx
Δx→0
The Function f (x) = a x
d
then f (x) would equal f (x). We call this value of a the special (or
dx
exceptional) number e and write
Equation:
x
f (x) = e
d x
f (x) = e .
dx
The number e would then be e = f (1). Let's write our condition that
Δx
a − 1
converges to 1 as
Δx
Equation:
Δx
e − 1 ≅ Δx, Δxsmall
or as
Equation:
1/Δx
e ≅ (1 + Δx) .
1/n
1 1
Our definition of e = lim (1 + ) amounts to defining Δx =
n→∞
n n
Equation:
x x/Δx
e = lim (1 + Δx) .
Δx→0
x
By letting Δx = we can write this definition in the more familiar form
n
Equation:
n
x
x
e = lim (1 + )
n→∞
n
Equation:
n−1
d x
x 1 x
e = lim n(1 + ) = e .
n→∞
dx n n
prefer?
annual interest. (When x = 0. 01, this is 1%; when x = 0. 10, this is 10%
interest.) If interest is compounded only once per year, you have the simple
interest formula for V , the value of your savings account after 1 compound
1
This result is illustrated in [link]. Can you read the block diagram? The
general formula for the value of an account that is compounded n times per
year is
Equation:
n
x
V n = (1 + ) V0 .
n
Exercise:
Problem:
Equation:
365
x1 x2
(1 + ) versus e .
365
Let's try to extend our definitions of the function e to the argument x = jΘ. x
Equation:
n
jθ
θ
e = lim (1 + j )
n→∞ n
θ
The complex number 1 + j is illustrated in [link]. The radius to the point
n
1/2
2
θ θ θ
1 + j is r = (1 + 2
) and the angle is φ =tan −1
This means that
n n n
n/2
θ 2
the n th
power of 1 + j has radius r n
= (1 +
θ
n
2
) and angle
n
θ
nφ = n tan
−1
(Recall our study of powers of z.) Therefore the complex
n
n
θ
number (1 + j ) may be written as
n
Equation:
n n/2
2
θ θ −1
θ −1
θ
(1 + j ) = (1 + ) [cos (n tan ) + j sin (n tan )].
2
n n n n
n/2
2
θ θ θ
For n large, (1 + 2
) 2 ≅1 , and n tan −1
≅n = θ . Therefore
n n n
n
θ
(1 + j ) is approximately
n
Equation:
n
θ
(1 + j ) = 1(cos θ + j sin θ).
n
n
θ
(1 + j ) = 1 ( cos θ + j sin θ).
n
x = jθ:
Equation:
∞
1 n
jθ
e = ∑ (jθ) .
n!
n=0
When this series expansion for e is written out, we have the formula
jθ
Equation:
jθ ∞ 1 2n ∞ 1 2n+1
e = ∑ (jθ) + ∑ (jθ)
n=0 (2n)! n=0 (2n+1)!
n n
∞ (−1) 2n ∞ (−1) 2n+1
= ∑ θ + j∑ θ .
n=0 (2n)! n=0 (2n+1)!
It is now clear that cos θ and sin θ have the series expansions
Equation:
n
∞ (−1)
2n
cos θ = ∑ θ
n=0
(2n)!
Equation:
∞ n
(−1)
2n+1
sin θ = ∑ θ .
(2n + 1)!
n=0
When these infinite sums are truncated at N − 1 , then we say that we have N-
term approximations for cos θ and sin θ:
Equation:
n
N −1 (−1)
2n
cos θ ≅ ∑ θ
n=0
(2n)!
Equation:
N −1 n
(−1)
2n+1
sin θ ≅ ∑ θ .
(2n + 1)!
n=0
The ten-term approximations to cos θ and sin θ are plotted over exact
expressions for cos θ and sin θ in [link]. The approximations are very good
over one period (0 ≤ θ ≤ 2π), but they diverge outside this interval. For more
accurate approximations over a larger range of θ s, we would need to use more
′
terms. Or, better yet, we could use the fact that cos θ and sin θ are periodic in θ
. Then we could subtract as many multiples of 2π as we needed from θ to bring
the result into the range [0, 2π] and use the ten-term approximations on this new
variable. The new variable is called θ-modulo 2π.
Ten-Term Approximations to cos θ and sin θ
Exercise:
Problem:
Write out the first several terms in the series expansions for cos θ and
sin θ.
Demo 2.1 (MATLAB). Create a MATLAB file containing the following demo
MATLAB program that computes and plots two cycles of cos θ and sin θ
versus θ. You should observe [link]. Note that two cycles take in 2(2π) radians,
which is approximately 12 radians.
clg;
j = sqrt(-1);
theta = 0:2*pi/50:4*pi;
s = sin(theta);
c = cos(theta);
plot(theta,s);
elabel('theta in radians');
ylabel('sine and cosine');
hold on
plot(theta,c);
hold off
The Functions cos θ and sin θ
Exercise:
Problem:
The Unit Circle. The unit circle is defined to be the set of all complex numbers
z whose magnitudes are 1. This means that all the numbers on the unit circle
may be written as z = e . We say that the unit circle consists of all numbers
jθ
1 1
, illustrated in [link]. We call the “reflection of z through the unit circle”
* *
z1 z1
1 1
(and vice versa). Note that z 1 = r1 e
jθ 1
and = e
jθ 1
. The complex
*
r1
z1
1
numbers z 1 − e
jθ
and − e
jθ
are illustrated in [link]. The magnitude squared
*
z
1
of each is
Equation:
Equation:
Equation:
∣
1
*
z1
*
z1
z1 − e
− e
β
2
jθ
jθ
β
2
=
=
2
= (
= (z 1 − e
(z 1 − e
(
1
z
*
1
− e
zi
1
z1
(e
(1−e
2
*
− e
jθ
jθ
)(
e
jθ −jθ
jθ
jθ
) (z 1 − e
z 1 −1)(z e
jθ
|z 1 | , independent of θ!
This result will be of paramount importance to you when you study digital
filtering, antenna design, and communication theory.
*
) (z 1 − e
)(
z1
z 1 )(1−z 1 e
*
1
− e
jθ
*
z1
−1)e
−jθ
−jθ
−jθ
)
− e
−jθ
z
)
1
−jθ
)
)
−jθ
).
The Unit Circle
Exercise:
The Euler and De Moivre identities are the fundamental identities for
deriving trigonometric formulas. From the identity e =cos θ + jsin θ and
jθ
*
the conjugate identity e −jθ
= (e ) =cos θ − jsin θ, we have the Euler
jθ
jθ −jθ
e −e
sin θ =
2j
The identity e jθ
=cos θ + j sin θ also produces the De Moivre identity:
Equation:
n n
jθ jnθ
(cos θ + j sin θ) = (e ) = e
.
= cos nθ + j sin nθ
When the left-hand side of this equation is expanded with the binomial
expansion, we obtain the identity
Equation:
n
n n−k k
∑( )(cos θ) (j sin θ) =cos nθ + j sin nθ.
k
k=0
n n!
( ) = k = 0, 1, ..., n.
k (n − k)!k!′
How do we know that there are ( ) terms of the form x y ? One way to
n
k
n−k k
Exercise:
Problem: Prove ( n
k
) = (
n
n−k
) .
Exercise:
Problem: Find an identity for ( n−1
k−1
) + (
k
n−1
) .
Exercise:
Exercise:
Problem:
Use e j(θ 1 +θ 2 )
= e
jθ 1
e
jθ 2
= (cos θ 1 + j sin θ 1 ) (cos θ 2 + j sin θ 2 ) to
prove
circle at angle θ = 2π/N . When this number is raised to the n power, the
th
result is z = e
n j2πn/N
. This number is also illustrated in [link]. When one
of the complex numbers e j2πn/N
is raised to the N power, the result is
th
Equation:
N
j2πn/N j2πn
(e ) = e = 1.
The Complex Numbers e j2π/N
and e j2πn/N
around the unit circle at angles 2πn/12. The sum of all of the N roots ofth
unity is zero:
Equation:
N −1
j2πn/N
SN = ∑ e = 0.
n=0
Roots of Unity
These partial sums will become important to us in our study of phasors and
light diffraction in "Phasors" and in our discussion of filters in "Filtering".
Partial Sums of the Roots of Unity
j2πn/N
Sk = ∑ e .
n=0
n
Sk = ∑ z ?
n=0
The answer is yes, and here is how we find it. If z = 1, the answer is
S = k. If z ≠ 1, we can premultiply S by z and proceed as follows:
k k
Equation:
k−1 n+1 k m
zS k = ∑ z = ∑ z
n=0 m=1
k−1 m k
= ∑ z + z − 1
m=0
k
= Sk + z − 1.
k−1 k−1
n=0 n=0
Exercise:
N −1
Exercise:
Problem:
Find formulas for the magnitude and phase of the partial sum
k−1
Sk = ∑ e
j2πn/N
.
n=0
Exercise:
Problem:
sum S k = ∑e
j2πn/N
for k = 1, 2, ..., N . You should observe [link].
n=0
Exercise:
2 st
(s + a 1 s + a 2 )e = 0.
As we know from our study of this quadratic equation, the solutions are
Equation:
a1 1
s 1,2 = − ± √ a 2 − 4a .
1 2
2 2
fundamental result from the theory of differential equations that the most
general solution for x(t) is a linear combination of these assumed solutions:
Equation:
s1 t s2 t
x (t) = A 1 e + A2 e .
Equation:
a1 1
2
s 1,2 = − ± j √ 4a − a .
2 1
2 2
Equation:
1
2
ω = √ 4a − a .
2 1
2
If this solution is to be real, then the two terms on the right-hand side must
*
be complex conjugates. This means that A = A and the solution for x(t)
2 1
is
Equation:
*
σt jωt σt −J ωt
x (t) = A1 e e + A e e
1
σt jωt
= 2 Re{A 1 e e }.
Exercise:
Problem:
−1 −2 n
(1 + a 1 z + a2 z )z = 0.
Equation:
−1 −2
1 + a1 z + a2 z = 0
2
z + a 1 z + a 2 = 0.
a1 1 2
z 1,2 = − ± j √ 4a 2 − a
2 2 1
jθ
= re .
* * n
n
= A1 z + A 1 (z 1 )
1
n
= 2 Re{A 1 z }
1
n
= 2|A|r cos (θn + φ).
Exercise:
Problem:
a. x n + 2x n−1 + 2 = 0 ;
b. x n − 2x n−1 + 2 = 0;
c. x n
+ 2x n−2 = 0.
The Functions e^x and e^jθ: Numerical Experiment (Approximating e^jθ)
n
jθ
1. e jθ
= lim (1 + ) ; and
n→∞ n
n k
(jθ)
2. e jθ
= lim ∑ .
n→∞
k!
k=0
In this experiment, you will write a MATLAB program to evaluate the two
functions f and S for twenty values of n:
n n
n
jθ
1. f n = (1 +
n
) , n = 1, 2, ..., 20 ; and
k
2. S .
n (jθ)
n
= ∑ , n = 1, 2, ..., 20k
k=0 k!
Choose θ = π/4(= pi/4). Use an implicit for loop to draw and plot a
circle of radius 1. Then use an implicit for loop to compute and plot f and
n
an explicit for loop to compute and plot S for n = 1, 2, ..., 100. You
n
"Sinusoidal Steady State and the Series RLC Circuit" and Light Scattering
by a Slit" on sinusoidal steady state and light scattering are too demanding
for freshmen but are right on target for sophomores. These sections may be
covered in a sophomore course (or a supplement to a sophomore course) or
skipped in a freshman course without consequence.
In this chapter we use what we have learned about complex numbers and
the function e to develop a phasor calculus for representing and ma-
jθ
nipulating sinusoids. This calculus operates very much like the calculus we
developed in "Complex Numbers" and "The Functions ex and ejθ" for
manipulating complex numbers. We ap- ply our calculus to the study of
beating phenomena, multiphase power, series RLC circuits, and light
scattering by a slit.
Phasors: Phasor Representation of Signals
There are two key ideas behind the phasor representation of a signal:
When τ is positive, then τ is a “time delay” that describes the time (greater
than zero) when the first peak is achieved. When τ is negative, then τ is a
“time advance” that describes the time (less than zero) when the last peak
2π
was achieved. With the substitution ω = we obtain a third way of
T
writing x(t):
Equation:
2π
x(t) = A cos (t − τ ).
T
In this form the signal is easy to plot. Simply draw a cosinusoidal wave
with amplitude A and period T; then strike the origin (t = 0) so that the
signal reaches its peak at τ. In summary, the parameters that determine a
cosinusoidal signal have the following units:
T, in seconds (sec)
φ, in radians (rad)
τ, in seconds (sec)
Exercise:
Problem:
2π
Show that x (t) = A cos (t − τ ) is “periodic with period T ,"
T
meaning that x(t + mT ) = x(t) for all integer m.
Exercise:
Problem:
(seconds)
−1
or hertz (Hz). Write x(t) in terms of f . How is f related
to ω? Explain why f gives the number of cycles of x(t) per second.
Exercise:
Problem:
π
Sketch the function x (t) = 110 cos [2π (60)t − ] versus t. Repeat
8
π
for x (t) = 5 cos [2π (16 × 10 6
)t + ] and
4
−3
2π 10
x (t) = 2 cos [ (t − )] . For each function, determine
−3
10 8
The signal x(t) = A cos (ωt + φ) can be represented as the real part of a
complex number:
Equation:
j(ωt+φ)
x (t) = Re [Ae ]
jφ jωt
= Re[Ae e ].
We call Ae jφ
e
jωt
the complex representation of x(t) and write
Equation:
jφ jωt
x (t) ↔ Ae e ,
meaning that the signal x(t) may be reconstructed by taking the real part of
Ae
jφ
e . In this representation, we call Ae the phasor or complex
jωt jφ
Exercise:
Problem:
For each of the signals in Problem 3.3, give the corresponding phasor
representation Ae . jφ
the complex representation of the real signal A cos (ωt + φ). At t = 0, the
complex representation produces the phasor
Equation:
jφ
Ae .
−π
This phasor is illustrated in [link]. In the figure, φ is approximately If
10
we let t increase to time t , then the complex representation produces the
1
phasor
Rotating Phasor
We know from our study of complex numbers that e just rotates thejωt 1
2π
circular trajectory of [link]. When t = then e jωt
= e
j2π
= 1 .
ω
2π
Therefore, every ( ) seconds, the phasor revisits any given position on
ω
d
d
ωt = ω.
dt
the signal A cos (ωt + φ). In this representation, e rotates the phasor
jωt
Ae
jφ
through angles ωt at the rate ω. The real part of the complex
representation is the desired signal Acos (ωt + φ). This real part is read off
the rotating phasor diagram as illustrated in [link]. In the figure, the angle φ
2π
is about − . As we become more facile with phasor representations, we
10
and X the phasor representation. The phasor X is, of course, just the phasor
Ae
jφ
.
Reading a Real Signal from a Complex,
Rotating Phasor
Exercise:
Problem:
A sin (ωt + φ). What do we mean when we say that the real and
Exercise:
Problem:
2π 2π 2π
ranges from −2( )to + 2( ) in steps of 0.02 ( ) . In your
ω ω ω
two-dimensional plot to get a picture like [link] and plot Re[e ] and jωt
A
In this formula, the term e
jφ
e
jωt
is a rotating phasor that begins at the
2
phasor value Ae jφ
(for t = 0) and rotates counterclockwise with frequency
A
ω. The term e
−jφ
e
−jωt
is a rotating phasor that begins at the (complex
2
A
conjugate) phasor value e
−jφ
(for t = 0) and rotates clockwise with
2
(negative) ffequency ω. The physically meaningful frequency for a cosine
is ω, a positive number like 2π(60) for 60 Hz power. There is no such thing
as a negative frequency. The so-called negative frequency of the term
A
e
−jφ
e
−jωt
just indicates that the direction of rotation for the rotating
2
phasor is clock-wise and not counterclockwise. The notion of a negative
frequency is just an artifact of the two-phasor representation of A
cos (ωt + φ). In the one-phasor representation, when we take the “real
part,” the artifact does not arise. In your study of circuits, systems theory,
electromagnetics, solid-state devices, signal processing, control, and
communications, you will encounter both the one- and two-phasor
representations. Become facile with them.
Exercise:
Problem:
[link].
Adding Phasors
Exercise:
Problem:
Equation:
d
A cos (ωt + φ) = −ωA sin (ωt + φ)
dt
jφ jωt
= − Im[ωAe e ]
jφ jωt
= Re[jωAe e ]
jπ/2 jφ jωt
= Re[ωe Ae e ].
This finding is very important. It says that the derivative of A cos (ωt + φ)
has the phasor representation
Equation:
d jφ
A cos (ωt + φ) ↔ jωAe
dt
jπ/2 jφ
↔ ωe Ae .
These two phasor representations are entirely equivalent. The first says that
the phasor Ae is complex scaled by jω to produce the phasor for
jφ
d
A cos (ωt+φ) , and the second says that it is scaled by ω and phased by
dt
+π/2 . The phasor representations of A cos (ωt + φ) and
d
A cos (ωt + φ) are illustrated in Figure 3.6. Note that the derivative
dt
“leads by π/2 radians (90)."
Differentiating and Integrating Phasors
A jφ jωt
= Im[ e e ]
ω
A jφ jωt
= Re[−j e e ]
ω
A jφ jωt
= Re[ e e ]
jω
1 −jπ/2 jφ jωt
= Re[ e Ae e ].
ω
This finding shows that the integral of A cos (ωt + φ) has the phasor
representation
Equation:
1 jφ
∫ A cos (ωt + φ)dt ↔ Ae
jω
1 −jπ/2 jφ
↔ e Ae .
ω
1 1
The phasor Ae jφ
is complex scaled by or scaled by and phased by
jω ω
e
−jπ/2
to produce the phasor for ∫ A cos (ωt + φ)dt . This is illustrated
in [link]. Note that the integral “lags by π/2 radians (90). Keep these
geometrical pictures of leading and lagging by π/2 in your mind at all
times as you continue your more advanced study of engineering.
Try it:
Equation:
2
d d
2
x (t) = [−Aω sin (ωt + φ)] = −ω A cos (ωt + φ).
2
dt dt
The constants A and φ are determined from the initial conditions
Equation:
2 2 π 2
x (0) = A cos φ x (0) + x ( ) = A
2ω
π x(π/2ω)
x( ) = −A sin φ − =tan φ.
2ω x(0)
Exercise:
Problem:
d
x (t)|
t=0
.
dt
Phasors: Beating between Tones
Perhaps you have heard two slightly mistuned musical instruments play
pure tones whose frequencies are close but not equal. If so, you have sensed
a beating phenomenon wherein a pure tone seems to wax and wane. This
waxing and waning tone is, in fact, a tone whose frequency is the average
of the two mismatched frequencies, amplitude modulated by a tone whose
“beat” frequency is half the difference between the two mismatched
frequencies. The effect is illustrated in [link]. Let's see if we can derive a
mathematical model for the beating of tones.
average frequency is ω0, and the difference frequency is 2ν . What you hear
is the sum of the two tones:
Equation:
The first tone has amplitude A and phase φ ; the second has amplitude
1 1
A and phase φ . We will assume that the two amplitudes are equal to A.
2 2
φ1 = φ + ψ and φ2 = φ − ψ
1 1
φ = (φ 1 + φ 2 ) and ψ = (φ 1 − φ 2 ).
2 2
Beating between Tones
j(ω 0 t+φ)
= 2A Re e , cos, (νt + ψ)
cos (ω t + φ) turns out many cycles of its tone. For example, if t runs
0
2π
from 0 to (about 0.1 seconds in our example), then the modulating
10ν
wave turns out just 1/10 cycle while the carrier turns out 10ν ω cycles
Δ
(about 100 in our example). Every time νt changes by 2π radians, then the
modulating term goes from a maximum (a wax) through a minimum (a
wane) and back to a maximum. This cycle takes
Equation:
2π
νt = 2π ⇔ t = seconds,
ν
which is 1 second in our example. In this 1 second the carrier turns out
1000 cycles.
Exercise:
Problem:
Exercise:
j2π(60)t
= Re{X 1 e }
jφ
X 1 = 110e
j[2π(60)t+φ+π]
x 2 (t) = 110 cos [2π (60)t + φ + π] = Re {110e }
j2π(60)t
= Re{X 2 e }
j(φ+π)
X 2 = 110e .
You may use x (t) to drive your clock radio or your toaster and the
1
Equation:
Exercise:
Equation:
j[ω 0 t+n(2π/3)] jn(2π/3)
x n (t) = 110 Re {e } ↔ X n = 110e , n = 1, 2, 3.
[link]. Compute the voltage you can get with x (t) − x (t). This
2 1
answer explains why you do not get 220 volts in three-phase circuits.
What do you get?
Three-Phase Power
0, 1, ..., N − 1) are
Equation:
( )
2π
x n (t) = A cos (ωt + n)
N
N −1 N −1 j2πn/N jωt
∑ x n (t) = Re {A ∑ e e }
n=0 n=0
j2π
1−e jωt
= Re{A j2π/N
e }
1−e
= 0.
But what about the sum of the instantaneous powers? Define the
instantaneous power of the n signal to be
th
Equation:
2 2 2 2π
p n (t) = x (t) = A cos (ωt + n)
n N
2 2
A A 2π
= + cos (2ωt + 2 n)
2 2 N
2 2
A A j(2π/N )2n j2ωt
= + Re { e e }.
2 2
Lissajous figures are figures that are turned out on the face of an
oscilloscope when sinusoidal signals with different amplitudes and different
phases are applied to the time base (real axis) and deflection plate
(imaginary axis) of the scope. The electron beam that strikes the
phosphorous face then had position
Equation:
and A cos (ωt + φ) is the “y-coordinate of the point.” As time runs from
y
0 to infinity, the point z(t) turns out a trajectory like that of [link]. The
2π
figure keeps overwriting itself because z(t) repeats itself every
ω
seconds. Do you see why?
Lissajous Figure on Oscilloscope Screen
Exercise:
Problem:
Find the intercepts that the Lissajous figure makes with the real and
imaginary axes in [link]. At what values of time are these intercepts
made?
Exercise:
Problem:
jφ x jφ y −jφ x −jφ y
Ax e +jA y e Ax e +jA y e
jωt −jωt
= e + e .
2 2
Equation:
jωt −jωt
z (t) = B 1 e + B2 e
jφ x jφ y
Ax e +jA y e
B1 =
2
−jφ x −jφ y
Ax e +jA y e
B2 =
2
of values for t.
Phasors: Sinusoidal Steady State and the Series RLC Circuit
and - on the voltage source indicate that the polarity of the applied voltage
is positive on the top and negative on the bottom. Our convention is that
current flows from positive to negative, in this case clockwise in the circuit.
Series RLC Circuit
We will assume that the voltage source is an audio oscillator that pro- duces
the voltage
Equation:
We then describe the voltage source by the phasor V and remember that we
can always compute the actual voltage by multiplying by e and taking
jωt
Exercise:
Circuit Laws. In your circuits classes you will study the Kirchhoff laws
that govern the low frequency behavior of circuits built from resistors (R),
inductors (L), and capacitors (C). In your study you will learn that the
voltage dropped across a resistor is related to the current that flows through
it by the equation
Equation:
V R (t) = Ri (t).
You will learn that the voltage dropped across an inductor is proportional to
the derivative of the current that flows through it, and the voltage dropped
across a capacitor is proportional to the integral of the current that flows
through it:
Equation:
di
V L (t) = L (t)
dt
1
V C (t) = ∫ i (t)dt.
C
Phasors and Complex Impedance. Now suppose that the current in the
preceding equations is sinusoidal, of the form
Equation:
V R (t) = Ri (t)
jωt
= R Re{I e }
jωt
= Re{RI e }.
V R (t) ↔ V R ; V R = RI .
We call R the impedance of the resistor because R is the scale constant that
relates the “phasor voltage VR' to the “phasor current I.”
di d
jωt
V L (t) = L (t) = L Re {I e }.
dt dt
The derivative may be moved through the Re[ ] operator (see [link]) to
produce the result
Equation:
jωt
V L (t) = L Re {jωI e }
jωt
= Re{jωLI e }.
Equation:
V L (t) ↔ V L ; V L = jωLI .
We call jωL the impedance of the inductor because jωL is the complex
scale constant that relates “phasor voltage V ' to “phasor current I .”
L
Exercise:
d
Problem: Prove that the operators and Re[] commute:
dt
Equation:
d d
jωt jωt
Re {e } = Re { e }.
dt dt
1 1 jωt
V C (t) = ∫ i (t)dt = ∫ Re {I e }dt.
C C
The integral may be moved through the Re[ ] operator to produce the result
Equation:
1 I jωt
V C (t) = Re { e }
C jω
I jωt
= Re{ e }.
jωC
Thus the phasor representation of V C (t) is
Equation:
I
V C (t) ↔ V C ; V C =
jωC
1 1
We call the impedance of the capacitor because is the complex
jωC jωC
Kirchhoff's Voltage Law. Kirchhoff's voltage law says that the voltage
dropped in the series combination of R, L, and C illustrated in [link] equals
the voltage generated by the source (this is one of two fundamental
conservation laws in circuit theory, the other being a conservation law for
current):
Equation:
An obvious solution is
Equation:
V = VR + VL + VC
1
= (R + jωL + )I
jωC
where I is the phasor representation for the current that flows in the circuit.
This solution is illustrated in [link], where the phasor voltages RI , jωLI ,
1
and I are forced to add up to the phasor voltage V .
jωC
Exercise:
1
Problem: Redraw [link] for R = ωL = = 1 .
ωC
1
Impedance. We call the complex number R + jωL + the complex
jωC
impedance for the series RLC network because it is the complex number
that relates the phasor voltage V to the phasor current I :
Equation:
V = ZI
1
Z = R + jωL + .
jωC
The complex number Z depends on the numerical values of resistance (R),
inductance (L), and capacitance (C), but it also depends on the angular
frequency (ω) used for the sinusoidal source. This impedance may be
manipulated as follows to put it into an illuminating form:
Equation:
1
Z = R + j(ωL − )
ωC
L 1
= R + j√ (ω√ LC − ).
C
ω√ LC
The parameter ω 0 =
1
√ LC
is a parameter that you will learn to call an
"undamped natural frequency" in your more advanced circuits courses.
With it, we may write the impedance as
Equation:
ω ω0
Z = R + jω 0 L ( − ).
ω0 ω
The frequency ω
ω0
is a normalized frequency that we denote by ν . Then the
impedence, as a function of normalized frequency, is
Equation:
1
Z (ν) = R + jω 0 L (ν − ).
ν
When the normalized frequency equals one (ν = 1), then the impedance is
entirely real and Z = R. The circuit looks like it is a single resistor.
Equation:
ω0 L 2 1 2 1/2
Z (ν) = R[1 + ( ) (ν − ) ] .
R ν
ω0 L 1
−1
arg Z (ν) =tan (ν − ).
R ν
The impedance obeys the following symmetries around ν = 1 :
Equation:
* 1
Z (ν) = Z ( )
ν
1
Z(ν) = Z( )
ν
1
arg Z (ν) = −arg Z ( ).
ν
In the next paragraph we show how this impedance function influences the
current that flows in the circuit.
Resonance. The phasor representation for the current that flows the current
that flows in the series RLC circuit is
Equation:
V
I =
Z(ν)
1 −jargZ(ν)
= e V
|Z(ν)|
Z(ν)
displays a "resonance phenomenon." that is,
peaks at ν
|H (ν)| = 1 and decreases to zero and ν = 0 and ν = ∞ :
Equation:
0, ν = 0
1
|H (ν)| = ν = 1
R
0, ν = ∞.
Exercise:
Problem:
Circle Criterion and Power Factor. Our study of the impedance Z(ν) and
1
the function H (ν) = brings insight into the resonance of an RLC
Z(ν)
circuit and illustrates the ffequency selectivity of the circuit. But there is
more that we can do to illuminate the behavior of the circuit.
Equation:
1
V = RI + j(ωL − )I .
ωC
This equation shows how voltage is divided between resistor voltage RI and
inductor-capacitor voltage j(ωL − 1
)I .
ωC
Equation:
ω ω0
V = RI + jω 0 L ( − )I
ω0 ω
or
Equation:
jω 0 L 1
V = RI + (ν − )RI .
R ν
V = V R + jk (ν)V R
Equation:
ω0 L 1
k(ν) = (ν − ).
R ν
[link] brings very important geometrical insights. First, even though the
phasor voltage V in the RLC circuit is complex, the terms V and
R R
π
jk (ν)V R are out of phase by radians. This means that, for every
2
allowable value of V , the corresponding jk (ν)V must add in a right
R R
jk (ν)V R
that sum to V . Several such solutions for V and jk (ν)V are
R R
illustrated in Figure 3.15(b). From the figure we gain the clear impression
V V
that the phasor voltage V >R lies on a circle of radius centered at
2 2
Let's try this solution,
Equation:
V V jψ
VR = + e
2 2
V jψ
= (1 + e ),
2
and explore its consequences. When this solution is substituted into [link],
the result is
Equation:
V V
jψ jψ
V = (1 + e ) + jk (ν) (1 + e )
2 2
or
Equation:
jψ
2 = (1 + e ) [1 + jk (ν)].
that Produce V
If we multiply the left-hand side by its complex conjugate and the right-
hand side by its complex conjugate, we obtain the identity
Equation:
2
4 = 2 (1+ cos ψ)[1 + k (ν)].
This equation tells us how the angle ψ depends on k(ν) and, conversely,
how k(ν) depends on ψ:
Equation:
2
1 − k (ν)
cos ψ =
2
1 + k (ν)
Equation:
1− cos ψ
2
k (ν) =
1+ cos ψ
The number cos ψ lies between −1 and +1, so a circular solution does
indeed work.
Exercise:
Problem:
V
The equation V R = (1 + e
jψ
) is illustrated in [link]. The angle that V R
2
makes with V is determined from the equation
Equation:
ψ
2φ + π − ψ = π ⇒ φ =
2
The Voltages V and VR, and the Power Factor
cos φ
2 2
= cos φ − (1− cos φ)
2
= 2 cos φ − 1
2
= 2η − 1.
cos ψ + 1 1
2
η = =
2
2 1 + k (ν)
ν = 0, ∞(ω = 0, ∞).
Exercise:
Problem:
ω0 L 1
With k defined as k (ν) = (ν − ) , plot k 2
,
(ν) cos ψ , and η 2
R ν
versus ν .
Exercise:
Problem: Find the value of ν that makes the power factor η = 0. 707.
Phasors: Light Scattering by a Slit
One of the most spectacular successes for phasor analysis arises in the study
of light diffraction by a narrow slit. The experiment is to shine laser light
through a slit in an otherwise opaque sheet and observe the pattern of light
that falls on a distant screen. When the slit is very narrow compared with
the wavelength of the light, then the light that falls on the screen is nearly
uniform in intensity. However, when the width of the slit is comparable to
the wavelength of the light, the pattern of light that falls on the screen is
scalloped in intensity, showing alternating light and dark bands. The
experiment, and the observed results, are illustrated in [link].
Light Diffraction by a Slit
Why should this experiment produce this result? Phasor analysis illuminates
the question and produces an elegant mathematical description of a
profoundly important optical experiment.
system.
A
j[ωt−(2π/λ)r n ]
E (r n , t) = Re { e }.
N
The function E(r , t) describes the “electric field” at time t and distance rn
n
Exercise:
Problem:
time t. Sketch the function and interpret it. What is its period?
Exercise:
Problem:
radius r . Sketch the function and interpret it. Call the “period in r "
n n
is
Equation:
2 2 2
(r n − nd sin φ) + (nd cos φ) = r0 .
2
nd
1 + ( cos φ) ≅ 1.
r0
nd
This will be close for << 1 . We will assume that the slit width L is
r0
for all n. This means that, for any point P on the distant screen, the light
contributed by the n source is approximately
th
Equation:
A j[ωt−(2π/λ)(r 0 +ndsinφ)]
E n (φ, t) = Re { e }
N
A −j(2π/λ)r 0 −j(2π/λ)ndsinφ
E n (φ) = e e .
N
Phasors and Interference. The phasor representation for the field observed
at point P on the screen is the sum of the phasors contributed by each
source:
Equation:
N −1 N −1
−j(2π/λ)ndsinφ
E (φ) = ∑ E n (φ) = E 0 (φ) ∑ e .
n=0 n=0
jnθ
E (φ) = E 0 (φ) ∑ e
n=0
where the angle θ is (2π/λ)d sin φ. This sum is illustrated in [link] for
several representative values of θ. Note that for small θ, meaning small φ,
the sum has large magnitude, whereas for θ on the order of 2π/N , the sum
is small. This simple geometric interpretation shows that for some values of
φ, corresponding to some points P on the screen, there will be constructive
interference between the phasors, while for other values of φ there will be
destructive interference. Constructive interference produces bright light,
and destructive interference produces darkness.
Phasor Sums for Diffraction
Exercise:
L
This function is plotted in [link] for two values of the width of the slit
λ
L λ
measured in wavelengths. When << 1 (i.e., >> 1 ), then the light is
λ L
L λ
uniformly distributed on the screen. However, when > 1( < 1) ,
λ L
then the function has many zeros for | sin φ| < 1, as illustrated in the
figure. These zeros correspond to dark spots on the screen where the fields
radiated from the infinity of points within the slit interfere destructively.
Interference Pattern for a Slit
Exercise:
d
sin (π sin φ)
λ
L Nd
versus sin φ for = = 10 and N = 2, 4, 8, 16, 32 . Compare
λ λ
with the continuous, limiting form
Equation:
∣
A sin (π
π
L
λ
L
λ
sin φ)
sin φ
Phasors: Numerical Experiment (Interference Patterns)
Let's add two sinusoids whose amplitudes and frequencies are identical and
whose phases are different:
Equation:
ψ j[φ+(ψ/2)]
X = 2A cos ( )e .
2
Interpret this finding. Then write a MATLAB program that computes and
plots complex X on the complex plane as ψ varies from 0 to 2π and that
plots magnitude, |X|, and phase, arg X, versus the phase angle ψ. (You
2π
will have to choose ψ = n , n = 0, 1, ..., N − 1 , for a suitable N .)
N
When do you get constructive interfelence and when do you get destructive
interference? Now compute and plot x(t) versus t (you will need to
discretize t) for several interesting values of ψ. Explain your interference
results in terms of the amplitude and phase of x(t) and the magnitude and
phase of X. Use the subplots discussed in "An Introduction to MATLAB"
to plot all of your results together.
Linear Algebra: Introduction
Vectors are introduced in the section "Vectors", along with algebraic and
geometric interpretations of some fundamental vector operations and
properties. The section "Inner Product and Euclidean Norm", the section
"Direction Cosines", and the section "Projections" introduce inner products
and their applications, including norm, direction cosines, orthogonality, and
projections. Some important alternatives to the Euclidean norm are
introduced in the section "Other Norms". Matrices are motivated and
introduced in this section. The notation in these sections can be daunting to
the beginner, so we proceed very carefully, using example after example. In
the section "Solving Linear Systems of Equations" we codify the
elimination procedures that students have used in high school to solve linear
systems of equations. The MATLAB demonstration in Demo 2 shows how
to use MATLAB to solve linear equations. The section "Circuit Analysis"
shows how linear algebra and MATLAB can be used to analyze dc circuits.
The numerical experiment "Circuit Design" gives students practice in
building function files in MATLAB and shows how to solve a sequence of
linear equations in order to design a circuit with desired properties.
Introduction
Linear algebra is a branch of mathematics that is used by engineers and
applied scientists to design and analyze complex systems. Civil engineers
use linear algebra to design and analyze load-bearing structures such as
bridges. Mechanical engineers use linear algebra to design and analyze
suspension systems, and electrical engineers use it to design and analyze
electrical circuits. Electrical, biomedical, and aerospace engineers use linear
algebra to enhance X rays, tomographs, and images from space. In this
chapter and the next we study two common problems from electrical
engineering and use linear algebra to solve them. The two problems are (i)
electrical circuit analysis and (ii) coordinate transformations for computer
graphics. The first of these applications requires us to understand the
solution of linear systems of equations, and the second requires us to
understand the representation of mathematical operators with matrices.
Example:
A woman steps onto a moving sidewalk at a large airport and stands while
the moving sidewalk moves her forward at 1.2 meters/seconds. At the
same time, a man begins walking against the motion of the sidewalk from
the opposite end at 1.5 meters/second (relative to the sidewalk). If the
moving sidewalk is 85 meters long, how far does each person travel
(relative to the ground) before they pass each other?
To solve this problem, we first assign a variable to each unknown quantity.
Let x be the distance traveled by the woman, and let x be the distance
1 2
traveled by the man. The sum of the two distances is 85 meters, giving us
one equation:
Equation:
x 1 + x 2 = 85.
Our second equation is based on the time required before they pass. Time
equals distance divided by rate, and the time is the same for both people:
Equation:
x1 x2
= ⇒ 0. 3x 1 − 1. 2x 2 = 0.
1. 2 1. 5 − 1. 2
1. 2
We may substitute [link] into [link] to obtain the result x 2 + x 2 = 85 ,
0. 3
or
Equation:
5x 2 = 85 ⇒ x 2 = 17.
Combining the result from [link] with that of [link], we find that
Equation:
x 1 = 68.
1 1 x1 85
[ ][ ] = [ ].
0. 3 −1. 2 x2 0
(1) x 1 + (1)x 2 = 85
Equation:
0 5 x1 85
[ ][ ] = [ ].
0. 3 −1. 2 x2 0
x1
x2
x = x3 .
|
xn
Notice that we indicate a vector with boldface and the constituent elements
with subscripts. A real number by itself is called a scalar, in distinction
from a vector or a matrix. We say that x is an n-vector, meaning that x has
n elements. To indicate that x is a real number, we write
1
Equation:
x1 ∈ ,
geometric intuition begins to fail above three dimensions, but the linear
algebra is completely general.
A Vector in R3
x1 + y1 x1− y1
x2 + y2 x2 − y2
x + y = x3 + y3 ;x − y = x3 − y3 .
| |
xn + yn xn − yn
Example:
1 0
see that this result is consistent with the definition of vector subtraction in
[link]. You can also picture the subtraction in [link] by mentally reversing
the direction of vector y to get −y and then adding it to x by sliding it to
the position where its tail coincides with the head of vector x. (The head is
the end with the arrow.) When you slide a vector to a new position for
adding to another vector, you must not change its length or direction.
Subtraction of Vectors
Exercise:
Problem:
1 1
a. x = 3 , y = 2 ;
2 3
−1 1
b. x = 3 , y = 2 ;
−2 3
1 1
c. x = −3 , y = 3 .
2 2
Scalar Product. Several different kinds of vector multiplication are
defined.[footnote] We begin with the scalar product. Scalar multiplication
is defined for scalar a and vector x as
The division of two vectors is undefined, although three different
“divisions” are defined in MATLAB.
Equation:
ax1
ax2
ax = ax3 .
axn
If |a| < 1, then the vector ax is "shorter" than the vector x; if |a| > 1, then
the vector ax is ‚"longer" than x. This is illustrated for a 2-vector in [link].
Exercise:
Problem:
Compute and plot the scalar product ax when x = 1/2 for each of
l/4
a. a = 1;
b. a = −1;
c. a = −1/4;
d. a = 2.
Exercise:
Problem:
Given vectors , , ∈
n
and the scalar a ∈ , prove the following
identities:
(x, y) = x 1 y 1 + x 2 y 2 + x 3 y 3 + ⋯ + x n y n .
a ∈ R,
Exercise:
Problem:
2 2 2
∥ x ∥= √ x + x + +x n .
1 2
Notice the use of the double vertical bars to indicate the norm. An
equivalent definition of the norm, and of the norm squared, can be given in
terms of the inner product:
Equation:
∥ x ∥= √ (x, x)
or
Equation:
2
∥ x ∥ = (x, x).
Example:
The Euclidean norm of the vector
Equation:
1
3
x = ,
5
−2
is ∥ x ∥= √1 2
+ 3
2
+ 5
2
+ (−2)
2
= √ 39.
An important property of the norm and scalar product is that, for any
x ∈ R and a ∈ R ,
n
Equation:
||ax|| = |a|||x||.
So we can take a scalar multiplier outside of the norm if we take its absolute
value.
Exercise:
2
(x, y)
2λ||x|| − 2 (x, y) = 0 ⇒ λ =
2
||x||
When this solution is substituted into the formula for the norm squared in
[link], we obtain
Equation:
2
(x, y) 2
2(x, y) 2
||x|| − (x, y) + ||y|| ≥ 0,
2 2
||x|| ||x||
which simplifies to
Equation:
2
(x, y) 2 2 2 2
− + ||y|| ≥ 0 ⇒ (x, y) ≤ ||x|| ||y|| .
2
||x||
2 2 2
= (|α| ||x|| )||x||
2
= (αx, αx)||x||
2
= (y, y)||x||
2 2
= ||y|| ||x|| ,
in the same direction as x. The term unit vector means that the norm of the
vector is 1:
Equation:
||u x || = 1.
The question is, given x, how can we find u ? The first part of the answer
x
Equation:
||u x || = 1
Equation:
|αx|| = 1
Equation:
|α|||x|| = 1
Equation:
1
α =
||x||
We have dropped the absolute value bars on α because ||x|| is positive. The
α that does the job is 1 over the norm of x. Now we can write formulas for
Equation:
1
ux = x,
||x||
Equation:
x = ||x||u x .
Unit Coordinate Vectors. There is a special set of unit vectors called the
unit coordinate vectors. The unit coordinate vectore is a unit vector in ∇
i
n
that points in the positive direction of the i th
coordinate axis. [link] shows
the three unit coordinate vectors in ∇ . 3
Equation:
1 0 0
e1 = 0 , e2 = 1 , e3 = 0 .
0 0 1
3
a. x = [ ] ;
4
b. x = 6 ;
−2
−1
c. x = .
1
−1
Direction Cosines. We often say that vectors “have magnitude and
direction.” This is more or less obvious from "Linear Algebra: Vectors",
where the three-dimensional vector x has length √x + x + x and2
1
2
2
2
3
Equation:
(x, e k ) = (e k , x) = x k .
as follows:
Equation:
(x, y)
cos θ =
||x||||y||
Equation:
(x, e k )
cos θ k =
||x||||e k ||
Equation:
(x, e k ) xk
cos θ k = =
||x|| ||x||
This formula really shows that the vector x has “magnitude” ||x|| and
direction (θ , θ , ..., θ ) and that the magnitude and direction are sufficient
1 2 n
to determine x. We call ( cos θ , cos θ , ..., cos θ ) the direction cosines for
1 2 n
Show that [link] agrees with the usual definition of an angle in two
dimensions.
Exercise:
1 2
a. x = 0 , y = 2 ;
0 2
1 −1
−1 0
b. x = , y = ;
1 1
−1 0
2 4
c. x = 1 , y = 2
−2 −4
cosθ 1
cosθ 2
u x =cos θ 1 e 1 + cos θ 2 e 2 + ⋯ + cos θ n e n = .
cosθ n
angles:
Compute the norm and the direction cosines for the vector x = 2 .
Exercise:
Problem:
Prove that the direction cosines for any vector satisfy the equality
Equation:
2 2 2
cos θ 1 + cos θ 2 + ⋯ + cos θ n = 1.
What does this imply about the number of scalars needed to determine
a vector x ∈ R ? n
Exercise:
Problem:
find equations that give φ, θ , and ||x|| in terms of x , x , and x3, and
3 1 2
Exercise:
Problem:
Exercise:
Problem:
( cos θ , cos θ , ..., cos θ ) and ( cos φ , cos φ , ..., cos φ ). Prove
1 2 n 1 2 n
Exercise:
Problem:
2 2
result.
Linear Algebra: Projections
that the vectors are orthogonal. A quick look at the definition of angle
(Equation 12 from "Linear Algebra: Direction Cosines") leads to this
equivalent definition for orthogonality:
Equation:
3 −2
For example, in Figure 1(a), the vectors x = [ ] and y = [ ] are clearly
1 6
3 −2 0
mutually orthogonal, and the inner product between each pair is zero:
Equation:
Equation:
(x, z) = 3(0) + 1(0) + 0(4) = 0
Equation:
Orthogonality of Vectors
Exercise:
1 0
a. x = 0 , y = 1 ;
1 0
1 1
b. x = 1 , y = 1 ;
0 1
c. x = e 1, y = e3 ;
a −b
d. x = [ ] ,y=[ ]?
b a
We can use the inner product to find the projection of one vector onto
another as illustrated in Figure 2. Geometrically we find the projection of x
onto y by dropping a perpendicular from the head of x onto the line
containing y. The perpendicular is the dashed line in the figure. The point
where the perpendicular intersects y (or an extension of y) is the projection
of x onto y, or the component of x along y. Let's call it z.
Exercise:
Problem:
The vector z lies along y, so we may write it as the product of its norm ||z||
and its direction vector u :
y
Equation:
y
z = ||z||u y = ||z|| .
||y||
But what is norm ||z||? From Figure 2 we see that the vector x is just z, plus
a vector v that is orthogonal to y:
Equation:
x = z + v, (v, y) = 0.
But because z and y both lie along y, we may write the inner product (x, y)
as
Equation:
2
= ||z||||y||||u y || = ||z||||y||.
(x, y)
From this equation we may solve for ||z|| = and substitute ||z|| into
||y||
Equation 6 to write z as
Equation:
y
z = ||z||
||y||
(x,y) y (x,y)
= = y.
||y|| ||y|| (y,y)
Equation:
||x|| cos θ
z = y.
||y||
Orthogonal Decomposition. You already know how to decompose a vector
in terms of the unit coordinate vectors,
Equation:
of x onto e , but the set of unit coordinate vectors is not the only possible
k
(x, y) = 0.
2 2
= ||x|| + ||y|| .
w = (1)x + (1)y.
z = aw = (a)x + (a)y.
(w, x)
wx = x.
(x, x)
But there must be another component of w such that w is equal to the sum of
the components. Let's call the unknown component w . Then y
Equation:
w = wx + wy .
Equation:
(w, x)
wy = w − wx = w − x.
(x, x)
Interestingly, the way we have decomposed w will always produce w and x
2
(w,x) (w,x)
= (x, w) − 2
(x, x)
(x,x) (x,x)
2 2
(w,x) (w,x)
= −
(x,x) (x,x)
= 0.
Equation:
The following examples illustrate what the Euclidean norm, the l-norm, and
the sup-norm look like for typical vectors.
Example:
−3
i. ||x|| = [(−3) ;
2 2 2 1/2
+ (1) + (2) ] = (14)
ii. ||x|| 1
= (| − 3| + |1| + |2|) = 6 ; and
iii. ||x|| sup
=max (| − 3|, |1|, |2|) = 3.
Example:
x1
Figure 1 shows the locus of two-component vectors x = [ ] with the
x2
The next example shows how the l-norm is an important part of city life.
Example:
The city of Metroville was laid out by mathematicians as shown in Figure
2. A person at the intersection of Avenue 0 and Street −2 (point A) is
clearly two blocks from the center of town (point C). This is consistent
with both the Euclidean norm
Equation:
2
||A|| = √ 0 + (−2) = √ 4 = 2
2
But how far from the center of town is point B at the intersection of
Avenue-2 and Street 1? According to the Euclidean norm, the distance is
Equation:
2 2
||B|| = √ (−2) + (1) = √ 5.
Metroville, U.S.A.
While it is true that point B is √5 blocks from C , it is also clear that the
trip would be three blocks by any of the three shortest routes on roads. The
appropriate norm is the l-norm:
Equation:
B
1 || = (| − 2| + |1|) = 3.
1
Even more generally, we can define a norm for each value of p from 1 to
infinity. The so-called p-norm is
Equation:
p p
p 1/p
|Ix|| p = (|x 1 +|x 2 + ⋯ +|x n | ) .
Exercise:
Problem:
Show that the Euclidean norm is the same as the p-norm with p = 2
and that the 1-norm is the p-norm with p = 1. (It can also be shown
that the sup-norm is like a p-norm with p = ∞.)
DEMO 4.1 (MATLAB). From the command level of MATLAB, type the
following lines:
>> x = [1;3;-2;4]
>> y = [0;1;2;-0.5]
>> x - y
Check to see whether the answer agrees with the definition of vector
subtraction. Now type
>> a = -1.5
>> a * x
Check the answer to see whether it agrees with the definition of scalar
multiplication. Now type
>> x' * y
This is how MATLAB does the inner product. Check the result. Type
>> norm(y)
>> sqrt(y' * y)
>> norm(y,1)
>> norm(y' * y)
Now type your own MATLAB expression to find the cosine of the angle
between vectors x and y. Put the result in variable t. Then find the angle θ
by typing
Note:This module is part of the collection, A First Course in Electrical and Computer Engineering. The LaTeX
source files for this collection were created using an optical character recognition technology, and because of this
process there may be more errors than usual. Please contact us if you discover any errors.
The word matrix dates at least to the thirteenth century, when it was used to describe the rectangular copper tray, or
matrix, that held individual leaden letters that were packed into the matrix to form a page of composed text. Each
letter in the matrix, call it a , occupied a unique position (ij) in the matrix. In modern day mathematical parlance,
ij
a matrix is a collection of numbers arranged in a two-dimensional array (a rectangle). We indicate a matrix with a
boldfaced capital letter and the constituent elements with double subscripts for the row and column:
Matrix
In this equation A is an m x n matrix, meaning that A has m horizontal rows and n vertical columns. As an
extension of the previously used notation, we write A ∈ R to show that A is a matrix of size m x n with
mxn
∈ R . The scalar element a is located in the matrix at the i row and the j column. For example, a is
th th
aij ij 23
located in the second row and the third column as illustrated in [link].
The main diagonal of any matrix consists of the elements a . (The two subscripts are equal.) The main diagonal
ii
runs southeast from the top left corner of the matrix, but it does not end in the lower right corner unless the matrix
is square (∈ R m×m
).
The transpose of a matrix A ∈ R is another matrix B whose element in row j and column i is b = a for
m×n
ji ij
denoted by A'. A more intuitive way of describing the transpose operation is to say that it flips the matrix about its
main diagonal so that rows become columns and columns become rows.
Exercise:
2 1
Problem: If A ∈ R m×n
, then A T
∈?
–
. Find the transpose of the matrix A = 5 4 .
7 9
Matrix Addition and Scalar Multiplication. Two matrices of the same size (in both dimensions) may be added
or subtracted in the same way as vectors, by adding or subtracting the corresponding elements. The equation
C = A ± B means that for each i and j, c = a ± b . Scalar multiplication of a matrix multiplies each element
ij ij ij
ax 21 ax 22 ax 23 ... ax 2n
aX = ax 31 ax 32 ax 33 ... ax 3n .
⠇ ⠇ ⠇ ⠇
ax ml ax m2 ax m3 ... ax mn
Matrix Multiplication. A vector can be considered a matrix with only one column. Thus we intentionally blur the
distinction between R n×1
and Rn. Also a matrix can be viewed as a collection of vectors, each column of the
matrix being a vector:
Equation:
a 11 a l2 a 1n
| | |
a 21 a 22 a 2n
A = al a2 ... an = .
| | |
| | |
a m1 a m2 a mn
In the transpose operation, columns become rows and vice versa. The transpose of an n × 1 matrix, a column
vector, is a 1 ×n matrix, a row vector:
Equation:
x1
x2
T
x = ;x = [x 1 x 2 x n ].
|
xn
Now we can define matrix-matrix multiplication in terms of inner products of vectors. Let's begin with matrices
A ∈ R
m×n
and B ∈ R . To find the product AB, first divide each matrix into column vectors and row vectors
n×p
as follows:
Thus a is the i column of A and α is the j row of A. For matrix multiplication to be defined, the width of the
i
th T
j
th
first matrix must match the length of the second one so that all rows α and columns b have the same number of
T
i i
elements n. The matrix product, C = AB, is an m × p matrix defined by its elements as c = (α , b ). In words, ij i j
each element of the product matrix, c , is the inner product of the i row of the first matrix and the j column of
ij
th th
matrix (a scalar). The special significance is that x y is the inner product of x and y:
T
Thus the notation x y is often used in place of (x, y). Recall from Demo 1 from "Linear Algebra: Other Norms"
T
Another special case of matrix multiplication is the outer product. Like the inner product, it involves two vectors,
but this time the result is a matrix:
In the outer product, the inner products that define its elements are between one-dimensional row vectors of x and
one-dimensional column vectors of y , meaning the (i, j) element of A is x y .
T
i j
Exercise:
0 −2 1 −3
1 −1 2
a. A = [ ], B = 4 2 2 0 ;
3 0 5
2 −2 3 1
1 0 1 2 3 4
b. A = [ ], B = [ ] ;
0 1 5 6 7 8
1 −1 −1 0 3 6
c. A = 1 −1 1 , B = 1 4 7 .
1 1 1 2 5 8
There are several other equivalent ways to define matrix multiplication, and a careful study of the following
discussion should improve your understanding of matrix multiplication. Consider A ∈ R ,B ∈ R , and m×n n×p
Equation:
p n
p
m [C] = m [A][ ]n.
B
c ij = (α i , b j ) = Σ a ik b kj .
k=1
In pictures,
You will prove in Exercise 3 that we can also represent C on a column basis:
Equation:
n
cj = Σ a k b kj .
k=1
Finally, C can be represented as a sum of matrices, each matrix being an outer product:
Equation:
n
T
C = Σ ai βi
i=1
Example:
Let
Equation:
1 2 1
1 2 1 3
2 2 1
A = 2 1 2 4 , B = .
1 3 2
3 3 2 1
2 1 1
c ij = Σ a ik b kj
k=1
or
Equation:
(1 ⋅ 1 + 2 ⋅ 2 + 1 ⋅ 1 + 3 ⋅ 2) (1 ⋅ 2 + 2 ⋅ 2 + 1 ⋅ 3 + 3 ⋅ 1) (1 ⋅ 1 + 2 ⋅ 1 + 1 ⋅ 2 + 3 ⋅ 1)
C = (2 ⋅ 1 + 1 ⋅ 2 + 2 ⋅ 1 + 4 ⋅ 2) (2 ⋅ 2 + 1 ⋅ 2 + 2 ⋅ 3 + 4 ⋅ 1) (2 ⋅ 1 + 1 ⋅ 1 + 2 ⋅ 2 + 4. 1)
(3 ⋅ 1 + 3 ⋅ 2 + 2 ⋅ 1 + 1 ⋅ 2) (3 ⋅ 2 + 3 ⋅ 2 + 2 ⋅ 3 + 1 ⋅ 1) (3 ⋅ 1 + 3 ⋅ 1 + 2 ⋅ 2 + 1 ⋅ 1)
or
Equation:
12 12 8
C = 14 16 11 .
13 l9 l1
On a column basis,
Equation:
4
cj = Σ a k b kj
k=1
1 2 1 3 1 2 1 3 1 2 1
c1 = 2 1 + 1 2 + 2 1 + 4 2; c 2 = 2 2 + 1 2 + 2 3 + 4 1; c 3 = 2 1 + 1 1 + 2 2 +
3 3 2 1 3 3 2 1 3 3 2
C = [c 1 c 2 c 3 ]
(1 ⋅ 1 + 2 ⋅ 2 + 1 ⋅ 1 + 3 ⋅ 2) (1 ⋅ 2 + 2 ⋅ 2 + 1 ⋅ 3 + 3 ⋅ 1) (1 ⋅ 1 + 2 ⋅ 1 + 1 ⋅ 2 + 3 ⋅ 1)
C = (2 ⋅ 1 + 1 ⋅ 2 + 2 ⋅ 1 + 4 ⋅ 2) (2 ⋅ 2 + 1 ⋅ 2 + 2 ⋅ 3 + 4 ⋅ 1) (2 ⋅ 1 + 1 ⋅ 1 + 2 ⋅ 2 + 4. 1)
(3 ⋅ 1 + 3 ⋅ 2 + 2 ⋅ 1 + 1 ⋅ 2) (3 ⋅ 2 + 3 ⋅ 2 + 2 ⋅ 3 + 1 ⋅ 1) (3 ⋅ 1 + 3 ⋅ 1 + 2 ⋅ 2 + 1 ⋅ 1)
On a matrix-by-matrix basis,
Equation:
4
T
C = Σ ai βi
i=1
Equation:
1 2 1 3
C = 2 1 2 1 + 1 2 2 1 + 1 3 2 + 2 1 3 2 + 4 1 1 1
3 3 2 1
Equation:
1 ⋅ 1 1 ⋅ 2 1 ⋅ 1 2 ⋅ 2 2 ⋅ 2 2 ⋅ 1 1 ⋅ 1 1 ⋅ 3 1 ⋅ 2 3 ⋅ 2 3 ⋅ 1 3 ⋅ 1
= 2 ⋅ 1 2 ⋅ 2 2 ⋅ 1 + 1 ⋅ 2 1 ⋅ 2 1 ⋅ 1 + 2 ⋅ 1 2 ⋅ 3 2 ⋅ 2 + 4 ⋅ 2 4 ⋅ 1 4 ⋅ 1
3 ⋅ 1 3 ⋅ 2 3 ⋅ 1 3 ⋅ 2 3 ⋅ 2 3 ⋅ 1 2 ⋅ 1 2 ⋅ 3 2 ⋅ 2 1 ⋅ 2 1 ⋅ 1 1 ⋅ 1
Equation:
(1 ⋅ 1 + 2 ⋅ 2 + 1 ⋅ 1 + 3 ⋅ 2) (1 ⋅ 2 + 2 ⋅ 2 + 1 ⋅ 3 + 3 ⋅ 1) (1 ⋅ 1 + 2 ⋅ 1 + 1 ⋅ 2 + 3 ⋅ 1)
C = (2 ⋅ 1 + 1 ⋅ 2 + 2 ⋅ 1 + 4 ⋅ 2) (2 ⋅ 2 + 1 ⋅ 2 + 2 ⋅ 3 + 4 ⋅ 1) (2 ⋅ 1 + 1 ⋅ 1 + 2 ⋅ 2 + 4. 1)
(3 ⋅ 1 + 3 ⋅ 2 + 2 ⋅ 1 + 1 ⋅ 2) (3 ⋅ 2 + 3 ⋅ 2 + 2 ⋅ 3 + 1 ⋅ 1) (3 ⋅ 1 + 3 ⋅ 1 + 2 ⋅ 2 + 1 ⋅ 1)
as we had in each of the other cases. Thus we see that the methods are equivalent-simply different ways of
organizing the same computation!
Exercise:
Problem:
Prove that Equations 9, 11, and 13 are equivalent definitions of matrix multiplication. That is, if C = AB
where A ∈ R and B ∈ R
m×n
, show that the matrix-matrix product can also be defined by
n×p
Equation:
n
c ij = ∑ a ik b kj ,
k=1
and, if c is the k
k
th
column of C and a is the k
k
th
column of A, then
Equation:
n
c j = ∑ a k b kj .
k=1
Show that the matrix C may also be written as the ‚ "sum of outer products"
Equation:
n
T
C = ∑ ak βk .
k=1
Given A ∈ R m×n
,B ∈ R , and C ∈ R , for each of the following postulates, either prove that it is true
p×q r×s
Example:
Rotation
We know from the chapter on complex numbers that a complex number z 1
= x 1 + jy 1 may be rotated by angle θ
in the complex plane by forming the product
Equation:
jθ
z2 = e z1 .
When written out, the real and imaginary parts of z are 2
Equation:
z2 = (cos θ + j sin θ) (x 1 + jy 1 )
If the real and imaginary parts of z and z are organized into vectors z and z as in the chapter on complex
1 2 1 2
numbers, then rotation may be carried out with the matrix-vector multiply
Equation:
x2 cosθ −sinθ x1
z2 = [ ] = [ ] [ ].
y2 sinθ cosθ y1
cosθ −sinθ
We call the matrix R (θ) = [ ] a rotation matrix.
sinθ cosθ
Exercise:
Problem: Let R(θ) denote a 2 × 2 rotation matrix. Prove and interpret the following two properties:
a. R T
(θ) = R (−θ) ;
1 0
b. R T
(θ)R (θ) = R (θ)R
T
(θ) = [ ].
0 1
Linear Algebra: Solving Linear Systems of Equations
x 1 + x 2 = 85
x1 x2
=
1.2 1.5−1.2
The first step is to arrange each equation with all references to x in the
1
first column, all references to x in the second column, etc., and all
2
x 1 + x 2 = 85
0. 3x 1 − 1. 2x 2 = 0.
Exercise:
Problem:
Ax = b
1 1 xl 85
A = [ ], x = [ ], b = [ ].
0. 3 −1. 2 x2 0
(as long as a solution exists). Key ideas in the solution process are the
identity matrix and the inverse of a matrix.
When the matrix A is the 1 × 1 matrix a, the vector x is the l-vector x, and
the vector b is the l-vector b, then the matrix equation Ax = b becomes the
scalar equation
Equation:
ax = b.
−1
1x = a b.
Equation:
−1 −1
A (Ax) = A b
−1
Ix = A b.
1 0 0 ... 0
0 1 0 ... 0
0 0 1 ... 0
I = .
⋮ ⋮ ⋮ ⋱ ⋮
0 0 0 ... 1
It is clear that the identity matrix I and the inverse of a matrix, A , play a−1
key role in the solution of linear equations. Let's study them in more detail.
Equation:
1 0 0 0 0
0 1 0 0 0
I5 = 0 0 1 0 0 .
0 0 0 1 0
0 0 0 0 1
The subscript 5 indicates the size. In terms of the unit coordinate vectors e ,
i
| | |
In = e1 e2 ... en .
| | |
A = I n A.
Equation:
x = I n x.
x = ∑ xi ei .
i=1
This is a special case of one of the results you proved in Exercise 3 from
"Linear Algebra: Matrices". Figure 1 illustrates Equation 14 and shows how
the vector x can be broken into component vectors x e , each of which lies
i i
in the direction of one coordinate axis. The values of the x s are the
′
i
Exercise:
Problem:
Use Equation 13 and the rules for matrix multiplication to show that
x ∈ R may also be written as
n
Equation:
n
x = ∑ (x, e i )e i .
i=1
When the product of two numbers is 1 (the identity element), we say that
they are inverses of each other, like 2 and 0.5. Likewise, we say that two
square matrices are inverses of each other if their product is the identity
matrix:
Equation:
−1
AB = I ⇔ B = A .
An interesting and useful result is implied by this definition. Take the first
form of Equation 16 and multiply by B from the left:
Equation:
AB = I
⇒ B(AB) = BI
⇒ (BA)B = B
⇒ BA = I.
We emphasize that the inference made in the last step here is only valid
when B and A are square matrices. The result means that, even though
matrix multiplication is not commutative in general, we have a special case
where it is commutative. If A and B are inverses of each other, then
Equation:
AB = BA = I.
Exercise:
Problem:
Matrices that are not square do not have inverses. In fact, not all square
matrices have inverses. So it becomes an important issue to determine
which matrices do have inverses. If a matrix has an inverse, the inverse is
unique. If a square matrix has no inverse, it is called a singular matrix. The
determinant of a square matrix is a scalar computed from the numbers in
the matrix. It tells us whether a matrix will have an inverse or not. A matrix
is singular if and only if its determinant is zero.[footnote] In MATLAB, the
notation det(A) is used to compute the determinant. Whenever the matrix
A in Equation 4 is singular, it means one of two things about the system of
equations represented: either the equations are inconsistent and there is no
solution, or the equations are dependent and there are infinitely many
solutions.
It is not important now to understand how the determinant is defined and
computed from the elements of a matrix. In your more advanced courses
you will study the determinant in some detail.
matrix A exists with the property A A = I. The trick is to find it. Here
−1 −1
is one procedure.
x
[Ab][ ] = 0.
−1
The matrix [Ab] ∈ R is called the augmented matrix for the system
nx(n+1)
Equation:
x
[C m ⋯ C 2 C 1 AC m ⋯ C 2 C 1 b][ ] = 0.
−1
x
[I C m ⋯ C 2 C 1 b][ ] = 0,
−1
x = C m ⋯ C 2 C 1 b.
take A to I ; and
iii. when A is transformed to I , b will be transformed to x, so the solution
will appear as the last column of the transformed augmented matrix.
We may also conclude that the product of the matrices Ci must be the
inverse of A since A is the unique matrix for which A A = I. In
−1 −1
C m ⋯C C .
2 1
Example:
Consider the equation
Equation:
3 1 x1 6
[ ] [ ] = [ ]
2 4 x2 5
Equation:
A x = b.
3 1 6
[A b] = [ ].
2 4 5
Now if we could add −2/3 times the first row to the second row, we
would get 0 in the lower left corner. This is the first step in transforming A
to the identity I. We can accomplish this row operation with the matrix
Equation:
1 0
C1 = [ ]
−2/3 1
Equation:
3 1 6
C1 [A b] = [ ].
0 10/3 1
Now adding −3/10 times the new second row to the first row will
introduce 0 in the (1, 2) position, bringing us closer still to the identity.
Thus
Equation:
1 −3/10
C2 = [ ]
0 1
Equation:
3 0 57/10
C2 C1 [A b] = [ ].
0 10/3 1
1/3 0
C3 = [ ]
0 3/10
Equation:
1 0 19/10
C3 C2 C1 [A b] = [ ].
0 1 3/10
19/10
x = [ ].
3/10
1/3 0 1 −3/10 1 0
−1
A = C3 C2 C1 = [ ][ ][ ]
0 3/10 0 1 −2/3 1
The method we have just used, combined with a particular way of choosing
the C matrices, is called Gauss elimination. Gauss elimination requires less
i
You have entered the matrices A and b, which describe the problem. You
can now solve for x by finding the inverse of A and multiplying b:
>> x = inv(A) * b
>> x = A \ b
You should get the same answer. Now type the MATLAB code required to
compute Ax and to show Ax − b = 0.
Exercise:
Problem:
3 (x 1 − x 3 ) + 2 (x 2 − 1) − 6 = x 3
Equation:
4x 3 = 7x 2 − 5
Equation:
6 (x 1 + x 2 + 2) = x 3 + 1.
Linear Algebra: Circuit Analysis
In this section we use the linear algebra we have developed to find the
voltages and currents in a simple electrical circuit, such as the one shown in
Figure 1. There are many reasons why this might be necessary; in this
example we need to know the current flowing through the lamp to tell
whether or not it will glow. Too little current will have no visible effect; too
much current will cause the lamp to burn out. We will apply a few physical
laws relating the voltages and currents in a circuit, turn these laws into
systems of linear equations, and solve the equations for the voltages and
currents.
The analogy of water flowing through pipes can help you develop intuition
about electrical circuits. In this analogy, electrical current corresponds to the
flow rate of water. Voltage corresponds to the pressure that forces the water
to flow, and resistance is the friction of flow. A small pipe would impede
the flow of water more than would a large pipe, so the small pipe would
correspond to a higher resistance. While this analogy can be helpful, keep
in mind that electricity is not water. All analogies break down at some
point.
Voltage is measured in volts and is usually written as v (or e). Since voltage
is a difference in potential between two points (nodes), we can show it on a
circuit diagram with a +and a –sign to indicate which two nodes we are
comparing and which one of the nodes is considered negative. As with
current, the markings are for reference only and we may end up with a
negative value of v.
v = iR.
Ohm's Law
Example:
Ohm's law and Kirchhoff's current law are the only principles we need to
write equations that will allow us to find the voltages and currents in the
resistive circuit of Figure 1. We begin by choosing a reference node and
assigning variables to the voltages at every other node (with respect to the
reference node). These choices are shown in Figure 3.
The constant voltage source forces v to be exactly 5 volts higher than the
1
know). At the node labeled v are three paths for leaving current. The
2
current leaving through the 50 ohm resistor can be found by Ohm's law,
where the voltage across that resistor is v − v :
2 1
Equation:
v (v 2 − v 1 )
i 50 = =
R 50
For current leaving through the 300 ohm resistor, the voltage is v . Pay
2
careful attention to the sign; since we are interested in the current leaving
the node labeled v , Figure 4.14 indicates that to apply Ohm's law we
2
(v 2 − v 3 )
i 100 =
100
⇒ 6 (v 2 − v 1 ) + v 2 + 3 (v 2 − v 3 ) = 0
⇒ −6v 1 + 10v 2 − 3v 3 = 0.
Notice that when we wrote the equation for the node labeled v , the 2
variable v had a + sign each time it occurred in the equation, while the
2
others had a -sign. This is always the case, and watching for it can help you
avoid sign errors. Now we apply Kirchhoff's current law at the node
labeled v to get the equation
3
Equation:
(v 3 −v 2 ) v3
+ = 0
100 2
⇒ (v 3 − v 2 ) + 50v 3 = 0
⇒ 0v 1 − 1v 2 + 51v 3 = 0.
Equation:
1 0 0 vl 5
−6 10 −3 v2 = 0 ⋅
0 −1 51 v3 0
Exercise:
Problem:
v 1 = 5. 0000 volts
Equation:
v 2 = 3. 0178 volts
Equation:
v 3 = 0. 0592 volt.
We can determine the current flowing through the lamp from v to ground
3
The visible effect will, of course, depend on the lamp. Let us assume that
the specifications for our lamp indicate that 0.05 ampere or more is required
before it will glow, and more than 0.075 ampere will cause it to burn out. In
this case, our circuit would not make the lamp glow.
Exercise:
Problem:
(MATLAB) Write and solve equations for the circuit in Figure 4. What
are the voltages at the nodes labeled v through v ? What is the
1 4
A Resistive Network
Linear Algebra: Numerical Experiment (Circuit Design)
0 −2 R + 2 v3 0
function A = builda(R);
Now choose several values for R. For each choice, use your function
builda and solve the resulting matrix equation Av = b for the voltages.
Each time you choose a different R to build a different matrix A, check the
determinant of A to be sure the equations have a unique solution:
>> det(A)
Now add a column to your table for the current through the lamp i = v /2.
3
Add rows to your table until you have found a value of R for which the
lamp will glow. ( i needs to be between 0.05 and 0.075 ampere.)
Vector Graphics: Introduction
Acknowledgements
Fundamentals of Interactive Computer Graphics by J. D. Foley and A. Van
Dam, ©1982 Addison-Wesley Publishing Company, Inc., Reading,
Massachusetts, was used extensively as a reference book during
development of this chapter. Star locations were obtained from the share-
ware program “Deep Space” by David Chandler, who obtained them from
the “Skymap” database of the National Space Science Data Center.
Introduction
Pictures play a vital role in human communication, in robotic
manufacturing, and in digital imaging. In a typical application of digital
imaging, a CCD camera records a digital picture frame that is read into the
memory of a digital computer. The digital computer then manipulates this
frame (or array) of data in order to crop, enlarge or reduce, enhance or
smooth, translateor rotate the original picture. These procedures are called
digital picture processing or computer graphics. When a sequence of
picture frames is processed and displayed at video frame rates (30 frames
per second), then we have an animated picture.
Example:
Point P has coordinates (3, 1) in the (x, y) plane as shown in Figure 1.
π
Find the coordinates of the point P ′, which is rotated radians from P .
6
Rotating a Single Point in the (x, y) Plane
2 2
r = √ x + y = √ 10
−1 y
θ =tan ( ) ≈ 0. 3217 radian.
x
π
The rotated point P ′ has the same radius r, and its angle is θ + . We
6
now convert back to rectangular coordinates to find x′ and y′ for point P ′:
Equation:
′ π
x = r cos (θ + ) ≈ √ 10 cos (0. 8453) ≈ 2. 10
6
′ π
y = r sin (θ + ) ≈ √ 10 sin (0. 8453) ≈ 2. 37.
6
When the time comes to actually display a vector graphics image, it may be
necessary to alter the representation to match the display device. Personal
computer display screens are divided into thousands of tiny rectangles
called picture elements, or pixels. Each pixel is either off (black) or on
(perhaps with variable intensity and/or color). With a CRT display, the
electron beam scans the rows of pixels in a raster pattern. To draw a line on
a pixel display device, we must first convert the line into a list of pixels to
be illuminated. Dot matrix and laser printers are also pixel display devices,
while pen plotters and a few specialized CRT devices can display vector
graphics directly. We will let MATLAB do the conversion to pixels and
automatically handle cropping when necessary.
column vector
Equation:
xi
pi = [ ]
yi
Suppose there are n such endpoints in the entire image. Each point is
included only once, even if several lines end at the same point. We can
arrange the vectors P into a point matrix:
i
Equation:
G = [p1p2p3. . . pn]
x1 x2 x3 xn
= [ ].
y1 y2 y3 yn
Example:
Consider the list of points
Equation:
P1 = (0, 0)
P2 = (−1. 5, 5)
P3 = (4, 2. 3)
P4 = (4, −1).
0 −1. 5 4 4
G = [ ]⋅
0 5 2. 3 −1
Line Matrix. The next thing we need to know is which pairs of points to
connect with lines. To store this information for m lines, we will use a line
matrix, H ∈ R 2×m
. The line matrix does not store line locations directly.
Rather, it contains references to the points stored in G. To indicate a line
between points p and p , we store the indices i and j as a pair. For the k
i j
th
ik
hk = [ ].
jk
The order of i and j does not really matter since a line from p to p is the
i j
same as a line from p to p . Next we collect all the lines h into a line
j i k
matrix H :
Equation:
i1 i2 i3 ... im
H = [ ].
j1 j2 j3 ... jm
All the numbers in the line matrix H will be positive integers since they
point to columns of G. To find the actual endpoints of a line, we look at
columns i and j of the point matrix G.
Example:
To specify line segments connecting the four points of Example 1 into a
quadrilateral, we use the line matrix
Equation:
1 2 3 4
H1 = [ ].
2 3 4 1
Alternatively, we can specify line segments to form a triangle from the first
three points plus a line from P to P :
3 4
Equation:
1 2 3 3
H2 = [ ].
2 3 1 4
end
hold off
After you have saved the function file, run MATLAB and type the
following to enter the point and line matrices. (We begin with the
transposes of the matrices to make them easier to enter.)
>> G = [
0.6052 -0.4728;
-0.4366 3.5555;
-2.6644 7.9629;
-7.2541 10.7547;
-12.5091 11.5633;
-12.5895 15.1372;
-6.5602 13.7536;
-31.2815 -7.7994;
-38.8314 -9.9874;
-44.0593 -1.1537;
-38.8314 2.5453;
-39.4017 9.4594;
-39.3192 15.0932;
-45.9561 23.4158]
>> G = G'
>> H = [
1 2;
2 3;
3 4;
4 5;
4 7;
5 6;
8 9;
9 10;
10 11;
11 12;
12 13;
12 14]
>> H = H'
At this point you should use MATLAB's “save” command to save these
matrices to a disk file. Type
After you have saved the matrices, use the function VGRAPH1 to draw the
image by typing
≫ vgraph1(G,H)
The advantage of storing points and lines separately is that an object can be
moved and scaled by operating only on the point matrix G. The line
information in H remains the same since the same pairs of points are
connected no matter where we put the points themselves.
f irst point
last point
ki = .
f irst line
last line
Example:
Consider again Demo 1. We could group the points in G and the lines in H
into two objects with the matrix
Equation:
1 8
7 l4
K = .
1 7
6 12
The first column of K specifies that the first object (Ursa Minor) is made
up of points 1 through 7 and lines 1 through 6, and the second column of
K defines the second object (Ursa Major) as points 8 through 14 and lines
7 through 12.
Vector Graphics: Two-Dimensional Image Transformations
We now turn our attention to operating on the point matrix G to produce the
desired transformations. We will consider rotation scaling and translation
(moving) of objects. Rotation and scaling are done by matrix multiplication
with a square transformation matrix A. If we call the transformed point
matrix G , we have
new
Equation:
Rotation. We saw in the chapter on linear algebra that the matrix that
rotates points by an angle θ is
Equation:
cosθ −sinθ
A = R (θ) = [ ].
sinθ cosθ
When applied to the point matrix G, this matrix operator rotates each point
by the angle θ, regardless of the number of points.
Example:
We can use the rotation matrix to do the single point rotation of the
example from "Vector Graphics: Introduction". We have a point matrix
consisting of only the point (3, 1):
Equation:
3
G = [ ].
1
π
The necessary transformation matrix is R(θ) with θ = Then the rotated
6
point is given by
Equation:
π π
π cos −sin 3 2. 10
6 6
G new = R ( )G = [ ] ≈ [ ]⋅
π π
6 sin cos 1 2. 37
6 6
Equation:
sx 0
A = S (s x , s y ) = [ ].
0 sy
Write out the following matrices. Simplify and give numerical answers
to two decimal places:
π
a. R( ) ;
2
b. S(3, 2);
π
c. R(− ) ;
4
d. S(−1, 1).
Exercise:
Reflections
Problem: What does S(−1, 1) do? S(1, −1)?S(−1, −1)? S(1, 1)?
Exercise:
Problem:
0 −1. 5 4 4 π
Given G = [ ] and θ = find G new
.
=R(θ)G
0 5 2. 3 −1 3
1 1 2 2 1 2 3 4
G = [ ] ; H = [ ].
1 2 2 1 2 3 4 1
units to the right and 5 units down. We can write this in terms of the point
matrix as
Equation:
T
G new = G + b1
1
1 = .
⋮
1 1 π
G new = S ( , ) [R ( )G] = AG
2 2 3
where
Equation:
1 1 π
A = S( , )R ( )
2 2 3
1 π 1 π
cos ( ) − sin( )
2 3 2 3
= [ ] .
1 π l π
sin ( ) cos ( )
2 3 2 3
Example:
We can build an operator that stretches objects along a diagonal line by
composing scaling and rotation. We must
Figure 1 shows a square being stretched along a 45o line. The composite
operator that performs this directional stretching is
Equation:
2 2
scos θ + sin θ (s − 1)sinθcosθ
= [ ].
2 2
(s − 1)sinθcosθ cos θ + ssin θ
In the previous section we were able to combine rotation and scaling into a
single composite operation by matrix multiplication. Unfortunately,
translation cannot yet be included in the composite operator since we do it
by addition rather than by multiplication.
Example:
π
Suppose we wish to rotate the image G by about the point (−10, 10).
3
Our rotation matrix R(θ) always rotates about the origin, so we must
combine three transformations to accomplish this:
l0
For step (i), we have b 0 = [ ] and
−10
Equation:
T
G1 = G + b0 1 .
π T
= R( ) [G + b 0 1 ]
3
π π T
= R( )G + R ( )b 0 1 .
3 3
Equation:
T
G new = G2 − b0 1
π π T T
= R( )G + R ( )b 0 1 − b0 1
3 3
π π T
= R( )G + [(R ( ) − I)b 0 ]1 .
3 3
Equation:
T
G new = AG + b1 .
We will now move toward a modified representation of the image and the
operators by rewriting the last equation as
Equation:
G
G new = [Ab][ ]
T
1
π π
where in the example we had A = R( ) and b = (R ( ) − I)b 0 .
3 3
Exercise:
Problem: Show that, for any matrices A, B, C, D of compatible sizes,
Equation:
B
AB + CD = [A C] [ ].
D
G
The matrix [ T
] looks like
1
Equation:
x1 x2 xn
y1 y2 yn ,
1 1 1
G new A b G
[ ] = [ ] [ ].
T T T
1 O 1 1
In the new representation, each point in the image has a third coordinate,
which is always a 1. The homogeneous transformation is a 3 × 3 matrix,
Equation:
A b
Ah = [ ] ,
T
0 1
cosθ −sinθ 0
0 0 1
sx 0 0
S (s x , s y ) = 0 sy 0
0 0 1
1 0 tx
T (t x , t y ) = 0 1 ty .
0 0 1
Example:
The composite transformation to triple the size of an image and then move
it 2 units to the left is
Equation:
1 0 −2 3 0 0 3 0 −2
A = 0 1 0 0 3 0 = 0 3 0 .
0 0 l 0 0 1 0 0 1
3 0 0 1 0 −2 3 0 −6
B = 0 3 0 0 1 0 = 0 3 0 .
0 0 1 0 0 1 0 0 1
In the latter case, the distance of the translation is also tripled.
Exercise:
Problem:
x1 x2 x3 ... xn
yl y2 y3 ... yn
4×n
G = ∈ R .
z1 z2 z3 ... zn
1 1 1 ... 1
a 21 a 22 a 23 a 24
A = .
a 31 a 32 a 33 a 34
0 0 0 1
G new = AG.
Exercise:
Problem:
Equation 2?
Exercise:
Problem:
Write down the point matrix G for the unit cube (the cube with sides
of length 1, with one corner at the origin and extending in the positive
direction along each axis). Draw a sketch of the cube, numbering the
vertices according to their order in your point matrix. Now write down
the line matrix H to complete the representation of the cube.
sx 0 0 0
0 sy 0 0
S (s x , s y , s z ) =
0 0 sz 0
0 0 0 1
1 0 0 tx
0 1 0 ty
T (t x , t y , t z ) = .
0 0 1 tz
0 0 0 1
Exercise:
Problem:
Rotation may be done about any arbitrary line in three dimensions. We will
build up to the general case by first presenting the operators that rotate
about the three coordinate axes. R (θ) rotates by angle θ about the x-axis,
x
with positive θ going from the y-axis to the z-axis, as shown in Figure 2. In
a similar fashion, positive rotation about the y-axis using R (θ) goes from y
z to x, and positive rotation about the z-axis goes from x to y, just as in two
1 0 0 0
0 cosθ −sinθ 0
R x (θ) =
0 sinθ cosθ 0
0 0 0 1
cosθ 0 sinθ 0
0 1 0 0
R y (θ) =
−sinθ 0 cosθ 0
0 0 0 1
cosθ −sinθ 0 0
sinθ cosθ 0 0
R z (θ) = .
0 0 1 0
0 0 0 1
A more general rotation about any line through the origin can be
constructed by composition of the three fundamental rotations. Finally, by
composing translation with the fundamental rotations, we can build an
operator that rotates about any arbitrary line in space.
Directions of Positive Rotation
Example:
To rotate by angle φ about the line L , which lies in the x − y plane in
Figure 3, we would
The length of v is ||v||, and the direction can be specified in terms of the
three direction cosines ( cos θ , cos θ , cos θ ). The angle θ is measured
x y z x
between the vector v and the x-axis or, equivalently, between the vector v
and the vector e =[100] . We have
x
T
Equation:
(v, e x ) x
cos θ x = =
||v||||e x || ||v||
Equation:
y
cos θ y =
||v||
z
cos θz =
||v||
The vector
Equation:
cos θ x
u = cos θ y
cos θ z
cos θ x
cos θ z
Exercise:
The direction cosines are useful for specifying a line in space. Instead of
giving two points P and P on the line, we can give one point P plus the
1 2 1
direction cosines of any vector that points along the line. One such vector is
the vector from P to P .
1 2
x
Arc tangents. Consider a vector v = { } in two dimensions. We know
y
that
Equation:
y
tan θ =
x
for the angle θ shown in Figure 4. If we know x and y, we can find θ using
the arc tangent function
Equation:
−1
y
θ =tan ( ).
x
In MATLAB,
theta = atan(y/x)
−π π
Unfortunately, the arc tangent always gives answers between and
2 2
corresponding to points v in quadrants I and IV. The problem is that the
ratio−y
−x
is the same as the ratio − − −xA so quadrant III cannot be
distinguished from quadrant I by the ratio Likewise, quadrants II and IV
y
are indistinguishable.
theta = atan2(y,x)
will give the true angle θ −π and π in any of the four quadrants.
Example:
cosθ x
is the angle φ between the projection of u into the x − y plane and the y-
y
plane, and we need to know the angle φ in order to carry out this rotation.
y
First note that it is not the same as θ . From the geometry of the figure, we
y
can write
Equation:
cos θ x
tan φ y =
cos θ y
Exercise:
Problem:
Range. The projection plane is called the range of the projection. We will
assume for now that the projection plane passes through the origin. If it
does not, we may later compose the necessary translations with our
projection. Three points, not all in a line, are required to determine a plane.
We will take the origin as one of the points and suppose that the other two
points are the vectors r and r . From these vectors, we form the matrix
1 2
Equation:
R = [r 1 r 2 ],
P(R) 0
P h (R) = [ ].
T
0 1
Example:
Suppose we choose the x − y plane as our projection plane. Vectors r and 1
r can be any two points in the plane (besides the origin), so let's take
2
Equation:
1 1
r1 = 0 , r2 = 1
0 0
1 1
R = 0 1 .
0 0
1 0 0
= 0 1 0 .
0 0 0
In homogeneous coordinates,
Equation:
1 0 0 0
0 1 0 0
P h (R) = ⋅
0 0 0 0
0 0 0 1
Exercise:
Problem:
2 0
Example:
In the chapter on linear algebra you learned that the projection of w onto x
is given by
Equation:
(x, w)x
z =
(x, x)
−1
= x(x, x) (x, w)
−1
T T
= x(x x) (x w)
−1
T T
= [x(x x) x ]w
= P(x)w.
So we see that it can be written in the same way as the projection onto the
plane. The only difference is that the range is now one-dimensional and
specified by x in place of R.
where
Equation:
T
−l nn
T T
P (n) = n(n n) n =
2
||n||
As with the orthogonal projection, we can return to homogeneous
coordinates by
Equation:
E(R n) 0
E h (R, n) = [ ].
T
O 1
Exercise:
Problem:
a. P = P; E = E.
2 2
b. P R = R; ER = R.
c. En = 0; P n = 0. (First show that R T
n = 0 when n is
orthogonal to R.)
Display from Projections. Even after we have used a projection, the image
points are in three-dimensional homogeneous coordinates. How then do we
display them on a two-dimensional display? If we had chosen the x − y
plane as the range of our projection, we could let the output device
represent the x − y plane and ignore the z-coordinate of each point. The z-
coordinates of the projected image would all be 0 anyway since the
projected points would lie in the x − y plane. The fourth coordinate of 1
may also be ignored for display. But even if the projection plane is not the
x − y plane, we may perform a rotation to align the two planes and again
1 0 0 0
0 1 0 0
M (d) = .
0 0 0 0
−1
0 0 1
d
The first thing you should notice about the perspective projection M(d) is
that it violates the structure given in Equation 2 from "Vector Graphics:
Three-Dimensional Homogeneous Coordinates" by having the 4,3 position
1
equal to − rather than to 0. This means that the fourth coordinates will
d
not remain 1 in the new point matrix
Equation:
G new = M (d)G.
A Perspective Projection
This situation is interpreted to mean that the new point (x, y, z, w) must be
x y z
renormalized to ( , 1) before the operation is considered complete.
w w w
Renormalization adds another computational step to the image
transformation process. This is undesirable, but we are stuck with it if we
wish to include perspective projections in our repertoire of transformations.
Note that renormalization is a point-by-point process since w may be
different for each point.
How does renormalization affect composition of operators? We might
expect that, each time we perform an operation requiring renormalization,
we will be forced to stop and do the renormalization before going on with
other operations. In this respect we are fortunate: we may put off the
renormalization until all transformations are complete and renormalize once
just before displaying the image. Thus we are able to compose perspective
projections at will with other transformations.
Exercise:
Problem:
With Earth at the origin, we may specify the star positions for the Big and
Little Dippers in three-dimensional homogeneous coordinates. With light
years as our units, we have G =
T
To make use of this data, we need a function to display it. Enter and save
the following generalization of the function from Demo 1 in "Vector
Graphics: Two Dimensional Image Representation". Call it vhgraph.m.
Enter the point matrix given at rhe beginning of this section (and take its
transpose to put it in the usual form). Also enter the line matrix from Demo
1 in "Vector Graphics: Two Dimensional Image Representation". Save these
two matrices and try looking at the image
≫ save dip3d
≫ vhgraph(G,H)
Rx (θ) vhrx. m
Rz (θ) vhrz. m
M(d) vhm. m
Useful MATLAB functions for this task include zeros, eye, and diag.
Now build and use a perspective projection with viewpoint Earth and
projection plane at z = 1000 behind the dippers:
Oops! Now the image is too big; it's mostly off the screen. Scale it down
and have another look:
≫ A = vhs(.06,.06,.06) * A
≫ vhgraph(G,H,A)
≫ save dip3d
Experiment with scale and rotation about the z-axis. For example, try
≫ vhgraph(G,H,vhrz(pi/2) * A)
The two-dimensional star positions given in Demo 1 in "Vector Graphics:
Two Dimensional Image Representation" were obtained from the three-
dimensional positions with the composite operator A you are now using. To
compare the two, type
≫ Gnew = A * G
≫ for i = 1:14
Gnew(;,i) = Gnew(:,i)/Gnew(4,i);
end
≫ Gnew
function v = starxyz(rah,ram,decd,decm,dist)
% starxyz is the cartesian coordinates of a star w
hose
% spherical coordinates ( e.g. from a star catalog
) are
%
% rah right ascension hours
% ram right ascension minutes
% decd declination degrees
% decm declination minutes (should be
negative
% if decd is negative)
% dist distance (light years)
%
phi = (pi/180) * (decd + decm/60);
theta = (pi/12) * (rah + ram/60);
r = dist;
v = [r * cos(phi) * cos(theta); -
r * cos(phi) * sin(theta);
r * sin(phi)];
Have you ever wondered what the constellations would look like from other
places in the galaxy? We will soon see the answer. First we will view the
dippers from Alpha Centauri, the nearest star, whose coordinates are
We will look toward the centroid of the fourteen stars in the dippers, located
at
Now we want to look toward the centroid of the dippers from Alpha
Centauri. To do so, enter the vectors for the two points of interest and
construct the view like this:
≫ acentauri = [-1.5680; 1.3157; -3.6675]
≫ centroid = [-26.3632; 12.8709; 100.4714]
≫ A = vhview(acentauri,centroid)
≫ vhgraph(G,H,A)
≫ title('From Alpha Centauri')
The farther we move from Earth, the more distorted the dippers will look in
general. It should be easy now to view them from any desired location. Just
choose a viewpoint, recalculate the composite operator for that viewpoint
using vhview, and use vhgraph. Follow this procedure to view the
dippers from each of the stars in the following list. You will need to use
starxyz first to convert their coordinates.
Right Distance
Star Ascension Declination (ly)
Alpha
14h 40m -60° 50' 4.2
Centauri
Table 1 is a six-row and four-column table with the first row as a header,
the first column describing different stars, and the values in the second
through fourth columns describing the corresponding right ascension,
declination, and distance for each star.
Of course, star viewing is not the only application of vector graphics. Do
some experiments with the unit cube (see Exercise 2 from "Vector
Graphics: Three-Dimensional Homogeneous Coordinates"). View the cube
from location (4,3,2) looking toward the origin using the procedure just
outlined for stars. You may need to adjust the scaling to get a meaningful
view.
Filtering: Introduction
Note:This module is part of the collection, A First Course in Electrical and Computer Engineering.
The LaTeX source files for this collection were created using an optical character recognition
technology, and because of this process there may be more errors than usual. Please contact us if you
discover any errors.
Introduction
A filter is any device that passes material, light, sound, current, velocity, or information according to
some rule of selectivity. Material (or mechanical) filters are commonplace in your everyday life:
i. coffee filters pass flavored water while filtering out coffee grounds;
ii. Goretex fibers pass small, warm perspiration droplets while filtering out large, cool droplets of
rain or snow;
iii. fiberglass strands in a furnace filter pass warm air while filtering out particles of dirt and dust;
iv. a centrifuge retains material of low density while spinning out (or filtering out) material of high
density; and
v. an electrostatic precipitator filters out dust and other effluents by attaching charge to them and
using an electric field to move the charged particles to a high potential drain.
The first three of these examples selectively pass material according to size; the last two selectively
pass material according to its mass density.
i. UV filters on camera lenses and eyeglasses that pass light in the range of visible wavelengths
while blocking light in the invisible (but damaging) ultraviolet range;
ii. polaroid lenses that pass light that is randomly polarized while blocking out glare that is linearly
polarized;
iii. green fabrics that reflect green light and absorb other colors;
iv. red taillights that pass light in the long wavelength red range and reflect light in the short
wavelength violet range (look at the inside of your taillights to see violet); and
v. glacial ice that absorbs all but the blue wavelengths so that it appears blue.
Exercise:
Problem: List as many examples of natural and man-made sound filters as you can.
Satellite Television. Among current filters, the tuner in a super-heterodyne receiver is, perhaps, the
first example that comes to mind. But satellite TV filters are another fascinating example. A typical C-
band satellite has twelve transponders (or repeaters), each of which transmits microwave radiation in a
personalized 36 MHz band. (The abbreviation MHz stands for megahertz, or 10 Hz, or 10 cycles per
6 6
second. Other common abbreviations are Hz for 1 Hz, kHz for 10 Hz, and GHz for 10 Hz.) Each
3 9
transponder actually transmits two channels of information, one vertically polarized and one
horizontally polarized. There is an 8 MHz guard band between each band, and the vertical and
horizontal channels are offset by 20 MHz. The transmission scheme for the 24 channels is illustrated in
Figure 1. The entire transmission band extends over 540 MHz, from 3. 7 × 10 Hz to 4. 24 × 10 Hz.
9 9
The satellite receiver has two different microwave detectors, one for vertical and one for horizontal
polarization, and a microwave tuner to tune into the microwave band of interest.
Exercise:
Problem: Check that the transmission scheme of Figure 1 consumes 540 MHz of bandwidth.
Exercise:
Problem:
List as many examples of natural and man-made devices for velocity filtering as you can.
An Aside on Hertz and Seconds. The abbreviation Hz stands for hertz, or cycles/second. It is used to
describe the frequency of a sinusoidal signal. For example, house current is 60 Hz, meaning that it has
60 cycles each second. The inverse of Hz is seconds or, more precisely, seconds/cycle, the period of 1
cycle. For example, the period of 1 cycle for house current is 1/60 second. When we are dealing with
sound, electricity, and electromagnetic radiation, we need a concise language for dealing with signals
and waves whose frequencies range from 0 Hz (called DC or direct current) to 10 Hz (visible light).
18
Table 1 summarizes the terms and symbols used to describe the frequency and period of signals that
range in frequency from 0 Hz to 10 Hz.
12
Frequency Period
battery current:
0 Hz
Hz hertz 1 Hz sec second 1 sec
house current:
60 Hz
clock
106
MHz megahertz µsec microsecond 10-6sec frequencies in
Hz
microcomputers
microwave
109 radiation for
GHz gigahertz nsec nanosecond 10-9sec
Hz satellite
communication
Numerical Filters. Rather amazingly, these ideas extend to the domain of numerical filters, the topic of
this chapter. Numerical filters are just schemes for weighting and summing strings of numbers. Stock
prices are typically averaged with numerical filters. The curves in Figure 2 illustrate the daily closing
average for Kellogg's common stock and two moving averages. The 50-day moving average is obtained
by passing the daily closing average through a numerical filter that averages the most current 50 days'
worth of closing averages. The 200-day moving average for the stock price is obtained by passing the
daily closing prices through a numerical filter that averages the most current 200 days' worth of daily
closing averages. The daily closing averages show fine-grained variation but tend to conceal trends.
The 50-day and 200-day averages show less fine-grained variation but give a clearer picture of trends.
In fact, this is one of the key ideas in numerical filtering: by selecting our method of averaging, we can
filter out fine-grained variations and pass long-term trends (or vice versa), or we can filter out periodic
variations and pass nonperiodic variations (or vice versa). Figure 2 illustrates that moving averages
typically lag increasing sequences of numbers and lead decreasing sequences. Can you explain why?
We will call any algorithm or procedure for transforming one set of numbers into another set of
numbers a numerical filter or digital filter. Digital filters, consisting of memories and arithmetic logic
units (ALUs), are implemented in VLSI circuits and used for communication, control, and
instrumentation. They are also implemented in random–or semicustom–logic circuits and in
programmable microcomputer systems. The inputs to a digital filter are typically electronic
measurements that are produced by A/D (analog-to-digital) conversion of the output of an electrical or
mechanical sensor. The outputs of the filter are “processed,” “filtered,” or “smoothed” versions of the
measurements. In your more advanced courses in electrical and computer engineering you will study
signal processing and system theory, assembly language programming, microprocessor system
development, and computer design. In these courses you will study the design and programming of
hardware that may be used for digital filtering.
Dow-Jones Averages (Adapted from the New York Stock Exchange, Daily Graphs,
William O'Neil and Co., Inc., Los Angeles, California)
Filtering: Simple Averages
The simplest numerical filter is the simple averaging filter. This filter is
defined by the equation
Equation:
N
1
x = ∑ un .
N
n=1
The filter output x is the average of the N filter inputs u , u , ... , uN. These
1 2
inputs may be real or complex numbers, and x may be real or complex. This
simple averaging filter is illustrated in Figure 1.
Example:
If the averaging filter is excited by the constant sequence
u = u = ⋯ = u
1 2 N = u, then the output is
Equation:
N
1
x = ∑ u = u.
N
n=1
The output is, truly, the average of the inputs. Now suppose the filter is
excited by the linearly increasing sequence
Equation:
u n = n, n = 1, 2, ..., N .
1 1 1
x = (x 1 + x N ) + (x 2 + x N −1 ) + ⋯ + (x N /2 + x (N /2)+1 ).
N N N
N
Each pair-sum in parentheses equals N + 1 , and there are such pair-
2
sums, so the average is
Equation:
1 N N + 1
x = (N + 1) = .
N 2 2
Exercise:
Problem:
N
1
Write x = ∑n as a sum of pair-sums for N odd. What does x
N
n=1
equal?
General Sum Formula. Suppose the input to the simple averaging filter is
the polynomial sequence
Equation:
k
un = n , n = 1, 2, ..., N
where k is a non-negative integer such as k = 0, 1, 2, .... The output of the
filter is
Equation:
N
(k) 1 k
x = ∑n .
N
N
n=1
(k)
We rewrite x as x to remind ourselves that we are averaging N numbers,
N
Equation:
8
(2) 1 2
1
x = ∑n = (1 + 4 + 9 + ⋯ + 64).
8
8 8
n=1
(k) (k)
Rather than study the average x N
, we will study the sum N x N
and divide
by N at the very end:
Equation:
N
(k) (k) k
S = Nx = ∑n .
N N
n=1
(k)
The sum S N
may be rewritten as the sum
Equation:
(k) N −1 k k
S = ∑ n + N
N n=1
(k) k
= S + N .
N −1
(k)
This result is very important because it tells us that the sum S N
, viewed as
(k)
a function of N , obeys a recursion in which S N
is just the sum using one
(k)
less input, namely, S N −1
, plus N . Now, since polynomials are the most
k
(k)
general functions that obey such recursions, we know that s N
must be a
polynomial of order k + 1 in the variable N :
Equation:
(k) 2 k+1
s = a0 + a1 N + a2 N + ⋯ + a k+1 N .
N
Let's check to see that this polynomial really can obey the required
(k)
recursion. First note that S is the following polynomial:
N −1
Equation:
(k) k+1
s = a 0 + a 1 (N − 1) + ⋯ + a k+1 (N − 1) .
N −1
0
)N (−1) + ⋯
k+1 0 k+1
1
k 1
Equation:
(k) (k) k
S − S = c0 + c1 N + ⋯ + ck N .
N N −1
Equation:
( )
(k)
(N = 1) S = a 1 + ⋯ + a k+1
1
(k) k+1
(N = 2) S = 2a 1 + ⋯ + 2 a k+1
2
(k) k+1
(N = 3) s = 3a 1 + ⋯ + 3 a k+1
3
⋮ ⋮
(k) k+1
(N = k) S = ka 1 + ⋯ + k a k+1
k
(k) k+1
(N = k + 1) S = (k + 1)a 1 + ⋯ + (k + 1) a k+1 .
k+1
Using the linear algebra we learned earlier, we may write these equations as
the matrix equation
Equation:
(k)
l 1 ... 1 ⎡s ⎤
⎡ ⎤ ⎡a 1 ⎤
1
k+1 (k)
2 4 ... 2 a2 S
2
⋮ ⋮ ⋮ = .
⋮ ⋮
2 k+1
k k ... k
⎣ 2 k+1 ⎦⎣ ⎦
(k + 1) (k + 1) ... (k + 1) a k+1 (k)
⎣S ⎦
k+1
The terms on the right-hand side of the equal sign are “initial conditions”
(k)
that tell us how the sum S begins for N = 1, 2, ..., k + 1. These initial
N
(k)
conditions must be computed directly. (For example, S = 1 + 2 .) 2
k k
Example:
When k = 2, we have the following equation for the coefficients a 1, a2 ,
(2)
and a in the polynomial S = a N + a N + a N :
3 N 1 2
2
3
3
Equation:
Exercise:
Problem:
Solve for a
S
S
(2)
N
(2)
Exercise:
Problem:
− S
⎢⎥
⎡
1,
= a1 N + a2
(2)
N −1
1
3
1
9
1
27
a2 , a3
= N
N
⎦⎣
a
⎤⎡ 1 ⎤
a2
a3
⎦
=
⎡
⎣
1
2
1
+2
2
2
.
2
+ a N 3obeys the recursion
3
(k)
for the averages x for k = 1, 2, ..., 5. Evaluate these formulas for
N = 2, 4, 8, and 16.
N
(k)
un = a
n
, n = 0, 1, 2, ..., N − 1,
we say that the input is exponential (or geometric). Typical sequences are
illustrated in Figure 6.5 for a = 0. 9, a = 1, and a = 1. 1. Don't let it throw
you that we have changed the index to run from 0 to N − 1 rather than
from 1 to N . This change is not fundamentally important, but it simplifies
our study. The sum of the inputs is
Equation:
+ 2
2
2
+ 3
⎤
2⎦
=
⎡
⎣
1
14
⎦
⎤
⋅
N −1
n
SN = ∑ a .
n=0
Exponential Sequences
Equation:
N −1 n+1 N k
aS N = ∑ a = ∑ a
n=0 k=1
N −1 N
= ∑ ak + a − 1
k=0
N
= SN + a − 1.
Equation:
N
1 − a
SN = , a ≠ 1.
1 − a
This formula, discovered already in the chapter covering the functions e x
Equation:
N
1−a
, a ≠ 1
1−a
SN = {
N, a = 1.
Exercise:
Problem:
N −1
1
Evaluate S N = ∑ a
n
and X N = SN for a = 0. 9, 1, and 1.1 and
N
n=0
N −1
Equation:
N −1
S N = S N −1 + a .
SN = ∑ un
n=0
S N = S N −1 + u N −1 .
This means that when summing numbers you may “use them and discard
them.” That is, you do not need to read them, store them, and sum them.
x = ∑ wn un
n=1
Equation:
N
∑ w n = 1.
n=1
1
When w n = then x is the simple average studied in the section on
N
"Simple Averages".
Example:
There are many windows that are commonly used in engineering practice.
For N odd, the standard triangular window is
Equation:
2
N + 1
wn =
N + 1
2
(1−
Equation:
Exercise:
1
w n = α(1 − β|
N
N + 1
Triangular Window
2
N + 1
∣
2
N + 1
N + 1
− n |); α, β > 0,
2
− n |).
(N +1)/2
by
N odd.
Problem:
2
α = = β is a valid solution. Propose another solution that you
N + 1
like.
Exercise:
Problem:
You are taking three 3-credit courses, one 5-credit course, and one 2-
credit course. Write down the weighted average for computing your
GPA in a system that awards 4.0 points for an A, 3. 0 points for a B, ...
, and (horrors!) 0 points for an F .
Filtering: Moving Averages
The most current input, u , is weighted by w ; the next most current input,
n 0
Example:
1
When the weights w 0
, w 1 , ..., w N −1 are all equal to , then the moving
N
average x is a “simple moving average”:
n
Equation:
1
xn = [u n + u n−1 + ⋯ + u N −1 ].
N
This is the same as the simple average, but now the simple average moves
along the sequence of inputs, averaging the N most current values.
Exercise:
Problem:
N −1
1
Evaluate the moving average x n = u n−k for the inputs
N
k=0
0, n < 0
a. u n =
u, n ≥ 0;
0, n ≤ 0
b. u n =
n, n > 0.
the sequence
Equation:
0, n < 0
un =
n
a , n ≥ 0.
Example:
When the weights w equal w a for n = 0, 1, ..., N
n 0
n
− 1 , then the
moving average x takes the form
n
N −1
xn = w0
k
a u n−k .
k=0
When a < 1, then un is weighted more heavily than u when a > 1 n−(N −1);
,un−(N −1)
is weighted more heavily than un ; when a = 1, u is weighted n
the same as u .
n−(N −1)
Exercise:
Problem:
w0 a
n
(n = 0, 1, ..., N − 1) is a valid window (i.e., wn = 1 ).
n=0
Exercise:
Problem:
N −1
sequence u is n
Equation:
n
b , n ≥ 0
un =
0, n < 0.
Suppose we try to extend our method for computing finite moving averages
to infinite moving averages of the form
Equation:
∞
xn = ∑ w k u n−k
k=0
In general, this moving average would require infinite memory for the
weighting coefficients w , w , ... and for the inputs u , u , ....
0 1 n n−1
infinitely fast to compute the infinite moving average in finite time. All of
this is clearly fanciful and implausible (not to mention impossible). But
what if the weights take the exponential form
Equation:
0, k < 0
wk = {
k
w0 a , k ≥ 0?
wk = w0 , k = 0
aw k−1 k ≥ 1.
w k − aw k−1 = 0, k ≥ 1.
Let's now manipulate the infinite moving average and use the recursion for
the weights to see what happens. You must follow every step:
Equation:
∞
xn = ∑ w k u n−k
k=0
∞
= ∑ w k u n−k + w 0 u n
k=1
∞
= ∑ aw k−1 u n−k + w 0 u n
k=1
∞
= a∑ w m u n−1−m + w 0 u n
m=0
= ax n−1 + w 0 u n .
This result is fundamentally important because it says that the output of the
infinite exponential moving average may be computed by scaling the
previous output x n−1 by the constant a, scaling the new input u by w ,
n 0
and adding. Only three memory locations must be allocated: one for w , 0
one for a, and one for x . Only two multiplies must be implemented: one
n−1
for axn−1 and one for w u . A diagram of the recursion is given in Figure
0 n
1. In this recursion, the old value of the exponential moving average, x , n−1
Exercise:
Problem:
k
xn = a u n−k .
k=0
Equation:
0, n < 0
un = {
u, n ≥ 0.
Plot your result versus n.
Exercise:
Equation:
0, n < 0
wn = {
n
a w0 , n ≥ 0
1, n = 0
un = δn = {
0, n ≠ 0.
= wn .
Unit Pulse Sequence
(Note that δ = 0 unless n = k.) So the unit pulse sequence may be used
n−k
Exercise:
Problem:
Find the unit pulse response for the finite moving average
N −1
n < 0, 0 ≤ n ≤ N − 1 , and n ≥ N .
Exercise:
Problem:
n
= ∑ hk .
k=0
The unit step response is just the sequence of partial sums of the unit pulse
response.
Exercise:
Problem:
Find the unit step response for the finite moving average filter
N −1
1
where w k = for k = 0, 1, ..., N − 1 .
N
Exercise:
Problem:
(i) e represents (or codes) cos kθ. The real part of the sequence e
jkθ jkθ
is
the cosinusoidal sequence cos kθ:
Equation:
jkθ
Re[e ] =cos kθ.
same way that the continuous-time phasor e codes cos ωt. If the moving
jωt
average filter
Equation:
∞
x n = ∑ h k u n−k
k=0
has real coefficients, we can get the response to a cosinusoidal sequence by
taking the real part of the following sum:
Equation:
∞
xn = ∑ h k cos (n − k)θ
k=0
∞ j(n−k)θ
= Re[∑ hk e ]
k=0
jnθ ∞ −jkθ
= Re[e ∑ hk e ].
k=0
−jkθ
∑ hk e
k=0
is called the complex frequency response of the filter and is given the
symbol
Equation:
∞
jθ −jkθ
H (e ) = ∑ hk e .
k=0
jθ
jnθ jθ jargH (e )
= Re[e H (e ) e ]
jθ jθ
= H (e )| cos [nθ+ arg H (e )].
T
∣
This remarkable result says that the output is also cosinusoidal, but its
amplitude is H (e ) rather than 1, and its phase is argH (e ) rather than
jθ
e
jkθ
k
= e
jωt
jωt
t=kT
θ = ωT .
= e
jωkT
e
jωt
j[ω+m(2π/T )]t
is increased to ω + m(
jkθ
t=kT
:
= e
j(ωkT +km2π)
= e
“hide
under the same alias” when viewed through the sampling operation. That is,
the sampled-data phasor cannot distinguish the frequency ω from the
frequency ω + m
2π
T
)
jkθ
, then the
j[ω+m(2π/T )]t
jωt
jθ
jkθ
at
2π 1 Ω
T ≤ ; ≥
Ω T 2π
1
This rule says that you must sample signals at a rate ( ) that exceeds the
T
Ω
bandwidth of the signal.
2π
Example:
Let's pass the cosinusoidal sequence u k = cos kθ through the finite
moving average filter
Equation:
N −1
xn = ∑ h k u n−k
k=0
1
hk = k = 0, 1, ..., N − 1.
N
−jN θ
1 1−e
= −jθ
N 1−e
(Do you see your old friend, the finite sum formula, at work?) Let's try to
manipulate the result into a more elegant form:
Equation:
Equation:
H (e
jθ
|H (e
)
jθ
1
)|=
jθ
N
−j(N /2)θ
∣
−j(θ/2)
−j[(N −1)/2]θ
is
sin (
[e
[e
sin (
plotted in Figure 4.
This result shows that the moving average filter is frequency selective,
passing low frequencies with gain near 1 and high frequencies with gain
near 0.
Exercise:
j(θ/2)
2
−e
θ)
−e
sin(
sin(
θ)
jθ
−j(N /2)θ
−j(θ/2)
)
N
.
θ)
θ)
]
]
equals 1; at θ =
2π
N
N
1 sin ( θ)
jθ −j[(N −1)/2]θ 2
H (e ) = e .
1
N sin ( θ)
2
Exercise:
Problem:
1
Choose the filter length N for the filter h k = , k = 0, 1, ..., N − 1 ,
N
1
so that a 60 Hz cosine, sampled at the rate = 180 , is perfectly
T
zeroed out as it comes through the filter.
Exercise:
Problem:
when
Equation:
N
1 sin ( θ)
jθ −j[(N −1)/2]θ 2
H (e ) = e .
1
N sin ( θ)
2
k
xn = a u n−k; a = 0. 98.
k=0
1. Write out a few terms of the sum to show how the filter works.
2. Write xn as a recursion and discuss the computer memory required to
implement the filter.
3. Compute the complex frequency response H e for the filter. jθ
2π
steps of Do this for two values of a, namely, a = 0. 98 and
64
a = −0. 98 . Explain your findings.
5. Write a MATLAB program to pass the following signals through the
filter when a = 0. 98:
a. u n = δn
b. u n = ξn
2π
c. u n = ξ n cos n
64
2π
d. u n = ξ n cos n
32
2π
e. u n = ξ n cos n
16
2π
f. u n = ξ n cos n
8
2π
g. u n = ξ n cos n
4
2π
h. u n = ξ n cos n .
2
Plot the outputs for each case and interpret your findings in terms of the
complex frequency response H e . Repeat step 5 for a = −0. 98.
jθ
We develop some ad hoc tree codes for representing information and then
develop Huffman codes for optimizing the use of bits. Hamming codes add
check bits to a binary word so that errors may be detected and corrected.
The numerical experiment has the students design a Huffman code for
coding Lincoln's Gettysburg Address.
Introduction
It would be stretching our imagination to suggest that Sir Francis had digital
audio on his minde (sic) when he wrote the prophetic words
"Sir Francis Bacon, 1623 ...a man may express and signifie the intentions of
his minde, at any distance... by... objects... capable of a twofold difference
onely. "
Nonetheless, this basic idea forms the basis of everything we do in digital
computing, digital communications, and digital audio/video. In 1832,
Samuel F. B. Morse used the very same idea to propose that telegram words
be coded into binary addresses or binary codes that could be transmitted
over telegraph lines and decoded at the receiving end to unravel the
telegram. Morse abandoned his scheme, illustrated in Figure 1, as too
complicated and, in 1838, proposed his fabled Morse code for coding letters
(instead of words) into objects (dots, dashes, spaces) capable of a threefold
difference onely (sic).
Generalized Coder-Decoder
word w plus parity check bits for detecting and correcting errors; in digital
i
audio systems, where the “address a " is a stretch of digitized and coded
i
In this chapter we outline the main ideas in binary coding and illustrate the
role that binary coding plays in digital communications. In your subsequent
courses in electrical and computer engineering you will study integrated
circuits for building coders and decoders and mathematical models for
designing good codes.
Binary Codes: The Communication Paradigm
to modulate the signal A cos (ωt + φ). Each possible string of five bits has
its own personalized phase, φ, and this phase can be determined at the
receiver. The signal A cos (ωt + φ) is an analog signal that may be
transmitted over a channel (such as a telephone line, a microwave link, or a
fiber-optic cable). The channel has a finite bandwidth, meaning that it
distorts signals, and it is subject to noise or interference from other
electromagnetic radiation. Therefore transmitted information arrives at the
demodulator in imperfect form. The demodulator uses filters matched to the
modulated signals to demodulate the phase and look up the corresponding
bit stream. The channel decoder converts the coded bit stream into the
information bit stream, and the source decoder looks up the corresponding
symbol. This sequence of steps is illustrated symbolically in Figure 7.3.
subscript i:
Equation:
s 0 ∼ 000 = a0
s 1 ∼ 001 = a1
s 6 ∼ 110 = a6
s 7 ∼ 111 = a7 .
Octal Codes. When the number of symbols is large and the corresponding
binary codes contain many bits, then we typically group the bits into groups
of three and replace the binary code by its corresponding octal code. For
example, a seven-bit binary code maps into a three-digit octal code as
follows:
Equation:
0000000 ∼ 000
0000001 ∼ 001
0100110 ∼ 046
101111 ∼ 137
1111111 ∼ 177.
The octal ASCII codes for representing letters, numbers, and special
characters are tabulated in Table 1.
Exercise:
'00x ␀ ␁ ␂ ␃ ␄ ␅ ␆ ␇
'01x ␈ ␉ ␊ ␋ ␌ ␍ ␎ ␏
'02x ␐ ␑ ␒ ␓ ␔ ␕ ␖ ␗
'03x ␘ ␙ ␚ ␛ ␜ ␝ ␞ ␟
'04x ␠ ! " # $ % & '
'05x ( ) * + , - . /
'06x 0 1 2 3 4 5 6 7
'10x @ A B C D E F G
'11x H I J K L M N O
'12x P Q R S T U V W
'13x X Y Z [ \ ] ^ _
'14x ` a b c d e f g
'15x h i j k l m n o
'16x p q r s t u v w
'17x x y z { | } ~ ␡
Octal ASCII Codes (from Donald E. Knuth, The TEXbook, ©1986 by the
American Mathematical Society, Providence, Rhode Island p. 367, published
by Addison-Wesley Publishing Co.)
Exercise:
Problem:
2V
into little voltage cells of size A and approximate the voltage in each cell
M
by its midpoint. This scheme is illustrated in Figure 1. In the figure, the cell
2 V pV Δ
C is defined to be the set of voltages that fall between i and –
i −
M M
V
2V
i– MΔ + M
A
:
Equation:
2V 0 V0 2V 0 V0
C i = {V : i. − < V ≤ i + }.
M M M M
2V 0
Q (V ) = i , if V ∈ Ci .
M
2 V0
That is, V is replaced by the quantized approximation i whenever V lies in
–
M
2V
cell C . We may represent the quantized values i 0 with binary codes by
i
–
M
Example:
If M = 8, corresponding to a three-bit quantizer, we may associate quantizer
cells and quantized levels with binary codes as follows:
Equation:
2V 0
V ∈ C −3 ⇒ V −3 = (−3) ∼ 111
8
2V 0
V ∈ C −2 ⇒ V −2 = (−2) ∼ 110
8
2V 0
V ∈ C −1 ⇒ V −1 = (−1) ∼ 101
8
V ∈ C0 ⇒ V 0 = 0 ∼ 000
2V 0
V ∈ C1 ⇒ V 1 = (1) ∼ 001
8
2V 0
V ∈ C2 ⇒ V 2 = (2) ∼ 010
8
2V 0
V ∈ C3 ⇒ V 3 = (3) ∼ 011.
8
that it wastes one code by using 000 for 0 and 100 for-O. An alternative code
that has many other advantages is the 2's complement code. The 2 s ′
complement codes for positive numbers are the same as the sign-magnitude
codes, but the codes for negative numbers are generated by complementing
all bits for the corresponding positive number and adding 1:
Equation:
−4 ∼ 100
−3 ∼ 101 (100 + 1)
−2 ∼ 110 (101 + 1)
−1 ∼ 111 (110 + 1)
0 ∼ 000
1 ∼ 001
2 ∼ 010
3 ∼ 011.
Exercise:
Problem:
Equation:
Binary Trees and Constant-Length Codes; (a) Binary Tree, and (b)
Pruned Binary Tree
All of the codes we have generated so far are organized in Table 2. For each
code, the average number of bits/symbol is tabulated. This average ranges
from 2.4 to 3.0. If all symbols are equally likely to appear, then the best
variable-length code would be code 2.
Binary Trees and Variable-Length Codes; (a) Binary Tree for Variable-
length Code, and (b) Another Binary Tree for Variable-length Code
All of the codes we have constructed have a common characteristic: each
code word is a terminating leaf on a binary tree, meaning that no code word
lies along a limb of branches to another code word. We say that no code word
is a prefix to another code word. This property makes each of the codes
instantaneously decodable, meaning that each bit in a string of bits may be
processed instantaneously (or independently) without dependence on
subsequent bits.
Exercise:
0111001111000000101100111.
Exercise:
Problem:
S0 S1 S2 S3 S4
011 100 00 0 01
Code #2 generated in Table 2 seems like a better code than code #5 because
its average number of bits/symbol (2.4) is smaller. But what if symbol S is a
0
very likely symbol and symbol S is a very unlikely one? Then it may well
4
turn out that the average number of bits used by code #5 is less than the
average number used by code #2. So what is the best code? The answer
depends on the relative frequency of use for each symbol. We explore this
question in the next section.
Binary Codes: Huffman Codes for Source Coding
then formed a table that showed the relative frequency with which each
letter was used. His ingenious, variable-length Morse code assigned short
codes to likely letters (like “dot” for e ) and long codes to unlikely letters
′
(like “dash dash dot dot” for z ). We now know that Morse came within
′
about 15% of the theoretical minimum for the average code word length for
English language text.
A Variation on Morse's Experiment. In order to set the stage for our study
of efficient source codes, let's run a variation on Morse's experiment to see
if we can independently arrive at a way of designing codes. Instead of
giving ourselves a composition tray, let's start with a communication source
that generates five symbols or letters S , S , S , S , S . We run the source
0 1 2 3 4
′
′
50 S s
0
′
20 S s
1
′
20S s
2
′
5 S s
3
′
5 S s.
4
We will assume that these “source statistics” are typical, meaning that 1000
transmissions would yield 500 S s and so on.
′
0
The most primitive binary code we could build for our source would use
three bits for each symbol:
Equation:
S 0 ∼ 000
S 1 ∼ 001
S 2 ∼ 010
S 3 ∼ 011
S 4 ∼ 100
x ∼ 101
x ∼ 110
x ∼ 111.
This code is inefficient in two ways. First, it leaves three illegal code words
that correspond to no source symbol. Second, it uses the same code word
length for an unlikely symbol (like S ) that it uses for a likely symbol (like
4
N
≅log 2 5 = 2. 32.
M
This scheme improves on the best variable length code of Table 2 from
"Binary Codes: From Symbols to Binary Codes" by 0.08 bits/symbol.
Exercise:
Problem:
1 2 3 4 5 6
N 5 10
N /M 5 5
Now let's reason, as Morse did, that an efficient code would use short codes
for likely symbols and long codes for unlikely symbols. Let's pick code #5
from Table 2 from "Binary Codes: From Symbols to Binary Codes" for this
purpose:
Equation:
S0 S1 S2 S3 S4
This is a variable-length code. If we use this code on the 100 symbols that
generated our source statistic, the average number of bits/symbol is
Equation:
1
[50 (1) + 20 (2) + 20 (3) + 5 (4) + 5 (4)] = 1. 90bits/symbol.
100
Exercise:
Problem:
N
≥ 1. 861.
M
Code #5 comes within 0.039 of this lower bound. As we will see in the
next paragraphs, this is as close as we can come without coding composite
symbols.
S0 0.5 1
S1 0.2 2.32
S2 02 2.32
S3 0.05 4.32
S4 0.05 4.32
Exercise:
Problem:
− p i log 2 p i .
i=1
This tree is now labeled with 1's and 0's to obtain the Huffman code. The
labeling procedure is to label each right branch with a 1 and each left
branch with a 0. The procedure for laying out symbols and constructing
Huffman trees and codes is illustrated in the following examples.
Example:
Consider the source statistics
Equation:
Symbol S0 S1 S2 S3 S4
for which the Huffman algorithm produces the following binary tree and its
corresponding code:
Example:
The Huffman code for the source statistics
Equation:
Symbol S0 S1 S2 S3 S4
Exercise:
Problem:
Generate binary trees and Huffman codes for the following source
statistics:
Equation:
Symbol S0 S1 S2 S3 S4 S5 S6 S7
1024 × 1024 = 1, 059, 576 bits. If these were transmitted over a 9600
baud phone line, then it would take almost 2 minutes to transmit the FAX.
This is a long time.
Let's think about a typical scan line for a printed page. It will contain long
runs of 0's, corresponding to long runs of white, interrupted by short bursts
of l's, corresponding to short runs of black where the scanner encounters a
line or a part of a letter. So why not try to define a symbol to be “a run of k
0's" and code these runs? The resulting code is called a “run length code.”
Let's define eight symbols, corresponding to run lengths from 0 to 7 (a run
length of 0 is a 1):
Equation:
If we simply used a simple three-bit binary code for these eight symbols,
then for each scan line we would generate anywhere from 3 × 1024 bits
(for a scan line consisting of all 1's) to 3 × 1024/7 ≅ 400 bits (for a scan
line consisting of all 0's). But what if we ran an experiment to determine the
relative frequency of the run lengths S through S and used a Huffman
0 7
code to “run length encode” the run lengths? The following problem
explores this possibility and produces an efficient FAX code.
Exercise:
Problem:
Symbol S0 S1 S2 S3 S4 S5 S6 S7
0 ⊕ 0 = 0
0 ⊕ 1 = 1
1 ⊕ 0 = 1
1 ⊕ 1 = 0.
01101001 transmitted
⊕ 00100000 error
01001001 received.
Hamming error correcting codes will permit us to receive the erroneous
transmission and to detect and correct the error. This is obviously of great
value in transmitting and storing information. (Imagine how upset you
would be to have the binary code for your checking account confused with
that of Mrs. Joan Kroc.)
events, and we want these events to indicate whether or not any errors
occurred and, if so, where they occurred. Therefore we require
where (N + n) is the number of single error events that can occur and +1 is
the number of no-error events. For example, when N = 4, we require
n = 3 so that 2 ≥ (4 + 3) + 1.
3
How many check bits do you require to code seven bits of information for
single error correction?
a typical array of bits within a code word would be one of the following:
Equation:
c1 x1
c2 x2
x1 x3
c3 or x4 .
x2 c1
x3 c2
x4 c3
The first ordering is “natural” (as we will see), and the second is
“systematic” (a term that is used to describe any code whose head is
information and whose tail is check). If a single error occurs in an (N , n)
code, then the received code word will be the modulo-2 sum of the code
word and the error word that contains a 1 in its i position: th
Equation:
c1 0
c2 0
xl 0
c3 ⊕ l .
x2 0
x3 0
x4 0
We would like to operate on this received code word in such a way that the
location of the error bit can be determined. If there were no code word, then
an obvious solution would be to premultiply the error word by the parity
check matrix
Equation:
1 0 1 0 1 0 1
0 1 1 0 0 1 1
T
A = .
0 0 0 1 1 1 1
an error word, the error bit picks out the column that codes the error
position:
If the error word contains no error bits, then the product is 0, indicating no
errors.
This seems like a good idea, but what about the effect of the code word? In
Exercise 1, you are asked to show that the effect of the parity check matrix
A applied to the modulo-2 sum of a code word x and an error word e is
T
Equation:
T T T
A (x ⊕ e) = A x ⊕ A e.
In this equation all sums and products obey the rules of modulo-2
arithmetic.
Exercise:
Problem:
Equation:
T T T
A y = A x ⊕ A e.
produces a binary code for the error location. (The location of the error is
′
th e syndrome for the error word.) The product A x will interfere with this T
This constraint actually defines the Hamming code. Let's illustrate this point
by applying the constraint to a code word in its “natural format” x = T
(c c x c x x x ).
1 2 1 3 2 3 4
Natural Codes. When the information bits and the check bits are coded in
their natural order (c c x c x x x ), then we may determine the check bits
1 2 1 3 2 3 4
by writing A x as follows:
T
Equation:
c1
c2
1 0 1 0 1 0 1 x1 0
0 1 1 0 0 1 1 c3 = 0
0 0 0 1 1 1 1 x2 0
x3
x4
c1 ⊕ x1 ⊕ x2 ⊕ x4 = 0
c2 ⊕ x1 ⊕ x3 ⊕ x4 = 0
c3 ⊕ x2 ⊕ x3 ⊕ x4 = 0.
Therefore the check bits c 1, c2 , and c are simply the following modulo-2
3
sums
Equation:
c1 = x1 ⊕ x2 ⊕ x4
c2 = x1 ⊕ x3 ⊕ x4
c3 = x2 ⊕ x3 ⊕ x4.
c1 1101
c2 1011
x1
xl 1000
x2
c3 = 0111 .
x3
x2 0100
x4
x3 0010
x4 0001
This equation shows how the code word x is built from the information bits
(x , x , x , x ). We call the matrix that defines the construction a coder
1 2 3 4
x = HΘ
T T
x = (c1c2x1c3x2x3x4) Θ = (x1x2x3x4)
Equation:
1101
1011
1000
H = 0111
0100
0010
0001
Check to see that the product of the parity check matrix A and the
T
Exercise:
Problem:
Fill in the following table to show what the Hamming (4, 3) code is:
Equation:
x1 x2 x3 x4 c1 c2 x1 c3 x2 x3 x4
0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 1 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
Exercise:
Problem:
the syndrome is
Equation:
T
s = A e.
Convert this binary number into its corresponding integer location and
change the bit of y in that location. If the location is zero, do nothing. Now
strip off the information bits. This is the decoding algorithm.
Exercise:
Problem:
and show that all received code words with one or fewer errors are
correctly decoded.
Digital Hardware. The tables you have constructed in Exercise 3 and 5 for
coding and decoding Hamming (4, 3) codes may be stored in digital logic
chips. Their functionality is illustrated in Figure 1. The coder chip accepts
(x x x x ) as its address and generates a coded word. The decoder chip
1 2 3 4
your courses on digital logic you will study circuits for implementing
coders and decoders.
Exercise:
Problem:
x1 1 0 0 0
x2 0 1 0 0
x1
x3 0 0 1 0
x2
x4 = 0 0 0 1
x3
c1 c11 c12 c13 c14
x4
c2 c21 c22 c23 c24
1 0 0 0
0 1 0 0
0 0 1 0 I
H = 0 0 0 1 = _____ .
Equation:
1 0 0 0
0 1 0 0
1 0 1 0 1 0 1 0 0 1 0 0 0 0 0
0 1 1 0 0 1 1 = 0 0 0 1 = 0 0 0 0 .
Exercise:
Problem:
Solve Equation 19 for the c . Show that the coder matrix for a
ij
1 0 0 0
0 1 0 0
0 0 1 0
H = 0 0 0 1 .
0 1 1 1
1 0 1 1
1 1 0 1
Exercise:
Problem:
Synthesize all seven-bit binary codes and show that your decoder
correctly decodes correct codes and one-bit error codes.
Binary Codes: Numerical Experiment (Huffman Codes)
where is the relative frequency for symbol i and l is the code word
ni
i
N
Gettysburg Address
Fourscore and seven years ago, our fathers brought
forth upon this
continent a new nation, conceived in liberty and
dedicated to the proposition
that all men are created equal. Now we are engaged
in a great civil war,
testing whether that nation or any nation so
conceived and so dedicated can
long endure. We are met on a great battlefield of
that war. We have come
to dedicate a portion of that field as a final
resting-place for those who have
given their lives that that nation might live. It
is altogether fitting and proper
that we should do this. But in a larger sense, we
cannot dedicate, we cannot
consecrate, we cannot hallow this ground. The
brave men, living and dead,
who struggled here have consecrated it far above
our power to add or detract.
The world will little note nor long remember what
we say here, but it can
never forget what they did here. It is for us the
living rather to be dedicated
here to the unfinished work which they who fought
here have thus far so nobly
advanced. It is rather for us to be here dedicated
to the great task remaining
before us–that from these honored dead we take
increased devotion to that
cause for which they gave the last full measure of
devotion–that we here
highly resolve that these dead should not have
died in vain, that this nation
under God shall have a new birth of freedom, and
that government of the
people, by the people, for the people shall not
perish from the Earth.
-Abraham Lincoln, November 19, 1863
An Introduction to MATLAB: Introduction
Introduction
MATLAB stands for “Matrix Laboratory.” It is a computing environment
specifically designed for matrix computations. The program is ideally
suited to circuit analysis, signal processing, filter design, control system
analysis, and much more. Beyond that, its versatility with complex numbers
and graphics makes it an attractive choice for many other programming
tasks. MATLAB can be thought of as a programming language like
PASCAL, FORTRAN, C, or BASIC. Like most versions of BASIC,
MATLAB can be used in an interactive mode wherein statements are
executed immediately as they are typed. Alternatively, a program can be
written in advance and saved to a disc file using an editor and then executed
in MATLAB. You will find both modes of operation useful.
An Introduction to MATLAB: Running MATLAB (Macintosh)
To start MATLAB, you may need to open the folder containing the
MATLAB program. Then just “double-click” the program icon or the
program name (for example, EDU-MATLAB). Figure A.1 shows a typical
organization of the folder containing Mac II-MATLAB. It contains the main
program, the settings file, the demonstrations folder, and any toolbox
folders. The double-click on Mac II-MATLAB produces the Command
window as shown in Figure A.2. You will also see a Graph window
partially hidden behind it. (The fact that the window is not in ffont means
that it is opened but not currently active.) If you do not know what
“clicking,” “dragging,” “pop-up menu,” and “trash” mean, you should stop
reading now and familiarize yourself with the Macintosh.
The MATLAB Folder
(©Apple Computer, Inc.,
used with permission.)
In the command window, you should see the prompt ≫. The program
interpreter is waiting for you to enter instructions. At this point it is a good
idea to run the demonstration programs that are available in the “About
MATLAB” menu under the Apple menu. Just click on the “demos” button
and select a demo. During pauses, strike any key to continue. Whenever
you have a MATLAB file in any folder, then you may double-click the file
to launch the program. This allows you to have your own folder containing
your own MATLAB files, separated from the MATLAB folder.
When you run MATLAB, you should see the prompt . The program
interpreter is waiting for you to enter instructions. Some MATLAB
instructions, such as plot, are graphics-type instructions which plot results
and data. Execution of one of these graphics instructions puts the PC screen
into the graphics mode, which displays the resulting plot. No instructions
can be executed in the graphics mode other than a screen-dump function.
Striking any other key will return the PC to the command mode, but the
graphics are temporarily stored (like variables) and can be recalled by the
shg (show graphics) instruction. If you wish, you may run some of the
demonstration programs now by entering demo and following the on-screen
instructions.
An Introduction to MATLAB: Interactive Mode
≫ 2+2
≫ 5^2
≫ 2*sin(pi/4)
The variable pi = 3.14 is built into MATLAB, as are the sin function
and hundreds of other functions. When you entered each of the preceding
lines, MATLAB stored the results in a variable called ans for answer. The
value of ans was then displayed. The last line should have produced the
square root of 2. We can manipulate ans to find out
≫ ans^2
The new answer is very close to 2, as expected. Let's see what the roundoff
error is:
≫ ans-2
An Introduction to MATLAB: Variables
Any result you wish to keep for a while may be assigned to a variable other
than ans:
≫ x = pi/7
≫ cos(x)
≫ y = sin(x)^2+cos(x)^2;
≫ y
A semicolon (;) at the end of the line suppresses printing of the result, as
when we calculated y in the next-to-last line just shown. This feature is
especially useful when writing MATLAB programs where intermediate
results are not of interest and when working with large matrices.
MATLAB supports the dynamic creation of variables. You can create your
own variables by just assigning a value to a variable. For example, type x
= 3.5+4.2. Then the real variable x contains the value 7.7. Variable
names must start with an alphabetical character and be less than nineteen
characters long. If you type x = -3*4.0, the content 7.7 is replaced by
the value -12. Some commands allow you to keep track of all the variables
that you have already created in your session. Type who or whos to get the
list and names of the variables currently in memory (whos gives more
information than who). To clear all the variables, type in clear. To clear a
single variable (or several) from the list, follow the command clear by
the name of the variable you want to delete or by a list of variable names
separated by spaces. Try it now.
MATLAB is case sensitive. In other words, x and X are two different
variables. You can control the case sensitivity of MATLAB by entering the
command casesen, which toggles the sensitivity. The command
casesen on enforces case sensitivity, and casesen off cancels it.
If one line is not enough to enter your command, then finish the first line
with two dots (. . ) and continue on the next line. You can enter more than
one command per line by separating them with commas if you want the
result displayed or with semicolons if you do not want the result displayed.
For example, type
The number √−1 is predefined in MATLAB and stored in the two variable
locations denoted by i and j. This double definition comes from the
preference of mathematicians for using i and the preference of engineers for
using j (with i denoting electrical current). i and j are variables, and their
contents may be changed. If you type j = 5, then this is the value for j
and j no longer contains √−1. Type in j = sqrt(-1) to restore the
original value. Note the way a complex variable is displayed. If you type i,
you should get the answer
i =
0+1.0000i.
The same value will be displayed for j. Try it. Using j, you can now enter
complex variables. For example, enter z1 = 1+2*j and z2 =
2+1.5*j. As j is a variable, you have to use the multiplication sign *.
Otherwise, you will get an error message. MATLAB does not differentiate
(except in storage) between a real and a complex variable. Therefore
variables may be added, subtracted, multiplied, or even divided. For
example, type in x = 2, z = 4.5*j, and z/x. The real and
imaginary parts of z are both divided by x. MATLAB just treats the real
variable x as a complex variable with a zero imaginary part. A complex
variable that happens to have a zero imaginary part is treated like a real
variable. Subtract 2*j from z1 and display the result.
MATLAB contains several built-in functions to manipulate complex
numbers. For example, real (z) extracts the real part of the complex
number z. Type
≫ z = 2+1.5*j, real(z)
z =
2.000+1.500i
ans =
2
≫ z = 2+2*j;
≫ r = abs(z)
≫ theta = angle(z)
≫ z = r*exp(j*theta)
The last command shows how to get back the original complex number
from its magnitude and angle. This is clarified in Chapter 1: Complex
Numbers.
Another useful function, conj (z), returns the complex conjugate of the
complex number z. If z = x+j*y where x and y are real, then conj
(z) is equal to x-j*y. Verify this for several complex numbers by using
the function conj (z).
An Introduction to MATLAB: Vectors and Matrices
≫ A = [1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
x =
-1.3000 1.7321 4.8000
We call a matrix with just one row or one column a vector, and a 1 × 1
matrix is a scalar. Individual matrix elements can be referenced with indices
that are placed inside parentheses. Type x(5) = abs(x(1)) to produce
the new vector
x =
-1.3000 1.7321 4.8000 0.000 1.3000
Note that the size of x has been automatically adjusted to accommodate the
new element and that elements not referenced are set equal to 0 (here x(4)).
New rows or columns can be added very easily. Try typing r = [10 11
12],A = [A;r]. Dimensions in the command must coincide. Try r =
[13 14],A = [A;r].
The command size(A) gives the number of rows and the number of
columns of A. The output from size(A) is itself a matrix of size 1 × 2.
These numbers can be stored if necessary by the command [m n] =
size(A). In our previous example, A = [A;r] is a 4 × 3 matrix, so the
variable m will contain the number 4 and n will contain the number 3. A
vector is a matrix for which either m or n is equal to 1. If m is equal to 1, the
matrix is a row vector; if n is equal to 1, the matrix is a column vector.
Matrices and vectors may contain complex numbers. For example, the
statement
A =
1.0000+5.0000i 2.0000+6.0000i
3.0000+7.0000i 4.0000+8.0000i
Note that blanks must be avoided in the second expression for A. Try typing
≫A = [1 + 5*j 2 + 6*j 2 + 6*j;3 +7*j 4 + 8*j]
A =
1 4 7
2 5 8
3 6 9
The rows of A' are the column of A, and vice versa. If A is a complex
matrix, then A is its complex conjugate transpose or hermitian transpose.
For an “unconjugate” transpose, use the two-character operator dot-prime (.
'). Matrix and vector variables can be added, subtracted, and multiplied as
regular variables if the sizes match. Only matrices of the same size can be
added or subtracted. There is, however, an easy way to add or subtract a
common scalar from each element of a matrix. For example, x = [1 2 3
4],x = x-1 produces the output
x =
1 2 3 4
x =
0 1 2 3
row and the j column. Then the matrix A*B consists of elements
th
Equation:
n
k=1
where n is the number of columns of A and the number of rows of B. Try
typing A = [1 2 3;4 5 6];B = [7;8;9]; A*B. You should get
the result
ans =
50
112
The inner product between two column vectors x and y is the scalar defined
as the product x'*y or equivalently as y'*x For example, x =
[1;2],y = [3;4],x'*y, leads to the result
ans =
11
Similarly, for row vectors the inner product is defined as x*y'. The
Euclidean norm of a vector is defined as the square root of the inner product
between a vector and itself. Try to compute the norm of the vector [1 2 3
4]. You should get 5.4772. The outer product of two column (row)
vectors is the matrix x*y' (x'*y).
ans =
2 4 6
8 10 12
14 26 28
ans =
1.0e+16*
0.3152 -0.6304 0.3152
-0.6304 1.2609 -0.6304
0.3152 -0.6304 0.3152
ans =
1
-1
1
Equation:
1 2 3 x1 2
1 −2 4 x2 = 7 ,
0 −2 1 x3 3
Check to see that this is the correct answer by typing A*[1;-1;1]. What
do you see?
≫ A*B
≫ A.*B
Suppose we want to find the square of each number in A. The proper way to
specify this calculation is
≫ A_squared=A.^2
≫ A^2
≫ 2.^A
≫ 2 .^A %with a space after
the 2.
In the first case, the dot is “absorbed” by the 2 as a decimal point and the ^
is taken as a matrix exponential. But, when the dot is separated from the 2
by a space, it becomes part of the operator (. ^) and specifies that 2 should
be raised to the power of each element in A. The point is, you should be
very careful to type what you mean in an unambiguous way until you are
familiar enough with MATLAB to know how the subtle situations wiIl be
interpreted. An unambiguous way of typing the preceding lines is
≫ (2.)^A %for matrix
exponential
≫ (2).^A %for array
exponential.
An Introduction to MATLAB: The Colon
You can use the colon several ways in MATLAB (see help :). Its basic
meaning is a vector of sequential values. For example, type
≫ x = 3:9
to get
x =
3 4 5 6 7 8 9
≫ x = 1:0.5:4
≫ x = 6:-1:0
Most MATLAB functions will accept vector inputs and produce vector out-
puts. The statement
≫ y = sqrt(1:10)
builds a vector of integers from 1 to 10 and takes the square root of each of
those numbers. Try it.
x = [x6810] ⇒ x = [1356810]
1 3 5 6 8 10
y = [x; 1 : 6] ⇒ y = [ ].
1 2 3 4 5 6
An Introduction to MATLAB: Graphics
≫ plot(z2,'o')
≫ hold on
≫ plot(z1,'o')
≫ hold off
The advantage in using the hold command is that there is no limit to the
number of plot commands you can type before the hold is turned off, and
these plots may involve the same variable plotted over a range of values.
You can also use different point displays. A disadvantage of the hold
command is that the scaling is enforced by the first plot and is not adjusted
for subsequent plots. This is why we plot the point z2 first. Try reversing
the order of the plots and see what happens. This means that points outside
the scaling will not be displayed. The command hold off permits
erasing the current graph for the next plot command.
You can freeze the scaling of the graph by using the command axis.
MATLAB gives you the message
This freezes the current axis scaling for subsequent plots. Similarly, if you
type axis a second time, MATLAB resumes the automatic scaling feature
and prints the message
The axis scaling can also be manually enforced by using the command
where (xmin, ymin) is the lower left corner and (xmax, ymax) is
the upper right corner of the graph. This scaling remains in effect until the
next axis command is entered (with or without arguments).
plot(x,'*r') x
(line—connected curve
of the value of
on horizontal)
(line—connected curve
plot(x,y,'og') of the value of
on horizontal)
(circle—points of the
value of
on horizontal)
(line—connectedplot of
plot(real(z),imag(z)) z
(blue plus—points of
plot(real(z),imag(z),'+b') z
≫ help
≫ help sin
To learn how to use colon (;, a very important and versatile character) in
MATLAB, type
≫ help :
The demos will also help you become more familiar with MATLAB and its
capabilities. To run them, type
≫ demo
An Introduction to MATLAB: Editing Files and Creating Functions
(Macintosh)
If you quit MATLAB now, all the commands you have typed will be lost.
This is where the Edit window is useful. If you choose new from the File
menu, a new window appears with the title Edit 1: Untitled. In this window,
you should type in all the commands you would like MATLAB to execute
at once. When you are finished typing, you may save the file by choosing
save or save as in the file menu and by entering a name for the file. If the
edit window is active (that is, if it appears in front), then choose save and
go from the file menu to save the file and execute it. If the command
window is active, then you can execute the file by entering its name.
Editing Files. To test your understanding of file editing, enter the following
commands in a file named myfile:
You do not have to type the % sign and the text that follows it. These are
simply comments in a file. They are ignored by the MATLAB interpreter.
You should, however, make a habit of adding comments (preceded by %) to
your file if you want to be able to understand programs that have been
written long ago.
Do not forget to save your file. Such a file is called a script file. It contains
MATLAB commands that could have been entered one by one in the
command window. You have three ways to execute a script file:
i. with the edit window active, choose save and go from the file menu;
ii. with the command window active, enter the file name; or
iii. with the command window active, choose run script... from the M-file
menu. In this case, a menu pops up to ask you which file you want to
execute.
Try each of these three methods in order to get used to their differences.
Figure 1 shows the plot that you should get.
This means that the command plot is a build-in function and thus cannot
be typed by the user (it is compiled with the program). Similarly, try to type
the function file containing the command sinh by entering the command
type sinh. You should get
function y=sinh(x)
%SINH SINH(X) is the hyperbolic sine of the elemen
ts of X.
y=(exp(x)-exp(-x))/2;
This is a typical example of a function file. It differs from a script file by the
fact that the first line contains the word function. What it does is make
the command y = sinh(x) equivalent to the command y=(exp(x)-
exp(-x))/2 . The variable x is the input argument (there could be more
than one), and y is the output argument (there also could be more than one).
The second line contains comments about the function and its arguments.
They can spread to several lines. Display them by typing the command
help sinh. The third line contains the actual function commands (there
could also be several lines).
Note that local variables are just that–local. Only the input and out- put
arguments are kept in memory after the function is called and executed. For
more on functions and multiple arguments, see the MATLAB manual. In
the previous example, the variable j is local. If, before using the function
perp, you use the same variable j, its contents will not be affected by the
command perp(z). Verify this.
You should write a MATLAB program whenever you anticipate exe- cuting
some sequence of statements several times or again in a later session. On an
IBM PC, you may use any text editor to write a program, as long as the file
can be saved in ASCII format without the control codes used by most word
processors. Applicable text editors include Edix, Wordstar, XTree Pro, and
Turbo Pascal's editor.
Editing Files. If you have enough memory, you can run your editor without
leaving MATLAB by using the exclamation point (!), like this:
≫ !EDIX
Script Files. There are two kinds of m-files, called script files and
functions. Running a script file is exactly like typing the commands it
contains at the ≫ prompt. Your m-file will automatically be a script file
unless you specify otherwise, as described later. Practice by entering,
saving, and running plotsin.m as listed next:
t = -6:.2:6;
y = sin(t);
plot(t,y)
title('SINE')
pause
grid
xlabel('t')
ylabel('sin(t)')
When the pause is executed, you will need to press a key to go on. If you
type whos after running plotsin, you will see that the variables t and y
remain in memory. Comments are important to a script file. They are
marked with the symbol %. Anything following this symbol on a line is
assumed to be a comment and is ignored by the MATLAB program
interpreter.
Functions. Functions differ from script files in that they have designated
input and output variables. Any other variables used within a function are
local variables, which do not remain after the function terminates and which
have no effect on variables outside the function. Many of the functions
supplied with MATLAB are actually m-files. A good example is triu.m:
≫ type triu
The word function at the beginning of the file makes it a function rather
than a script file. The function name in this line must match the file name.
The input variables of triu are x and k, meaning that the first input
argument will be referred to as x and the second as k within the function.
Likewise, the function line designates y as the output. There is nothing
special about the variable names x,k, and y when the function is used. It is
only that whatever inputs and output you use will be referred to as x,k, and
y inside the function. The variables m,n,j, and i are created temporarily
when triu runs and disappear when it terminates. They are local variables
and have no effect on variables with the same names outside the function.
In contrast, a script file has no local variables and does no substitution of
input and output variable names.
As an exercise, enter and save the function perp.m:
function y=perp(x)
% PERP(x) is a complex number perpendicular
to x.
j = sqrt(-1);
y = j*real(x)-imag(x);
Printing Files and Graphics. To display an m-file on the screen, use the
instruction ≫ type filename. To make a copy at a printer, use the
DOS command ≫ !print filename.m. Graphics hardcopy is
available through the commands meta and gpp. See the MATLAB manual
for more information.
An Introduction to MATLAB: Loops and Control
assigns the value 0 to the first n elements of the array x. If n is less than 1,
the instruction is still valid but nothing will be done. If n is not defined,
then the following message will appear:
The command end must follow the command for. If it is not present,
MATLAB will wait for remaining statements until you type the command
end, and nothing will be executed in the meantime.
More than one statement may be included in the loop. The statement 1:n is
the way to specify all the integer values between 1 and n. A step different
than 1 may be specified. For example, the statement for
i=1:2:5,x(i)=1,end is equivalent to x(1)=1,x(5)=1. Negative
steps are also allowed, as in i=n:-1:1.
≫ j=sqrt(-1);
≫ n=360;
≫ for i=1:n,circle(1)=exp(2*j*i*pi/n);end;
≫plot(circle)
Note how easy it is to plot a curve. But also note how slowly the for loop is
executed. MATLAB is not very good at executing things one by one. It
prefers, by far, a vector-oriented statement. Using the range specification as
in the for loop, it is possible to speed up the process by replacing the
explicit for loop by an implicit for loop using the colon, like this:
≫ circle = exp((2*j*pi/n)*[1:n]);
Note how much faster this command is executed. In general, for loops
should be avoided as much as possible. For example, the first for loop you
typed could have been replaced by the command x=zeros(1,n);, which
is much more efficient. The function zeros fills the variable with 0's to the
specified size. Similarly, the function ones fills the variable with 1's. The
size can also be determined by the size of the argument. If A is a matrix of
size m,n, then the command B=ones(a) fills the matrix B with 1's and
forces the matrix B to have exactly the same size as the matrix A.
Avoiding for Loops. Since for loops are very inefficient in MATLAB
(they are computed sequentially, adding several more computations for
every loop), it is preferable to use the matrix capabilities of MATLAB to
replace for loops and speed up processing time.
A new file is created by calling the Edix editor with a file name that has not
been previously used. If the file name already exists on disc, then that file is
retrieved and displayed on the screen and is ready to be edited. Since Edix
is a visual editor, changes are made by moving the cursor to wherever
something needs to be typed in or deleted. Once changes have been made to
a file, then that file needs to be saved (written to disc) by typing “Alt-w.”
When all editing is finished, you may exit from the Edix editor by typing
“Alt-x.” Following are some useful Edix editor commands:
e
jθ
, cos θ, and sin θ
n ∞ n
jθ θ 1
e =lim n→∞ (1 + j ) = ∑ (jθ) =cos θ + j sin θ
n n=0 n!
n n
∞ (−1) 2n ∞ (−1) 2n+1
cos θ = ∑ θ ; sin θ = ∑ θ
n=0 (2n)! n=0 (2n+1)!
∞ n ∞ n
(−1) (−1)
2n 2n+1
cos θ = θ ; sin θ = θ
(2n)! (2n + 1)!
n=0 n=0
Trigonometric Identities
Equation:
2 2
sin θ+ cos θ = 1
Equation:
Equation:
Equation:
Euler's Equations
Equation:
jθ
e =cos θ + j sin θ
Equation:
jθ −jθ
e − e
sin θ =
2j
Equation:
jθ −jθ
e + e
cos θ =
2
De Moivre's Identity
Equation:
n
(cos θ + j sin θ) =cos nθ + j sin nθ
Binomial Expansion
Equation:
N
N
N N N!
n N −n
(x + y) = x y ; =
n n (N − n)!n!
n=0
Equation:
N
N
N
2 =
n
n=0
Geometric Sums
Equation:
∞
k
a
az = |z| < 1
1 − z
k=0
Equation:
N −1 N
a(1 − z )
k
az = z ≠ 1
1 − z
k=0
Taylor's Series
Equation:
∞ k
(x − a)
(k)
f (x) = f (a)
k!
k=0
Equation:
(Maclaurin's Series if a = 0)