DSP from Scratch · Lesson 2

Amplitude, Frequency and Phase: How to Read a Sine Wave

The three numbers that describe any sine wave, and how a computer writes one down sample by sample.

  • 10 min video
  • 9 min read
  • Lab and checks
Watch on YouTube
Chapters17 parts, tap one to jump there

In one sentence

Amplitude is how tall, frequency is how often, and phase is where the wiggle starts.

Watch first, then read. The video shows every idea moving. These notes write out each step so you can check the maths at your own pace. Press any ▶ time button to jump the video to that moment.

A guitar string, the hum of a fridge, the electricity in your wall socket: they all swing back and forth in the same smooth shape. It is called a sine wave, and it is the most important shape in all of signal processing.

All you need is school maths and lesson 1.

Lesson 1 in ten seconds

A computer keeps a signal as a list of samples, taken at regular moments. We write x[n]x[n] for the value of sample nn, counting from zero, and the sample rate fsf_s is how many samples arrive each second, in hertz (Hz). If any of that is new, read lesson 1 first.

What is a sine wave?

A sine wave rises smoothly to a peak, falls through zero to a valley, and climbs back again, over and over, exactly the same each time.

  • One complete rise and fall is called a cycle.
  • The time one cycle takes is called the period.
middle lineamplitude Aone cycle · period T = 0.1 s0 s0.1 s0.2 s
A 10 Hz sine wave. It rises to a peak, falls through the middle line to a valley and climbs back, the same every time.

Why does this shape matter so much? Because anything that swings back and forth smoothly makes it: a pendulum, a spring, a vibrating string. And almost any signal can be built by adding sine waves together; lesson 3 starts that story.

Every sine wave is described by just three numbers.

Amplitude: how tall

The amplitude, written AA, is how tall the wave is, measured from the middle line up to the peak.

Double the amplitude and the wave gets twice as tall, but it keeps exactly the same rhythm. For a sound wave, a bigger amplitude means louder.

Frequency and period: how often

The frequency, written FF, is how many complete cycles happen each second. Like the sample rate, it is measured in hertz: a 10 Hz wave completes ten cycles every second.

Double the frequency and the cycles squeeze closer together, but the height stays the same. For a sound, a higher frequency means a higher note.

Frequency and period are two views of the same thing. If FF cycles happen every second, one cycle takes 1/F1/F of a second:

T=1FT = \frac{1}{F}

A 10 Hz wave repeats every tenth of a second: T=1/10 s=100 msT = 1/10\ \text{s} = 100\ \text{ms}, where a millisecond (ms) is a thousandth of a second.

Phase: where it starts

The phase, written with the Greek letter φ\varphi (phi), tells you where in its cycle the wave is at the moment you start the clock.

Change the phase and the whole wave slides left or right. Its height does not change, and neither does its speed. Only the starting point moves.

Phase is measured as an angle, because one full cycle is like one full turn of a circle:

  • a quarter of a cycle is 90°;
  • half a cycle is 180°;
  • a whole cycle is 360°, which brings the wave back to exactly where it started.

Double the amplitude

Twice as tall, same rhythm.

Double the frequency

Twice as many cycles, same height.

Shift the phase

Slid a quarter cycle. Nothing else changes.

Grey: the starting wave. Orange: the same wave with one of its three numbers changed.

Sine waves around you

WhereFrequency
The electricity from a wall socket in Europe and much of the world50 Hz
The same in North America60 Hz
The note A that an orchestra tunes to440 Hz

So when an orchestra tunes up, everyone plays a wave that completes 440 cycles every second.

How noise-cancelling headphones use phase

Phase is the secret behind noise-cancelling headphones. A tiny microphone listens to a steady drone, like the hum of an aircraft engine. The headphones then play a copy with the same amplitude and the same frequency, but with the phase moved by half a cycle. Wherever the drone goes up, the copy goes down.

the drone+the copy=in your ear
Same amplitude, same frequency, phase moved by half a cycle. Wherever the drone goes up, the copy goes down, and the two add up to nothing.

Added together in your ear, the two cancel out at every moment, and the drone disappears. Same height, same speed, opposite starting point. You can hear this happen in the lab below.

Radians from scratch

Before we hand sine waves to a computer, we need one more tool: a different way to measure angles, called radians.

Take a circle and walk around its edge. When you have walked a distance equal to the radius, the angle you have turned is one radian.

radius redge walked = r1 radturndegreesradiansfull turn360°2π ≈ 6.28half turn180°π ≈ 3.14quarter turn90°π/2 ≈ 1.57one radian≈ 57.3°1
Walk along the edge a distance equal to the radius, and the angle you have turned is one radian. A whole turn takes 2π of them.

