You are on page 1of 26

Notes about

the Dark Side


of the Mathematical Force
by Mikhail Konnik

100

200

300

400

500

600

700

800

900

1000

Figure 1: The beauty of a (seemingly) boring function f (x) = xx + c.

an obligatory tribute to the Star Wars - the best science fiction ever made

Abstract
These notes are about high school mathematics, what it really means, and how it can be turned
into something fun and useful. Over the years Ive been collecting neat examples, interesting
proofs, and small programs that illustrate mathematical concepts, so this is not a watered-down
math for life kind of text: there are proofs and derivations, so the reader is invited to work
on them. On the other hand, these are not obscure textbook-type examples, either - these
examples are taken from real-world applications of mathematics in physics, engineering and
even biology. This is because the author is actually a researcher in optical engineering, and not
a pure mathematician.
The contents of typical textbooks is usually not a problem - the very way how the mathematics is being taught is the problem. The very way how mathematics is usually taught
leaves students with a feel that math is something useless, distant and unnecessary.
Imagine that the music theory is compulsory for high school courses, which means that you
have to become really good at reading and manipulating musical score on a paper. To pass the
rst music course, you need to be able to draw the treble and bass clefs in exactly the right
position, and know how to draw the whole, half, quarter, and eighth notes, you have to know
which positions in the sheet correspond to which musical notes, and so on. Yet, the teacher will
never allow you to sing a note or play an instrument.
As a result, a student will know everything about music theory. What for? Well, it is a useful
skill, you know... Would you say a student who excels in this practice is good at music? Hardly:
the student is likely to hate music to the rest of his life.
But this is precisely what high school students are subjected to in math class. We force them
to memorise the precise details of solving algebraic equations and polynomial inequalities. We
require them to be adept at simplifying fractions involving radicals, drawing accurate sketches
of ellipses and hyperbola from their equations, and writing out the steps of a geometric proof in
such pedantic detail that would make a grown mathematician cry.
So when a freshman high school student tells me that he was always good at math, it translates
to I was very good at following obscure steps to manipulate mysterious symbols, without any
real understanding of what I was doing.
Mathematics is not about numbers, or formulas - it is about models of a real-world processes.
It is, in a way, a puried form of a real-world. The simplest way to say it is that mathematics is
about recognising and reasoning about patterns. These patterns can come from anywhere:
shapes, numbers, relationships at a party, physical systems, tournaments, card games. The idea
is not just to dump mathematics on students, but to bring mathematics to life and show how it
works through applications in physics, engineering and programming, so math will not be just a
bunch of formulas, but a powerful toolbox for solving real world problems.

Chapter 1

Trigonometry
Trigonometry deals with the set of functions that allow us to work with angles, calculate the
properties of triangular, and model waves of any nature. It also allows us to break wine glasses
without touching them, unearth signals buried in noise, eciently compress music and images,
control ames, transmit and receive information, determine our geographical coordinates and a
lot more.

1.1

Brief introduction

Lets make a plot of two trigonometric functions, y = sin(x) and y = cos(x) by substituting
numbers into them - like in Figure 1.1 for x [0 : 7].
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1

cos
sin
0

Figure 1.1: The cosine and sine functions plotted on a range of numbers from 0 to 7.
That is, we just made two columns of numbers, x and y, and in the X column we put numbers
from 0 to 7 with step 0.1 - either by hand or (better) writing a program in MATLAB or Octave.
1

That is, we just put x = 0, 0.1, 0.2 all the way to 6.9 and nally 7. Each of the number in the
X column we substituted into cos(x) and sin(x), giving us corresponding values of the functions,
which we put into Y column. Then we plot numbers in X against numbers in Y.

1.2

Why do we need trigonometric functions?

These obscure mathematical functions look completely detached from real world and ultimately
useless. But lets take a closer look at, say, a smartphone and try to nd some applications of
trigonometric functions cos(x) and sin(x) there:
1. when you speak, you produce soundwaves (human vocal cord changes the air pressure)
that are sensed by a microphone and converted into electric signals for transmission;
2. what you say during the call is send to a cell-tower as a radiowave;
3. various communication networks, like WiFi and Bluetooth, use electro-magnetic waves,
too;
4. whenever you want to know where are you on the map, you use the GPS (global positioning
system) or cell tower triangulation method to determine your location;
5. when you look at the screen, you see lightwaves, and the image on the screen is formed
by turning their angle (light polarisation angle);
6. the images themselves, say, from the camera, are compressed to reduce size and occupy
less space using trigonometric transforms (Discrete Cosine Transform);
7. when you dont want to be disturbed, you can put the smart-phone in vibration mode,
which produces vibration waves;
It seems like our smartphones are packed with waves of dierent origin! Lets see if those
waves have anything to do with that boring trigonometry.

1.2.1

Sound waves and the cosine function

What do soundwaves and cosine functions have in common? To answer this question, lets write
a simple program that can generate a tone. A tone has its pitch (also called frequency) and
volume (loudness or amplitude).
Sound frequency When you record the tone on a computer, you see a waveform - this is just
the levels of sound proportional to air pressure made by the sound. For example, we can record a
sound tone with 400 Hz frequency (that is, the soundwave will do 400 turns per second) and plot
it Figure 1.2. The plot of a soundwave looks just like the cosine function on Figure 1.1, except
for the amplitude (volume, or dierence between the maximum and the minimum) and pitch (or
frequency). We can go further and record a tone with 800 Hz - twice the pitch compared to 400
Hz, and compare them both.
Not surprisingly, the tone has twice the pitch, so it makes two times more turns per second.
Lets generalise this example, and compare cos(x) with cos(2 x) - this is exactly what we did in
the example above with two soundwaves of 400Hz and 800Hz frequencies. Plugging the numbers
in a calculator is very tedious, and plotting many points on a paper is even more so - but we can
ask a computer to do this job! If we use a mathematical programming language like Octave and
write a simple program like this:
2

