Skip to content

Signals as sums of sinusoids

Watch a square wave build itself from spinning arrows, hear how the recipe sets the timbre, and see why each arrow can be measured alone.

Before this1.3 · 3.4 · 3 more
Chapter 7 · Lesson 1 of 4

First, the picture

Smooth spinning arrows, one riding on another, draw a wave with flat tops. Watch the wave beside the arrows as each new arrow joins.

Eight spinning arrows draw a square wave

Watch the wave build itself.

Arrows
1
0.00 / 14.70 s
Describe this picture

A chain of spinning arrows, each riding on the tip of the one before, and beside it the wave traced by the height of the chain’s tip, over a dashed outline of the square wave it is heading for. Arrows join one at a time, each shorter and faster than the last; the readout “Arrows” counts them, up to 8. A “Hear it” button plays the wave on screen, and a transport plays and pauses the clip.

Smooth arrows, flat tops

I want to start with something that bothered me the first time I saw it. Think of the buzz of a cheap synthesiser, or an old doorbell. Its wave is as unsmooth as a wave gets: it sits flat on top, jumps straight down, sits flat on the bottom, and jumps straight back up. This is called a square wave, and it repeats forever.

The picture at the top of the page builds that wave out of nothing but spinning arrows. You met them in the page Complex exponentials & phasors (3.4): an arrow turning at a steady rate, where the height of its tip, followed over time, is a smooth sine wave. Here, each new arrow rides on the tip of the one before it, and each is shorter and faster than the last.

Every arrow is perfectly smooth, but with each one that joins, the top gets flatter and the corners get steeper. By the eighth arrow the curve is nearly the square wave. The little spikes at the corners do not go away as you add arrows; the page Convergence and the Gibbs phenomenon (7.3) explains why.

That is the whole claim of this chapter: almost any repeating signal you will meet, however angular, can be built from smooth sinusoids. The rest of this page takes the animation apart, one piece at a time.

One arrow, one sine wave

Start with a single arrow. Let it turn at a steady rate, and let the dashed line carry the tip’s height across to the wave.

One spinning arrow traces a sine

The dot follows the height of the arrow’s tip.

The dot stays level with the tip of the arrow, so it rises and falls as the arrow turns.

Arrows
1
0.00 / 6.00 s
Describe this picture

One arrow turning at a steady rate, a dashed line carrying the height of its tip across to a dot on the wave, and the wave the dot draws. When the arrow finishes one lap, a bracket over the first repeat is labelled T. The caption says “The dot stays level with the tip of the arrow, so it rises and falls as the arrow turns.”, then “One lap of the arrow draws one period T of the wave.”

Watch the dot while the arrow turns. The dashed line carries the height of the tip to the wave, so the dot rises when the tip rises and falls when the tip falls. Then watch for the bracket: when the arrow finishes one full lap, the wave has drawn exactly one repeat, and the bracket marks that repeat as T, the period.

So one lap of the arrow is one period. If one lap takes TT seconds, the arrow turns at

ω0=2πT radians per second,\omega_0 = \frac{2\pi}{T}\ \text{radians per second},

and it makes f0=1/Tf_0 = 1/T laps every second. I’ll call ω0\omega_0 the fundamental angular frequency (f0f_0 is the fundamental frequency in Hz): it belongs to the slowest arrow, and it sets the frequency you hear as the note. With θ=ω0t\theta=\omega_0 t for the angle this first arrow has turned by time tt, the dot’s height is sin⁡θ\sin\theta.

A second arrow, three times as fast

Now ride a second arrow on the tip of the first. I’ll make it turn three times as fast, so it does three laps for every lap of the first, and I’ll make it a third as long.

A second, faster arrow

Three times as fast, a third as long.

A second arrow grows on the tip of the first. The dot slides down with it.

Arrows
1
0.00 / 7.25 s
Describe this picture

A second arrow grows on the tip of the first, three times as fast and a third as long, and the dot follows the height of the tip of the whole chain. The caption ends on “The top is flatter than a plain sine, with a small dip in the middle: a step toward a flat top.”

Watch the dot while the new arrow grows. The dashed line now carries the height of the tip of the whole chain, so the dot’s height is the first arrow’s height plus the second’s. As the second arrow grows, the top of the wave gets flatter than a plain sine, with a dip in the middle of each top.