The whole way around the edge is 2π2\pi times the radius, where π≈3.14\pi \approx 3.14. So a full turn is 2π≈6.282\pi \approx 6.28 radians, and

360°=2π rad,180°=π rad,90°=π2 rad360° = 2\pi\ \text{rad}, \qquad 180° = \pi\ \text{rad}, \qquad 90° = \frac{\pi}{2}\ \text{rad}

To turn degrees into radians, multiply by π/180\pi/180. In signal processing, one full cycle of a sine wave is 2π2\pi radians.

The computer’s view: digital frequency

People think in cycles per second. A computer only sees samples, so it asks a different question: how much of a cycle passes from one sample to the next?

If FF cycles pass every second and fsf_s samples arrive every second, then

cycles per sample=Ffs\text{cycles per sample} = \frac{F}{f_s}

Turn cycles into radians by multiplying by 2π2\pi. The result is called the digital frequency, written with the Greek letter ω\omega (omega), in radians per sample:

ω=2πFfs\omega = \frac{2\pi F}{f_s}

Then every sample of the sine wave is

x[n]=Asin⁡(ωn+φ)x[n] = A \sin(\omega n + \varphi)
  • AA sets the height;
  • ω\omega sets how far the wave turns from one sample to the next;
  • φ\varphi sets where it starts.

Worked example

A 10 Hz wave is sampled at 360 Hz. One cycle takes 360/10=36360 / 10 = 36 samples, and

ω=2π×10360=π18≈0.1745 radians per sample\omega = \frac{2\pi \times 10}{360} = \frac{\pi}{18} \approx 0.1745\ \text{radians per sample}

Take an amplitude of 1 mV and a phase of zero. What is sample 9?

Nine samples is a quarter of 36, so the wave has turned a quarter cycle, π/2\pi/2:

x[9]=1×sin⁡ ⁣(π18×9)=sin⁡ ⁣(π2)=1 mVx[9] = 1 \times \sin\!\left(\frac{\pi}{18} \times 9\right) = \sin\!\left(\frac{\pi}{2}\right) = 1\ \text{mV}

That is the very top of the wave.

1 mV0−1 mVx[9] = 1 mVn = 0n = 9n = 18n = 27n = 36
One cycle of the 10 Hz wave, sampled 360 times a second: 36 samples. Each sample turns the wave a further π/18 radians.

360/30=12360 / 30 = 12 samples per cycle. So each sample moves the wave one twelfth of a cycle:

ω=2π12=π6 rad=30°\omega = \frac{2\pi}{12} = \frac{\pi}{6}\ \text{rad} = 30°

Three common mistakes

Recap

  • A sine wave is described by three numbers: amplitude (how tall), frequency (how many cycles each second) and phase (where it starts).
  • The period is one over the frequency: T=1/FT = 1/F.
  • A full cycle is 2π2\pi radians.
  • A computer writes the wave as x[n]=Asin⁡(ωn+φ)x[n] = A\sin(\omega n + \varphi), where ω=2πF/fs\omega = 2\pi F / f_s.

Say the main idea aloud once: amplitude is how tall, frequency is how often, and phase is where the wiggle starts.

Next: what happens when you sample a wave too slowly, and why the samples can lie to you.

Interactive lab

Turn the three knobs, then cancel a hum

Set amplitude, frequency and phase to match a target wave. Then move the phase of a copy until a hum disappears, and hear it happen.

1. Three knobs

Press “Match a target wave”, then turn the knobs until your wave sits on the dashed one.

2. Cancel the hum

Play the sound, then move the copy’s phase until the hum disappears.

Sign in to open the lab

It is free. Signing in with Google also keeps your progress and your scores.

Sign in with Google

Lesson 1 of every course is open without signing in.

Check yourself

Did it stick?

Work each one out on paper first. Every question has a full worked answer.

  1. 1

    What is the period of a 25 Hz wave, in milliseconds?

  2. 2

    A 60 Hz tone is sampled at 480 Hz. How many samples fit in one cycle?

  3. 3

    For the same tone (60 Hz sampled at 480 Hz), what is the digital frequency ω\omega?

    Question 3: pick one answer

  4. 4

    Two waves both have amplitude 2 mV and frequency 50 Hz. The first has phase 0; the second has phase π\pi. What do you get when you add them?

    Question 4: pick one answer

  5. 5

    A computer stores a wave as x[n]=3sin⁡(πn/6)x[n] = 3\sin(\pi n / 6), sampled at 600 Hz. What is its frequency FF in hertz?

Sign in to open the checks

It is free. Signing in with Google also keeps your progress and your scores.

Sign in with Google

Lesson 1 of every course is open without signing in.

Free weekly email

Get the next lesson by email.

The week's new lessons, the daily facts in one place, one thing to try in the lab and one puzzle. Free.

No spam. One click to leave.