10
3

x 10

Figure 1.2: The tone of 400 Hz (blue) and 800 Hz (green).

x = 0:0.1:7;
y = cos(x);
y2 = cos(2*x);
figure, plot(x,y,x,y2), ...
legend('cos(x)', 'cos(2*x)', 'Location', 'SouthEast');

which means that:


1. x = 0:0.1:7; generate the row of numbers from 0 to 7 with a step of 0.1
2. y = cos(x); substitute numbers from x into cos(x) function to get row of cosine values y;
3. y2 = cos(2*x); substitute numbers from x into cos(2 x) to get row of cosine values with
double frequency (2x) in y;
4. figure, plot(x,y,x,y2) to plot y and y2 values on a plot like the one in Figure 1.3.
If we compare plots in Figure 1.2 and Figure 1.3, we discover that they are very similar
- in fact, the trigonometric functions y = cos(x) and y = cos(2 x) are describing the soundwaves
of two pitches 400 Hz and 800 Hz (single and double frequency).
Takeaway: trigonometric function cos(x) is a very good model of a soundwave
(that is, a pure tone): doubling the frequency of the tone (from 400 to 800 Hz) in our
example) can be well described by doubling the variable inside the cosine function
from y = cos(x) to y = cos(2 x). In fact, it does not matter if this is a sound wave,
a light wave or a wave on the surface of a pond - the cosine function will model them
as well, just change the frequency and amplitude accordingly.
But you may notice that the values on a vertical axis in Figure 1.2 and Figure 1.3 are very
dierent - this brings us to the notion of amplitude.
3

1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1

cos(x)
cos(2*x)
0

Figure 1.3: The plot of y = cos(x) and y = cos(2 x) where x are from 0 to 7.
Sound volume (or amplitude) Every time your listen to the music, you use that little knob
called Volume to make the song louder or quieter. Your music player changes the amplitude of
the soundwaves - yes, those cosine waves above. If we make another plot of two cosine functions
y = cos(x) and y = 2 cos(x), we can see from Fig. 1.4 that those plots are just scaled versions
of one another.
2
1.5
1
0.5
0

0.5
1

1.5

Figure 1.4: The plot of y = cos(x) and y = 2 cos(x) where x are from 0 to 7.

This brings us to a more general model of a wave:


y = A cos(F x)
where A stands for amplitude - a constant that controls the scale of the function (volume of
a soundwave), and F stands for f requency - a constant that controls how many complete turns
the function does (pitch, or a tone of a soundwave). The cosine function cos(x) is a idealised
model of a wave with unit amplitude and unit frequency, and this is why it returns the values
from -1 to 1.
By now you should see that you cannot just take the number N out of brackets in cos(N x)
and put it in front of the function - you cannot convert the frequency into volume this easily!
The conversion is a bit more complicated, and we will see it in trigonometric identities below.

1.3

Trigonometric identities: derivation and meaning

As we have already seen, we can think of trigonometric functions as models of waves that can be
described as y = A cos(F x). Here A stands for amplitude, F stands for f requency, and x is
a running variable (time, for example). But apart from generating pure tones, cosine and sinus
functions do not take us very far - we need to know the relationships between them if we want to
use trigonometry for something useful. Relationships between trigonometric functions are more
complex than just adding numbers, and there are formulas that describe those relationships.
But there is no need to memorise all the formulas: once you understand few basic trigonometric identities how the really work, you will be able to easily derive the rest of the formulas.

1.3.1

Sum of squares

One of the most useful identity is a sum of cosine and sine squares:
sin2 (x) + cos2 (x) = 1

(1.1)

If you look at Figure 1.8, you will notice that when a cos2 (x) has its Y -value at 0.5, so does
the sin2 (x). If you add them together, the result will be equal 1. Moreover, all other points on
the plot for cos2 (x) and sin2 (x) will give 1 in sum: when one of the functions is at valley, another
has a peak at 1, and so on. Therefore, the sum of squares sin2 (x) + cos2 (x) always equals 1.

1.4

1.2

0.8

0.6

0.4
cos2(x)

0.2

sin2(x)
cos2(x) + sin2(x)=1

0
5

Figure 1.8: The plot of sin2 (x) + cos2 (x) = 1.


The computer program for MATLAB or Octave programming languages that makes this plot is:
x = 5:0.01:5;
figure, plot(x,cos(x).2,x,sin(x).2,x, cos(x).2 + sin(x).2 ),...
legend('cos2(x)', 'sin2(x)', 'cos2(x) + sin2(x)=1',...
'Location', 'SouthEast');

Proof of Sum of squares formula


This identity can be also derived without any plots,
using only geometry. Recall that the trigonometric
functions are connected with a circle of unit radius
h = 1, as shown in Figure 1.9.
Take any point on a circle of unit radius h =
1, and put a vertical line down - this gives us a
triangle with right angle 90 with sides a and b,
and hypotenuse h = 1.
Pythagorean theorem tells us that a2 + b2 = h2
in the right triangle, and all we need is to express
the sides in terms of cosine and sinus of an angle
opposite
x. We know that sin(x) = hypotenuse
= ha and
adjacent
cos(x) = hypotenuse
= hb .
Since h = 1, we have a2 +b2 = 1 and sin(x) = a1
and cos x = 1b . Substituting it back, we get Figure 1.9: A geometric proof for identity
sin2 (x) + cos2 (x) = 1 just like in Equation 1.1.
sin2 (x) + cos2 (x) = 1.

1.3.2

Sum and dierence of angles for sin(x) and cos(x)