You met the word in the page Decomposing signals (2.3): an arrow that turns a whole number of times as fast as the fundamental is a harmonic. This one turns at 3ω03\omega_0, so it is the 3rd harmonic. The kkth harmonic turns at kω0k\omega_0 and adds a term bksin⁡(kω0t)b_k\sin(k\omega_0 t), where bkb_k is the arrow’s signed length. A negative bkb_k means the arrow points the opposite way.

Every harmonic fits a whole number of laps into one period TT, so after TT seconds each arrow is exactly back where it started. The sum is therefore back where it started too. Any sum of harmonics of ω0\omega_0 repeats with period TT, however many arrows you add.

Notice that the first arrow is longer than the height of the flat top. Its length is 4/π≈1.274/\pi\approx1.27, so on its own it rises above the dashed square wave. That is on purpose. The later arrows pull the top back down, and the next section gives all the lengths.

How long each arrow must be

So how long should each arrow be? Here is the recipe; the page Fourier series coefficients (7.2) shows where it comes from. For the square wave, the arrows at k=3,5,7,…k = 3, 5, 7, \dots are 1/3,1/5,1/7,…1/3, 1/5, 1/7, \dots as long as the first. The even ones, k=2,4,6,…k=2, 4, 6,\dots, have length zero. The first arrow has length 4/π4/\pi. Written out, the length of arrow kk is

bk=4πk(k odd),bk=0(k even).b_k = \frac{4}{\pi k}\quad (k\text{ odd}),\qquad b_k = 0\quad (k\text{ even}).

For now, I want you to see that it works. The wave here swings between −1-1 and +1+1, so the flat top should sit at height 1.

Here each arrow is drawn a new way, as a bar whose height shows its length. Watch the readout called “Height at the cursor”, the height of the curve at the middle of a flat top, as each bar joins.

Eight arrow lengths as bars

One bar per arrow; the readout is the curve’s height at the cursor.

Height at the cursor
1.273
Flat top (the target)
1
Arrows
1

Each new bar is one more arrow. The readout is the curve’s height at the cursor, at the middle of a flat top.

0.00 / 12.20 s
Describe this picture

The wave, with a cursor at the middle of a flat top, and below it one bar per arrow along an axis labelled “harmonic number k”. A second row above the bars, “length ÷ first arrow”, shows each bar as a fraction of the first: 1,13,15,…1, \tfrac13, \tfrac15, \dots. The first arrow itself is 4/π=1.2734/\pi=1.273 long, but the bars are drawn relative to it, which is why its bar reads 11. As each bar joins, the readout “Height at the cursor” goes 1.273, 0.849, 1.103, 0.922, 1.063, 0.947, 1.045, 0.960; the readouts “Flat top (the target)” and “Arrows” sit beside it. When the clip has finished, the cursor can be dragged along the wave, and the caption follows it: on a flat top it says “gets close to the flat top, +1.” or “gets close to the flat bottom, −1.”; at a jump it says “at a jump the arrows settle on 0, halfway.”

The height lands above 1, then below, then above, and each new arrow moves it by less than the one before. When the animation has finished, drag the cursor along the wave to read the height anywhere.

With the cursor at the middle of a flat top, the height is

4π(1−13+15−⋯ ),\frac{4}{\pi}\left(1-\frac13+\frac15-\cdots\right),

with one term for each arrow. The terms alternate in sign, so the sum overshoots and undershoots. With every term included, the bracket adds up to exactly π/4\pi/4. This is a known result, the Leibniz series; take it on trust here. The height then approaches 4π⋅π4=1\tfrac4\pi\cdot\tfrac\pi4=1.

Before we go on, a limit on what this page covers. This square wave is odd, as in the page Decomposing signals (2.3): its left-to-right mirror image is its upside-down copy. It also averages to zero over a period. For waves like that, sines alone are enough, and that is all I use here. A wave that does not average to zero needs a constant added. A wave without the odd symmetry needs cosines too. The page Fourier series coefficients (7.2) brings in both.

Same frequency, different recipe

If the first arrow decides the frequency, what do the other arrows do? Let’s listen, to a sine, a square, a sawtooth and a triangle. The sawtooth here is a falling slope that snaps back up, going from +1+1 down to −1-1. Press a wave button, then watch the first bar.

Four waves, one frequency

The first bar fixes the frequency; the other bars colour the sound.

Wave
Frequency
220 Hz

The first bar alone: a pure sine at 220 Hz. Watch the other bars rise.

