Concept units

Sine waves

Basic

Before you start

You need nothing else first. This unit starts from scratch.

The idea in one paragraph

Walk a point around a circle of radius 1. Its height goes up to 1, back through 0, down to −1 and up again, over and over. That height, as a function of the angle turned, is the sine; the sideways position is the cosine. Plot either against the angle and you get a smooth wave that repeats every full turn. Multiply the input by a larger number and the wave repeats faster. So sine and cosine turn any angle or position into a value between −1 and 1 that cycles.

Sine is the height of a point going around a circle

Draw a circle of radius 1 around the origin. Start a point at (1, 0) and turn it counterclockwise by an angle θ (the Greek letter theta). The point's position is then (cos θ, sin θ). That is the definition: the cosine is the point's x, and the sine is its y.

At 0° the point is at (1, 0), so sin 0° = 0 and cos 0° = 1. At 90° it is at the top, (0, 1). At 180° it is at (−1, 0), and at 270° at the bottom, (0, −1). At 360° it is back where it started, and everything repeats.

The point's height, plotted against the angle, traces a sine wave
sin 120° = 0.866   cos = −0.500
Try this. The green line is the point's height, sin θ; the wave on the right records it at every angle so far. Predict the first angle after 0° where the sine is −1, then slide to check. Keep going past 360° and watch the wave repeat.
Worked example

Find sin 30°. Turn the point 30° from (1, 0). Draw a line from it straight down to the x-axis. You get a right triangle with long side 1 and a 30° angle at the origin. Now reflect it in the x-axis. The triangle and its mirror image together have a 60° angle at the origin, between two sides of length 1. Because those two sides are equal, the other two angles are equal too. All three add up to 180°, so each is 60°. The two triangles form an equilateral triangle with sides of 1. Its vertical side, of length 1, is twice the point's height, so the height is 0.5.

So sin 30° = 0.5. By Pythagoras, cos 30° = √(1 − 0.25) = √0.75 ≈ 0.866.

Your turn. Use the circle's symmetry to find sin 150° and sin 210°.

Answer

150° is the mirror image of 30° across the vertical axis, at the same height: sin 150° = 0.5. 210° is 30° past the left side, below the axis: sin 210° = −0.5.

Code measures angles in radians

Most programs, including NumPy, measure angles in radians rather than degrees. One radian is the angle at which the point has traveled a distance of 1 along the circle's edge. The whole edge is 2π ≈ 6.283 long, so a full turn is 2π radians. Half a turn is π, and a quarter turn is π / 2. To convert, multiply degrees by π / 180.

A full wave, from one peak to the next, is called a period. The sine's period is 2π radians.

Multiplying the input makes the wave repeat faster

Sines are also used to turn a position, not an angle, into a wave. Take a position x between 0 and 1 and compute sin(2πfx). The 2π makes one unit of x a full turn, and the frequency f says how many full waves fit between 0 and 1. A larger f means a shorter period and more waves. Low frequencies change slowly across the range; high frequencies tell nearby positions apart.

The frequency sets how many waves fit between 0 and 1
Try this. The two dots sit at x = 0.30 and x = 0.35. At f = 1 their sines are close: 0.95 and 0.81. Goal: find the smallest frequency at which the two dots end up on opposite sides of zero.
This is a simplification

This page shows only the plain wave. A wave can also be stretched up and down by multiplying it, called its amplitude, or slid sideways by adding to the input, called its phase. The cosine is the sine slid a quarter turn: cos θ = sin(θ + 90°).

sine.py: NumPy's sin takes radians

import numpy as np

degrees = np.array([0, 30, 90, 180, 270, 360])
print(np.round(np.sin(np.radians(degrees)), 3))  # np.radians turns degrees into radians

x = np.array([0, 1/12, 1/6, 1/4])
print(np.round(np.sin(2 * np.pi * 3 * x), 3))   # sin(2πfx) with f = 3: 3 waves per unit of x (np.pi is π)
[ 0.   0.5  1.   0.  -1.  -0. ]
[ 0.  1.  0. -1.]

The -0. is a tiny rounding error, about −2 × 10−16, rounded to zero.

Check yourself

  1. What is cos 0°? What is sin(θ + 360°) compared with sin θ?

    Answer

    cos 0° = 1, the x of the starting point (1, 0). sin(θ + 360°) equals sin θ, because a full turn brings the point back to the same place.

  2. How many peaks does sin(2π × 2 × x) have for x between 0 and 1?

    Answer

    Two. The frequency 2 fits two full waves, each with one peak.

  3. You call np.sin(90) expecting 1 and get 0.894. What went wrong?

    Answer

    NumPy read 90 as 90 radians, not 90 degrees. Use np.sin(np.radians(90)) or np.sin(np.pi / 2).

Go further

Optional background, for readers who want more than this page.

Where this shows up

Units that build on this one