As you may have guessed, cosine wave of sum of frequencies is not just a sum of cosine waves:
that is, the expression cos(x + y) 6= cos(x) + cos(y) is wrong, and the actual expression is a bit
more complicated:
cos(x y) = cos x cos y sin x sin y

(1.2)

sin(x y) = sin x cos y cos x sin y

(1.3)

The expressions above are very important, since once you understood and memorised them,
you can derive pretty much any other expression for sine and cosine functions. You
can make a plot (like in Figure 1.10) and compare, for example, cos(x + 2x) and cos x cos(2x)
sin x sin(2x) to make sure that the expression from Equation 1.2 is true.
The program code that can plot Figure 1.10 in MATLAB or Octave programming language
is quite simple:
y cos 3x = cos(3*x);
y sin x = sin(x);
y cos x = cos(x);
y sin 2x = sin(2*x);
y cos 2x = cos(2*x);
figure, plot(x, y cos x. * y cos 2x y sin x. * y sin 2x, ...
x, y cos x. * y cos 2x, x, y sin x. * y sin 2x)
legend('cos(3*x)', 'cos(x)*cos(2x)', 'sin(x)*sin(2x)','Location', 'SouthEast');

Both equations 1.3 and 1.2 are so important that they deserve a formal proof1 .
1 There are many ways to prove those identities, like using complex exponentials. The proof here is Smiley, L.
and Smiley, D. Geometry of Addition and Subtraction Formulas.

10

1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
cos(3*x)
cos(x)*cos(2x)
sin(x)*sin(2x)

0.8
1

Figure 1.10: The plot of cos(x + 2x) and cos x cos(2x) sin x sin(2x) for comparison. If you
subtract the plot with sin x sin(2x) from cos x cos(2x), you will get cos(3x).
Proof for sin( )
Lets take the right triangle 4ABC in Figure 1.11 such that
AK = 1 (unit length). For the proof, we will need sin() =
AC
AB , so we need to express those sides in terms of cosine and
sine.
From 4ABC: ( + ) + = 90 = 90 ( + )
From 4AKC: AKC + = 90 AKC = ( +
) since = 90 ( + )
Now, we express side AC: sin( + ) = AC
1 AC =
sin( + )
From 4ANK: we are looking for expressions of sides
AN and NK.
cos = AN
1 AN = cos . Remember that we choose
AK to be of unit length - exactly for this! Now nd NK:
sin = N1K N K = sin
From 4NBK: we need to nd NB that we need for
the proof of the formula (from Figure 1.11 you can see that
NB+AN = AB that we are looking for).
sin
sin cos
K
NK
tan = N
N B N B = tan = tan =
sin . We have
everything we need by now, and we turn back to our main Figure 1.11: Illustration for the
triangle, 4ABC.
proof of sin( + ) = sin cos +
AC
AC
= N B+AN
= cos sin .
Finally, from 4ABC: sin = AB
sin(+)
. From this expression we need sin( + ),
cos + sin cos
sin

which is:

11

(
)
sin cos
sin( + ) = sin cos +
= sin cos + cos sin
sin
This concludes the proof 
Formula for sin( ) can be obtained simply substituting into the formula above, which
gives Equation 1.3.
Proof for cos( )
The proof is very similar to the previous one, except
we put the angle to the KAC. The side AK is still
of unit length, as seen in Figure 1.12. For this proof,
AC
we will need tan() = BC
, so we need to express those
sides in terms of cosine and sine.
From 4ABC: (+)+ = 90 = 90 (+)
From 4ANK: N KA + = 90 N KA =
( + )
Now, we express the side NK: cos( + ) = N1K
N K = cos( + ) Remember that we choose AK to be
of unit length - exactly for this!
cos(+)
K
From 4NBK: sin = N
BK BK =
sin .
From 4AKC: we need to express the sides AC and
KC in terms of trigonometric functions. As before, notice that AK is unit length, that is, AK = 1.
cos = AC
1 AC = cos
sin = KC
Figure 1.12: Illustration for the proof
1 KC = sin
sin
AC
Finally, from 4ABC: tan = cos
=
=
of cos( + ) = cos cos sin sin .

BC
cos
AC
=
and
all
we
need
is
to
express
cos(+)
BK+KC
sin

+sin

cos( + ) that we are looking for.


cos sin
sin
=
cos
cos( + ) + sin sin
from where
cos( + ) = cos cos sin sin
This concludes the proof 
Formula for cos( ) can be obtained by simply substituting into the formula above,
which gives Equation 1.2.
Now, since we have proven the formulas for sum and dierence for cosine and sine
functions, we will get nearly all other formulas - again, you dont have to memorise
them mechanically since you can (relatively) simply derive them.

1.3.3

Double-angle formulae

As before, keep in mind that cosine and sine functions describe a wave, thus cos(2x) is a wave
of double frequency compared to a simple wave cos(x). The relationship between a wave of
double and unit frequency is:

12

sin 2x = 2 sin x cos x

(1.4)

You can simply derive the expression in Equation 1.4 using Equation 1.3 and the following
trick: sin(2x) = sin(x + x). So sin 2x = sin x cos x + sin x cos x = 2 sin x cos x. Derivation
of the double-angle formula for cosine is similar: just use Equation 1.2 and the same trick
cos(2x) = cos(x + x):
cos 2x = cos x cos x sin x sin x = cos2 x sin2 x = 2 cos2 x 1 = 1 2 sin2 x

(1.5)

Why do we need the double-angle formula?


An illustrative example this time comes from optics: there are optical crystals that can double the
frequency of a lightwave, such as lithium niobate (LN) or potassium titanyl phosphate (KTP).
That is, you can convert a light of a infra-red laser (with wavelength of 1.1m that is easy to
get) into a green laser light (wavelength 0.55m). Most laser pointers that produce green light
use these frequency-doubling crystals.