0.00 / 8.00 s
Describe this picture

Bars along the same “harmonic number k” axis as before, one per arrow, and four “Wave” buttons: Sine, Square, Sawtooth and Triangle, with Sawtooth chosen to begin with. Each wave starts as a pure sine, the first bar alone; after about 2 seconds the other bars rise, and by 6 seconds the recipe is complete. The readout “Frequency” reads 220 Hz. A “Hear it” button plays the recipe on screen; it starts only when you click.

The first bar never moves, so the “Frequency” readout stays at 220 Hz whatever you choose. What changes is the other bars. The sine has the first bar only. The square adds the odd bars, and the sound becomes thinner. The sawtooth has every bar, falling off as 1/k1/k, and the sound becomes sharper, with a buzz. The triangle has only odd bars, but they shrink as 1/k21/k^2, so the sound stays gentle and close to the sine. In the triangle, bars 3, 7 and 11 hang below zero. Their signed lengths are negative, so those arrows point the opposite way, and that turns a flat top into a pointed one. Press Hear it on each wave in turn and compare.

That is why a flute and a violin can play the same note and still sound different. They share the frequency, which is the first arrow, and they differ in how long the other arrows are. The mix of harmonic lengths is a large part of the timbre, the colour of a sound. How a note starts and fades matters too.

At 220 Hz the period is T=1/220=4.5455T = 1/220 = 4.5455 ms, and the harmonics sit at 220, 660, 1100, 1540220,\ 660,\ 1100,\ 1540 Hz for k=1,3,5,7k = 1, 3, 5, 7.

Why each arrow can be measured on its own

Here is the question I could not stop asking: if someone hands me a wave, how would I find the length of one arrow in it, with all the others mixed in? The answer is a small trick, and it rests on one fact about multiplying waves.

Take two waves, multiply them point by point, and average the result over one period. You met the average of a signal on the page How big is a signal (1.3) as add up and divide. For a wave that runs continuously, the average over one period is the area from 00 to TT divided by TT:

1T∫0T(⋅) dt.\frac1T\int_0^T(\cdot)\,dt.

Here (⋅)(\cdot) stands for whatever you are averaging. It is the same add-up-and-divide, done with the running area from the pages Impulse, step and ramp (3.1) and Continuous-time convolution (5.3). When the two waves are the same harmonic, the product is never negative, so the average is positive. When they are different harmonics, the product has equal patches above and below the axis, and they cancel.

Here are four pairs, sin⁡θ×sin⁡θ\sin\theta\times\sin\theta, sin⁡θ×sin⁡3θ\sin\theta\times\sin3\theta, sin⁡3θ×sin⁡5θ\sin3\theta\times\sin5\theta, and finally the square wave times sin⁡3θ\sin3\theta. The first three use odd harmonics only, as the square wave does. Watch the shaded patches and the “average so far”: the area collected so far divided by the time elapsed so far, exactly as on the page How big is a signal (1.3).

Multiply, then average

Four pairs of waves, multiplied point by point.

Multiply the two waves point by point. Here they are the same wave, so the product never dips below zero.

Average so far
–
sin θ × sin θ–
sin θ × sin 3θ–
sin 3θ × sin 5θ–
square wave × sin 3θ–
0.00 / 14.00 s
Describe this picture

Each pair of waves, their product with its area shaded above and below the axis, and a line labelled “average so far”, over one period: the axis reads “time, as θ = ω₀t”, with ticks at 00, π\pi and 2π2\pi. The readout “Average so far” moves while the patches build. For the first pair it shows 0.5000.500 at halfway and ends at 0.50.5; for the second it already reads 0.0000.000 a quarter of the way through. Each pair’s final average joins a list under the plot. For the fourth pair the caption ends “Doubled, 0.212 becomes 0.424: the length of the third arrow.” A transport plays and pauses the clip.

At the end of the period the average so far equals the period average. The first pair is the same wave twice, so the product is never negative, and the average ends at 0.50.5. In the next two pairs the harmonics differ, and the patches above and below the axis are equal. The average ends at 00.

The fourth pair is the one we wanted. The square wave is a sum of odd arrows. Multiplying by sin⁡3θ\sin3\theta makes arrows 1, 5, 7, and so on cancel, as in the pairs before.

Only the third arrow survives, and the average ends at 0.2120.212. Like the first pair, it averages to half the arrow’s length, so double it: 0.424, the length of the third arrow. The worked example below does the same sum by hand.