Figure 1.13: Doubling the lightwave frequency: converting from cos(x) to cos(2x) in optics.

1.3.4

Sum-to-Product Formulas

We already know by now that sine and cosine functions are models of waves, and we cannot
just sum them like cos x + cos y 6= cos(x + y). The following expressions will allow us to convert
sum and dierence of trigonometry functions into products:
(

)
(
)
xy
xy
cos
2
2
)
(
)
(
xy
x+y
cos
cos x + cos y = 2 cos
2
2
(
)
(
)
x+y
xy
cos x cos y = 2 sin
sin
2
2
sin x sin y = 2 sin

(1.6)
(1.7)
(1.8)

These formulas can be derived using the expressions for double angles in Equation 1.4 and
Equation 1.5. Lets do it for sin(x) + sin(y). In this proof, we take the right part of Equation 1.6,
and try to show that it is equivalent to the left part. Use Equation 1.4 to get:
)
(
)
(
(
xy
x
y
x
y) (
x
y
x
y)
x+y
cos
= 2 sin cos + cos sin
cos cos + sin sin
= ...
2 sin
2
2
2
2
2
2
2
2
2
2

13

Here we just used the Equation 1.3 and Equation 1.2. Open the brackets and multiply these
items to get:
(
x
y
x
x
y
y
y
x
y
y
x
x)
= 2 sin cos2 cos + sin2 cos sin + sin cos2 cos + sin2 cos sin
= ...
2
2
2
2
2
2
2
2
2
2
2
2
Take a closer look at item 1 and 4 - we can group them like this: cos x2 sin x2 (sin2 y2 + cos2 y2 ).
Notice that the sum inside brackets equals 1, as we already know from sin2 (x) + cos2 (x) = 1 (see
Equation 1.1). The items 2 and 3 in the expression above can be grouped similarly, so we get:
(
y
x
x)
y
= ...
= 2 cos sin + sin cos
2
2
2
2
Now open the brackets and look closely on each item: for instance, 2 cos y2 sin y2 looks similar
to Equation 1.4. Therefore, 2 cos y2 sin y2 = sin(2 y2 ) = sin y and therefore
(
y
y
x
x)
= 2 cos sin + sin cos
= sin y + sin x,
2
2
2
2
which is exactly the Equation 1.6 and concludes our proof.
Why do we need sum-to-product formulas?
These sum-to-product formulas are really special because your own brain does this all the time:
sounds that you hear with both ears are summed and processed by the brain so you can determine,
for example, where does the sound came from. You can actually trick your own brain into nding
a sum of two cosine waves (soundwaves), and hear binaural beats. For example, if a frequency
of 100 Hz is presented to your left ear, and a frequency of 105 Hz is presented to your right
ear, your brain hears a third frequency pulsing at 5 Hz, the exact dierence between the two
frequencies. Some binaural beat frequencies were found to be useful in auditory stimulation to
enhance brain functioning.
We can use the formula of sum-to-product to nd the expression for sum of two sound waves
with frequency f1 and f2 ::
(
)
(
)
(f1 + f2 )
(f1 f2 )
cos(2f1 t) + cos(2f2 t) = 2 cos 2
t cos 2
t ,
2
2
where t is a variable for time. If the two sound frequencies are close (a dierence f1 f2
of about twenty hertz), the frequency of the sound wave is often too slow to be perceived as a
pitch. Instead, the sound wave is perceived as a periodic variation (beat) of the volume, which
is described by the expression above. We can see it in Figure 1.14.
The program below (runs in MATLAB and GNU/Octave) generates two sound waves (a
stereo sound), with two pure tones of frequencies f1 = 500Hz and f2 = 500 + 30 = 530Hz. Then
the sound is played for 4 seconds.
Amplitude=10;
duration=4; %% seconds
Frequency=500;
Frequency diff= 30; % frequency difference for beat
Freq sampling=10000; % sampling frequency
values=0:1/Freq sampling:duration;
left=Amplitude*cos(2*pi* Frequency*values);

14

0.02

0.04

0.06

0.08

0.1

0.12

Figure 1.14: The sum (blue) of two cosine waves, compared to a single wave (green). The function
plotted is yk = cos(2 500xk ) + cos(2 530xk ).
right = Amplitude*cos(2*pi* (Frequency+Frequency diff)*values);
stereosnd = [left; right]; %% combining two sounds at a stereo
soundsc(stereosnd, Freq sampling); %% play the sound

You should use headphones to listen to this sound. Put one earpiece in your ear, and you
will hear a pure tone. Then move the second earpiece slowly to your other ear - and instead of
two separate tone you are going to hear a sound beat, since the frequencies (or tones) dier
slightly (only by 30 Hz). Keep in mind that those two tones do not mix - they are in the left and
right earpieces. That is, the tones do not interfere physically, but are summed by the brain.
This eect is related to the brains ability to locate sounds in three dimensions.
See, your own brain already knows and does the trigonometry, and all this mathematical expressions just bring the trigonometric expressions to you in a convenient form.

1.3.5

Product-to-sum formula

Lets derive the reverse formulas, which allow us to convert the product of two waves into the
sum (or dierence) of separate waves:
2 cos x cos y = cos(x y) + cos(x + y)

(1.9)

2 sin x sin y = cos(x y) cos(x + y)


2 sin x cos y = sin(x + y) + sin(x y)

(1.10)
(1.11)

2 cos x sin y = sin(x + y) sin(x y)

(1.12)

These formulas can be used for transmitting the information via radiowaves, as we will see
shortly. The derivation of this formulas is very simple: all you need is to use Equations 1.3
and 1.2. For example, the formula 2 cos x cos y = cos(x y) + cos(x + y) can be derived as sum
of the two equations below:
15


cos(x + y) = cos x cos y sin x sin y
+

cos(x y) = cos x cos y + sin x sin y


where sin x sin y are gone and therefore we get cos(x + y) + cos(x y) = 2 cos x cos y, exactly
as in Equation 1.9. Other formulas can be derived in a similar way.
Why do we need these Product-to-sum formulas?
The product-to-sum trigonometric formulas can be used to transmit and receive information.
Ever wondered what are those FM and AM acronyms stand for? They stand for Amplitude
Modulation and Frequency Modulation, respectively - these are the methods of transmitting
music on a radio, and we are going to use trigonometry for this.
First, we need a carrier wave - we are going to modify it with the input signal (our music) to
transmit music using radiowaves. The carrier wave is usually of a much higher frequency than
the input signal, which helps us to detect the actual signal. Lets take a carrier wave C(t) of
frequency Fc and amplitude A given by:
C(t) = A cos(2Fc t) .
which is a function of time t. We are going to modify (or, as engineers say, modulate) this
carrier wave C(t) with a music, but for simplicity lets say we want to transmit just a pure tone
S(t). This signal S(t) represent the modulation soundwave of a frequency Fm (which must be a
much lower frequency than Fc ):
S(t) = M cos(2Fm t) ,
where M is the amplitude of the modulation. Lets agree that M < 1 so that (1 + S(t)) is always
positive. Amplitude modulation occurs when the carrier wave C(t) is multiplied by (1 + S(t)):
y(t) = [1 + S(t)] C(t) = [1 + M cos(2Fm t)] A cos(2Fc t)

(1.13)

Using the Equation 1.9, the resulting signal (as a function of time) y(t) can be shown to be:
y(t) = A cos(2Fc t) +

AM
2

[cos(2(Fc + Fm )t) + cos(2(Fc Fm )t)] .

The modulated radiowave is shown in Figure 1.15, and the program for this demonstration
is provided below.
A = 2; %% amplitude
duration=4; %% in seconds
Freq sampling = 10000;
values=0:1/Freq sampling:duration;
Carrier Frequency=1000;
C t =A*cos(2*pi* Carrier Frequency*values);
M = 0.1; %% modulation coefficient
Signal Frequency = 120;
S t = M*cos(2*pi*Signal Frequency*values);
y t = (1+S t).* C t;
figure, plot(values, y t); %%% this is to plot a beat

16

0.005

0.01

0.015

0.02

0.025

0.03

0.035

0.04

0.045

0.05

Figure 1.15: The Amplitude Modulation in action: we have a carrier wave of 1000 Hz frequency,
which is modulated (modied) with a tone of 120 Hz using Equation 1.13. Notice the change in
the amplitude on the plot.

1.3.6

The power of Trigonometry: meet the Discrete Cosine Transform

Many textbooks mention the applications of trigonometry, like determining the height of a building if you know the distance to it and the angle to the rooftop, or some equally boring/exotic
examples. Here we are going to see a real-world application of cosine functions, which is really
useful for sound analysis and compression - the Discrete Cosine Transform (DCT).
Be not afraid of this fancy name: it simply means that we are going to use Cosine function to
Transform, or decompose, our sound signal on pure tones (cosine functions of various frequencies).
The word Discrete simply means that the values of our signal are sampled with some xed-step
interval - for example, we measure a value of our signal every 0.1 seconds.
Using DCT we are going to mathematically de-compose our signal into pure tones (or cosine
waves), and calculate how many cosine waves of this particular frequency do we have in the
signal. This is extremely useful for analysis of the signal: for example, you can reduce the noise
in signal by simply zeroing out the unwanted frequencies and transforming the signal back.
There are many applications of DCT that we use every day without even knowing it:
signal analysis: by decomposing the signal on the pure cosine waves, we can see what are
the main waves in the signal. This way you can analyse, for example, stock market prices
to nd any recurring periodical uctuations of prices (and predict when it happens next).
audio compression: MP3 format uses a variety of DCT algorithm to determine which sound
frequencies to keep and which to throw away, compressing the song without noticeable loss
in quality.
images compression: JPEG format also compresses the images using DCT-like algorithm
to reduce the size of the image by throwing away unnecessary details.

17

Example of frequency analysis using Discrete Cosine Transform


Lets go back to our previous example and take it one step further: we combine a soundwave of
frequency F1 = 400 Hz and amplitude A = 1 with a soundwave of frequency F2 = 800 Hz and
amplitude A = 2:
yk = cos(2 400xk ) + 2 cos(2 800xk )

(1.14)

were indexes with the letter k in yk and xk simply mean the row number in the table with y
and x. Thats where the word discrete comes into play: our computers can work with discrete
numbers, and all we need is to take enough samples of a function (cosine in this case) close to
each other to describe the signal.
In the program code below, we take L = 1000 samples for our signal from Equation 1.14, and
we take samples of our signal close to each other - say, once every t = 1/4000th of a second. Here
4000 is our sampling frequency - this is how often we evaluate our function in Equation 1.14. We
took Fsampling = 4000 arbitrary - any number larger than 800 will be ne.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Fs = 4000;
T = 1/Fs;
L = 1000;
x k = (1:L)*T;

%
%
%
%

Sampling frequency
Sample time
Length of signal, counts
Time count

%% Sum of a 400 Hz wave and a 800 Hz wave


y k = cos(2*pi*400* x k) + 2*cos(2*pi*800* x k);
%% Now add some random noise to the sum of waves
y k noisy = y k + 2*randn(size(x k));
figure, plot(Fs* x k(1:200),y k(1:200))
title('Original signal (sum of two waves)'), xlabel('time (milliseconds)')
figure, plot(Fs* x k(1:200),y k noisy(1:200))
title('Signal Corrupted with Random Noise'), xlabel('time (milliseconds)')

That is, take L = 1000 numbers (line 3) and generate xk values (line 4) to be plugged into
Equation 1.14 (line 7). The plot of the signal can be seen in Figure 1.16(a).
The Discrete Cosine Transform Now the main part: we are going to transform (decompose)
our sound signal into pure tones (cosine waves of dierent frequencies) using the Discrete Cosine
Transform (DCT):
N
1

Dk =
yn cos
N
n=0

1
n+
2

) ]
k

for every frequency k = 0, . . . , N 1.

(1.15)

Now, what does this formula2 actually mean:


the sign

N
1

means summing elements with subscript n from n = 0 to n = N 1;

n=0

N is the length of the signal y - in our case, the signal has 1000 values (a row in a table
with 1000 cells);
2 This formula does not include a normalisation term to account for the number of samples - Im skipping it
to simplify the discussion.

18

Original signal (sum of two waves)

How many waves of different frequencies do we have in the Signal?

40

2.5

35

X: 800
Y: 36.18

2
30
1.5
25

1
0.5

X: 400
Y: 21.27

20

15

0.5
10
1
5

1.5
2

20

40

60

80
100
120
time (milliseconds)

140

160

180

200

(a)

200

400

600

800
1000 1200
Frequency (Hz)

1400

1600

1800

2000

(b)

Figure 1.16: Clean, noiseless signal: (a) The plot of yk = cos(2 400xk ) + 2 cos(2 800xk );
(b) the wave frequencies (Discrete Cosine Transform) in the noiseless signal: you can see 400 Hz
and 800 Hz peaks.
yn we take from Equation 1.14.

and we do this for every frequency k from 0 to N 1. At the end we get a row of numbers
Dk that tells us how many cosine waves with frequency 0, 1, 2 all the way up to frequency N 1
do we have in our signal. The program code (MATLAB or Octave) for the DCT formula in
Equation 1.15 is quite simple3 :
function D = my dct(y)
N = length(y); %% N rows do we have in the signal y?
D = zeros(N,1); %% D stores the DCT transform of the signal y
for k = 0:1:N1 %% for every frequency k = 0 to N1 with step 1....
for n = 0:1:N1 %% for every row value of signal y do this:
D(k+1) = D(k+1) + y(n+1)*cos(pi/N *(n + 1/2)*k);
end %% the line above literary implements the DCT formula
end