The algebra below writes each sine as two spinning arrows, as on the page Complex exponentials & phasors (3.4). Why, then, do the arrow animations at the top of this page use one arrow per harmonic? They read only the tip’s height, and one arrow’s height is already a real sine. The pair is a tool for the algebra only.

Why do the pairs cancel? Write sin⁡a=eja−e−ja2j\sin a=\dfrac{e^{ja}-e^{-ja}}{2j}, and recall cos⁡x=12(ejx+e−jx)\cos x=\tfrac12\left(e^{jx}+e^{-jx}\right). Multiplying out and collecting pairs into cosines,

sin⁡a sin⁡b=−14[ej(a+b)−ej(a−b)−e−j(a−b)+e−j(a+b)]=12[cos⁡(a−b)−cos⁡(a+b)].\sin a\,\sin b=-\tfrac14\left[e^{j(a+b)}-e^{j(a-b)}-e^{-j(a-b)}+e^{-j(a+b)}\right]=\tfrac12\left[\cos(a-b)-\cos(a+b)\right].

If you have met the product-to-sum identity, this is it. So sin⁡θsin⁡3θ=12[cos⁡2θ−cos⁡4θ]\sin\theta\sin3\theta=\tfrac12[\cos2\theta-\cos4\theta]. Both cosines complete whole laps in one period, so each averages to zero. For a=ba=b the identity gives 12[1−cos⁡2a]\tfrac12[1-\cos2a], which averages to 12\tfrac12.

In general, for whole numbers m,k≥1m,k \ge 1,