There is no need to program the DCT formula: in MATLAB and Octave it can be called
using dct(Y) command to transform the signal stored in the variable Y .
Now, if we now plot the numbers in the variable Dk versus frequencies of a cosine wave (k
from 0 to N-1), we will see the picture like the one in Fig. 1.16(b). Notice two peaks at 400 and
800 Hz - these peaks correspond to the cosine waves in our signal described by Equation 1.14:
yk = cos(2 pi 400 xk ) + 2 cos(2 pi 800 xk );
This is exactly what we expect: after all, our soundwave contains only 400 Hz and 800 Hz
cosine waves, and those peaks of DCT indicate this.
Now imagine that our soundwave was recorded with a bad microphone: we have a lot of
noise in the recording. If you look at Figure 1.17(a), there is so much noise that you dont even
see the waves! But if you use the DCT to decompose the noised signal, and again make the plot
3 The code is not ecient, and it will take a lot of time for long signals. However, it is a simple, word-for-word,
implementation of the DCT mathematical formula and serves its illustrative purpose

19

of its result, you will be able to see those peaks (that correspond to soundwaves buried under
noise) in Figure 1.17(b).
Signal Corrupted with Random Noise

How many waves of different frequencies do we have in the Signal?

35

30

25

20

15

10

20

40

60

80
100
120
time (milliseconds)

140

160

180

200

X: 800
Y: 33.67

X: 400
Y: 18.58

200

400

600

(a)

800
1000 1200
Frequency (Hz)

1400

1600

1800

2000

(b)

Figure 1.17: Noised signal: (a) the plot of yk = cos(2 400xk ) + 2 cos(2 800xk ) with lots
of noise added; (b) the wave frequencies (Discrete Cosine Transform) in the signal: you can see
400 Hz and 800 Hz peaks..
This is the real power of trigonometric functions: we can decompose even a very noisy
signal and still see what are the cosine waves (that use, pure tones) that make it. And not just
to look at the plot, but also clean up the signal: we can just zero-out the small numbers in the
DCT variable Dk to clean up the noise, and transform the signal back to its original state - and
noise is (almost) gone!
The MATLAB (or Octave) code for this example is below:
Fs = 4000;
T = 1/Fs;
L = 1000;
x k = (1:L)*T;

%
%
%
%

Sampling frequency
Sample time
Length of signal, counts
Time count

%% Sum of a 400 Hz wave and a 800 Hz wave


y k = cos(2*pi*400* x k) + 2*cos(2*pi*800* x k);
%% Now add some random noise to the sum of waves
y k noisy = y k + 2*randn(size(x k));
% Sinusoids plus noise
figure, plot(Fs* x k(1:200),y k(1:200))
title('Original signal (sum of two waves)'), xlabel('time (milliseconds)')
figure, plot(Fs* x k(1:200),y k noisy(1:200))
title('Signal Corrupted with Random Noise'), xlabel('time (milliseconds)')
%% How many cosine waves of different frequencies we have in the signal
D k dct clean signal = dct(y k,L);
D k dct noisy signal = dct(y k noisy,L);
%% Plot the number of cosine waves versus cosine waves' frequencies:
freq = Fs/2*[0:(1/L):11/L];

20

figure, plot(freq, abs(D k dct clean signal(1:L)))


title('How many waves of different frequencies do we have in the Signal?'),...
xlabel('Frequency (Hz)')

figure, plot(freq, abs(D k dct noisy signal(1:L)))


title('How many waves of different frequencies do we have in the Signal?'),...

This example is your rst glimpse into a wonderful world of Signal Processing - the area
of engineering that deals with signals and noise that always stands in our way. But the DCT
has another (and much more entertaining) application - you can use DCT to break a wine glass
without touching it!
Fun application of DCT: breaking the wine glass using soundwaves!
Who said that trigonometry is boring? After all, we study to do something with our knowledge,
and what is the best application of the knowledge than having fun?
In the example above we used the Discrete Cosine Transform to gure out the frequencies
of the signal, even when the signal had a lot of noise. We can take it a bit further and use to
have some fun - we are going to use DCT to gure out the sound frequency that is inherent to
a wine glass. When we play that specic sound frequency through a loudspeaker, we can break
the glass!
WARNING! This trick can be dangerous: wear a protective plastic glasses,
since small pieces of the glass can land in your eye and damage it. Also, use a plastic
wrap to surround the glass so the pieces will not y away and damage something (or
someone) else. This trick is better be performed by a teacher.
First, a bit of physics. Many objects, including a wine glass, have a natural resonance
frequency FR - a frequency that is inherent to the structure and the material of this particular
object. If we apply a soundwave cos(F ) of the same frequency F = FR as resonance cos(FR )
using loudspeakers, we will force the glass to vibrate the most. Mathematically, this is
exactly what the Equation 1.7 is all about: we add two sound waves:
(
)
(
)
FR + F
FR F
cos(FR ) + cos(F ) = 2 cos
cos
2
2
where the FR is the resonant sound frequency of the glass, and F is just about any other
sound frequency. If we want to break the glass, we need to make it vibrate as violently as possible
- that is, we need to put a soundwave of exactly the same frequency as the resonant frequency
of the glass (F = FR ), and the equation above will be:
(
)
(
)
(
)
FR + FR
FR FR
2 FR
2 cos
cos
= 2 cos
= 2 cos (FR )
2
2
2
It is not the volume of the sound that breaks the glass - it is the correct (resonant) frequency
that does the trick. The only problem is to nd it - and here we are going to use the Discrete
Cosine Transform again.
Figuring out the resonant frequency of the glass with DCT: we need to record the
sound of the glass and take the DCT of the signal. To nd the resonance frequency, gently ping
the glass and record the sound on a computer. Then we need to take DCT of the signal to see
the frequencies of the sound - here is an example of the program:
21

recObj = audiorecorder;
disp('Start speaking.')
recordblocking(recObj, 5); % Record your voice for 5 seconds.
disp('End of Recording.');
play(recObj); % Play back the recording.
myRecording = getaudiodata(recObj); % Store data in myRecording table of numbers
% Compute the Discrete Cosine Transform.
L = size(myRecording,1);
Fs = 8000; %% sampling rate, in Hz. Default is 8000 for audiorecorder
D k dct = dct(myRecording); % take DCT
plot(myRecording);% Plot the waveform.
% Plot the number of cosine waves versus cosine waves' frequencies:
freq = Fs/2*[0:(1/L):11/L];
figure, plot(freq, abs(D k dct));

We are looking for the most vocal (prominent) sound frequencies, so we make a plot of the
frequencies found by the DCT like in Figure 1.18.

X: 615.4
Y: 1.724

200

400

600

800

1000

1200

1400

1600

1800

2000

2200

Figure 1.18: The Discrete Cosine Transform of the sound of the glass: notice large peaks - these
are resonant frequencies, and the most prominent of them in this case is FR = 615Hz.
Figure 1.18 gives us the spectrum of the sound produced by the wine glass, and it turns
out that the frequency FR = 615Hz is the resonant frequency of the glass (the most prominent
frequency). Now we know what frequency of the sound we need - lets get dangerous!
Note, however, that the frequency is not the only factor - volume is also important. The
louder the sound, the more violent the vibrations will be. When they reach a level that the

22

glass cannot withstand - it will shatter. This process is very quick - it is hard to see without a
high-speed camera, but we can add a straw and notice that it will be tossed from side to side as
the glass vibrates more and more.
The rim of the glass will be bending back and forth. Figure 1.19 illustrates this: the sound
waves (in blue) push the rim of the glass with the same frequency as the glass itself vibrates,
and this what causes the glass to break apart. Again, the soundwave cos(FR ) with exactly right
frequency FR is what does the trick.

Figure 1.19: If we put the correct soundwave with the resonant frequency of the glass (which
we determined with DCT), the glass will break. Notice how the rim of the glass is bent - this is
what causes the glass to shutter.
The eect of resonance is studied in physics, and occurs in many engineering and science
elds. For example, we put the electromagnetic waves of specic frequency through the food
in microwave ovens, and water molecules happen to absorb those specic frequencies (about
800 MHz), which heats the food up. Another example is the resonance in civil engineering,
like bridges and skyscrapers, which we obviously want to eliminate. One of the most famous
examples of unwanted structural resonances is Tacoma Narrows Bridge.

23

1.5

Pythagorean theorem and its proof

The Pythagorean theorem states that the square of the hypotenuse (the side opposite the right
angle) is equal to the sum of the squares of the other two sides:
a2 + b2 = c2 ,

(1.16)

where c is the length of the hypotenuse, a and b are the lengths of the triangles other sides.
This theorem is very important for the geometry, and we will see how to prove it. There are
many proofs of the Pythagorean theorem, but here we have two ways: Euclids original proof
and a more simple algebraic proof.

1.5.1

Euclids proof