1T∫0Tsin⁡(mω0t) sin⁡(kω0t) dt={12m=k0m≠k.\frac1T\int_0^T \sin(m\omega_0 t)\,\sin(k\omega_0 t)\,dt=\begin{cases}\tfrac12 & m=k\\[2pt] 0 & m\ne k.\end{cases}

Now use the trick. Suppose x(t)=∑kbksin⁡(kω0t)x(t)=\sum_k b_k\sin(k\omega_0 t), and multiply it by sin⁡(mω0t)\sin(m\omega_0 t) and average. Every term with k≠mk\neq m averages to zero. Only the term k=mk=m survives, and it contributes 12bm\tfrac12 b_m: the arrow’s signed length bmb_m times the average of sin⁡2\sin^2, which is the 0.50.5 from the first pair. That is why we double at the end. So

bm=2⋅1T∫0Tx(t) sin⁡(mω0t) dt.b_m = 2\cdot\frac1T\int_0^T x(t)\,\sin(m\omega_0 t)\,dt.

To measure one arrow, multiply by its harmonic, average, and double. The other arrows contribute nothing, so you can find them one at a time without disturbing each other. Try it on the square wave in the worked example below.

The maths behind it · dot products

Multiplying two waves and averaging works like measuring how much two arrows in space point the same way. Harmonics with different whole-number frequencies do not point the same way at all: their product averages to zero. The length of arrow kk is how far xx reaches along the direction of harmonic kk. Linear algebra calls this a dot product. It calls writing a wave as a sum of harmonics a change of basis.

Worked example

  1. Arrow lengths. For the ±1\pm1 square wave, bk=4πkb_k=\dfrac{4}{\pi k} for odd kk. So b1=1.2732b_1=1.2732, b3=0.4244b_3=0.4244, b5=0.2546b_5=0.2546, b7=0.1819b_7=0.1819, b9=0.1415b_9=0.1415.
  2. Four arrows at a flat top. With k=1,3,5,7k=1,3,5,7 at θ=π/2\theta=\pi/2: 4π(1−13+15−17)=1.2732×0.72381=0.9216\tfrac4\pi\left(1-\tfrac13+\tfrac15-\tfrac17\right)=1.2732\times0.72381=0.9216, a little below 1.
  3. Measuring the 1st arrow. The square wave is +1+1 on (0,π)(0,\pi) and −1-1 on (π,2π)(\pi,2\pi). The average of xsin⁡θx\sin\theta is 12π(∫0πsin⁡θ dθ−∫π2πsin⁡θ dθ)=2+22π=2π=0.6366.\frac1{2\pi}\left(\int_0^\pi\sin\theta\,d\theta-\int_\pi^{2\pi}\sin\theta\,d\theta\right)=\frac{2+2}{2\pi}=\frac2\pi=0.6366. Doubling gives b1=1.2732b_1=1.2732.
  4. Pencil and paper: the 3rd arrow. First the area under one hump of sin⁡3θ\sin3\theta: ∫0πsin⁡3θ dθ=[−cos⁡3θ3]0π=1−(−1)3=23,\int_0^{\pi}\sin3\theta\,d\theta=\left[-\frac{\cos3\theta}{3}\right]_0^{\pi}=\frac{1-(-1)}{3}=\frac23, since cos⁡3π=−1\cos3\pi=-1. Over (π,2π)(\pi,2\pi) the wave sits below the axis: ∫π2πsin⁡3θ dθ=[−cos⁡3θ3]π2π=−cos⁡6π+cos⁡3π3=−1−13=−23,\int_\pi^{2\pi}\sin3\theta\,d\theta=\left[-\frac{\cos3\theta}{3}\right]_\pi^{2\pi}=\frac{-\cos6\pi+\cos3\pi}{3}=\frac{-1-1}{3}=-\frac23, since cos⁡6π=1\cos6\pi=1. Check: the whole period gives ∫02πsin⁡3θ dθ=23−23=0\int_0^{2\pi}\sin3\theta\,d\theta=\tfrac23-\tfrac23=0, as a full number of laps must.
  5. The 3rd arrow, finished. The −1-1 on the second half flips the −23-\tfrac23 to +23+\tfrac23, so the average of xsin⁡3θx\sin3\theta is 12π(23+23)=23π=0.2122.\frac1{2\pi}\left(\frac23+\frac23\right)=\frac2{3\pi}=0.2122. Doubling gives b3=0.4244b_3=0.4244, matching the recipe.
  6. The 2nd arrow. The average of xsin⁡2θx\sin2\theta is 00, so b2=0b_2=0, as the recipe says.

Where you’ll meet this

Every synthesiser that builds a sound by adding sine waves is using this idea. So is every spectrum display that shows how much of each frequency a sound contains. Sound compression keeps the components you can hear and drops the ones you cannot. The next page, Fourier series coefficients (7.2), turns the multiply-and-average trick into the Fourier series formula, with exact values for any reasonable repeating wave.

The maths behind it · uncorrelated signals

The average of the product of two signals that each average to zero tells you how much they rise and fall together. Harmonics at different frequencies do not do that at all, so their powers add. The power of a wave will turn out to be the sum of the power in each harmonic, on the page Fourier series coefficients (7.2). Statistics calls that average of products the covariance, and calls two signals whose covariance is zero uncorrelated.

Reference card

QuantityFormulaNotes
Fundamentalf0=1/Tf_0=1/T, ω0=2π/T\omega_0=2\pi/Tone lap of arrow 1 per period
Harmonic kkfrequency kf0kf_0, angular kω0k\omega_0k=1k=1 is the fundamental
Sum of harmonics (odd, zero-mean waves)x(t)=∑k≥1bksin⁡(kω0t)x(t)=\sum_{k\ge1} b_k\sin(k\omega_0 t)repeats with period TT; the general case adds a constant and cosines (see Fourier series coefficients (7.2))
Square wave (±1\pm1)bk=4πkb_k=\dfrac{4}{\pi k} (kk odd), 00 (kk even)made exact in Fourier series coefficients (7.2)
Sawtooth (falling, +1→−1+1\to-1)bk=2πkb_k=\dfrac{2}{\pi k}, all k≥1k\ge1lengths in the ratio 1/k1/k
Triangle (peak 11)bk=8π2k2(−1)(k−1)/2b_k=\dfrac{8}{\pi^2k^2}(-1)^{(k-1)/2} for odd kk, 00 for even kklengths in the ratio 1/k21/k^2; b1=0.8106b_1=0.8106, b3=−0.0901b_3=-0.0901, b5=0.0324b_5=0.0324
Orthogonality1T∫0Tsin⁡(mω0t)sin⁡(kω0t) dt=12\tfrac1T\int_0^T\sin(m\omega_0t)\sin(k\omega_0t)\,dt=\tfrac12 if m=km=k, 00 if m≠km\ne km,k≥1m,k\ge1
Measuring one lengthbk=2⋅1T∫0Tx(t)sin⁡(kω0t) dtb_k=2\cdot\tfrac1T\int_0^T x(t)\sin(k\omega_0t)\,dtmultiply by the harmonic, average, double

End of lesson 7.1

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look