Perhaps the most famous proof of all times is Euclids geometric proof, although it is neither the
simplest nor the most obvious4 . Euclids proof used the Figure 1.21.

Figure 1.21: Illustration for the proof from Euclid.


The idea of Euclids proof is to draw a square for each side of the right triangle 4ABC, and
divide the biggest square BCED into two rectangles, @
ABKLD and @
AKCEL. The idea is to
show that the area of the biggest square is the sum of two smaller ones, which can be expressed
through triangles sides and thus complete the proof.
A triangle 4BAD is constructed such that it has half the area of the left rectangle @
ABKLD
(pink in Figure 1.21). Another triangle 4F BC is constructed such that it has half the area of the
square BF GA. These two triangles are shown to be congruent, proving the square BF GA
has the same area as the rectangle @
ABKLD. This argument is followed by a similar version for
the right rectangle @
AKCEL and the square AHIC. Putting the two rectangles together to
reform the square on the hypotenuse, its area is the same as the sum of the area of the other
two squares.
Necessary assumptions (lemmas)

We need four elementary assumptions:

If two triangles have two sides of the one equal to two sides of the other, each to each, and
the angles included by those sides equal, then the triangles are congruent (side-angle-side).
4 The philosopher Schopenhauer has described this proof as a brilliant piece of perversity (Schopenhauer
1977; Gardner 1984, p. 153).

26

The area of a triangle is half the area of any parallelogram on the same base and having
the same altitude.
The area of a rectangle is equal to the product of two adjacent sides.
The area of a square is equal to the product of two of its sides (follows from 3).

The following steps prove the theorem:


1. Let 4ACB be a right-angled triangle with right angle CAB.
2. Draw squares CBDE, BAGF, and ACIH on each of the sides BC, AB, and CA of the
4ACB.
3. Drop a perpendicular from A to the side opposite the hypotenuse in the square BF GA.
That line divides the square BCED on two rectangles. That is, CL||BD||CE
4. Join CF and AD, to form the triangles 4BCF and 4BDA. These triangles are equivalent
except for rotation.
5. Angles CAB = BAG = 90 therefore C, A, and G are collinear. Similarly for B, A,
and H.
6. Angles CBD = F BA = 90 therefore angle ABD equals angle FBC, since both are
the sum of a right angle (90 ) and angle ABC.
7. Since AB = F B and BD = BC, triangle 4ABD must be congruent to triangle 4FBC.
8. Since the points A, K, and L lie on a straight line AL||BD, then S@
ABDLK = 2 S4ABD .
This is because they share the base BD and have the same altitude BK. (See lemma 2).
9. Since C is collinear with A and G, then square SBAGF = 2 4F BC.
10. Therefore, rectangle BDLK must have the same area as square BAGF: S@
ABDLK = S BAGF =
AB 2 .
11. Similarly, it can be shown that rectangle CKLE must have the same area as square ACIH:
2
S@
ACKLE = S ACIH = AC .
12. Adding these two results, AB 2 + AC 2 = BD BK + KL KC
13. Since BD = KL, BD BK + KL KC = BD(BK + KC) = BD BC
14. Therefore, AB 2 + AC 2 = BC 2 , since CBDE is a square.
This completes the proof, which would be enjoyable by real jedi math warriors. Those who
have less midichlorians and still learning the Way of mathematical Force are invited to look into
simpler (and more straightforward) algebraic proof.

27

1.5.2

Algebraic proof

There is a much simpler proof of the Pythagorean theorem from Equation 1.16 using a simple
algebra and the area of square and right-angle triangles.
Consider Figure 1.22, where there are two squares: a big blue square ABCD and a smaller
yellow KLMN. We tted the yellow square KLMN into ABCD so it touches the sides of
the ABCD and cuts the same pieces from the sides: AL = BM = N C = DK = a and
LB = M C = DN = AK = b as in Figure 1.22. Lets denote the side of the small yellow square
KLMN as KL = c.
Notice that the length of each side of a big blue square ABCD is AB = BC = CD = AD =
a + b. We express the areas of the whole square ABCD and its pieces (4 blue right triangulars
inside and a smaller yellow square KLMN) in terms of a, b and c.

Figure 1.22: Illustration for the proof in Subsection 1.5.2.


The central idea is to use the fact that the area of the big square is equal to the sum of its
pieces, which is SABCD = SKLM N + S4ALK + S4LBM + S4M N C + S4N DK .
Area of the big square ABCD

The total area of a square ABCD is:

SABCD = AB 2 = (a + b)(a + b) = a2 + 2ab + b2


Now lets consider the areas of the blue right triangles and yellow smaller square.
Area of the pieces of the square ABCD

The area of the yellow square KLM N is

SKLM N = KL2 = c2
All four triangles have the same area, since the smaller square KLM N cuts the same portions
of the sides of a bigger square ABCD. The area of each of the triangular, say S4ALK , is:
S4ALK =

28

1
ab
2

The area of all four triangles is:


1
S4 = S4ALK + S4LBM + S4M N C + S4N DK = 4 S4ALK = 4 ab = 2ab
2
The area of the pieces of the square ABCD is therefore:
SKLM N + S4 = c2 + 2ab
Areas of pieces comprise the area of the big square As mentioned above, the idea of the
proof is to show that the area of the large square ABCD is equal to sum of its pieces, namely
smaller yellow square KLM N and 4 blue triangles:
SKLM N + S4 = SABCD
We found the area in terms of the triangles sides a, b, and c. Lets substitute them into
expression above to get:
(a + b)(a + b) = c2 + 2ab
Open the brackets:
a2 + 2ab + b2 = c2 + 2ab
The part 2ab is the same at the left and right, so it can be cancelled:
a2 + b2 = c2 ,
which gives us the proof of the Equation 1.16. 

29

You might also like