# Sleeping Better with Cosines

If you’ve ever woken up drowsy, chances are you woke up near the “bottom” of your sleep cycle. On this page I explain how math (specifically, trigonometric functions) can help you avoid that, and get more restful sleep overall. (This content comes from Chapter 1 of my book, Everyday Calculus.)

As the chart shows, on average one sleep cycle lasts 90 minutes, or 1.5 hours, and within each 90-minute period we descend into deeper stages of sleep, reach the bottom of the cycle, and then climb back up to a nearly-awake stage called REM sleep.

The fact that our sleep cycles on average every 90 minutes means that the sleep stage S can reasonably be described by a trigonometric function. In chapter 1 of Everyday Calculus I derived the equation for this function:

$S(t)=2\cos\left(\frac{2\pi}{1.5}t\right)-2, \$

where is the number of hours you’ve slept, and “awake” corresponds to S=0, “REM sleep” to S=-1, and so on (and where the Stages 3 and 4 have been lumped together). This model does a good job of capturing the peaks and troughs in the chart above. It also helps determine the optimal number of hours to sleep. Since we want to wake up no deeper than in the REM sleep stage, what we’d like is for

$S(t) \geq -1. \$

This works out to a roughly 15 minute cushion—were we, for example, to awake after sleeping between 5 hours and 45 minutes and 6 hours and 15 minutes, we wouldn’t feel groggy. A quick look at the chart above convinces us that this might be true—score another one for our model!

But what if your sleep cycle isn’t 90 minutes long? What if it’s 84, or 97 minutes long? (Today you can buy gadgets that determine your own sleep cycle length.) That’s where this model really shines. If we call your sleep cycle length (measured in minutes), then our equation becomes

$S(t)=2\cos\left(\frac{120\pi}{T}t\right)-2, \$

where the “120=2(60)” came from converting from hours to minutes. Here’s an interactive graph that you can use to explore how changing T changes those cushions around the new average cycle length T.

Graph controls: You can pan by clicking and dragging the graph. You can also zoom in/out using your mouse wheel, or by clicking the arrow below the wrench, or by adjusting the bounds of the graph by clicking on the wrench. Finally, click on any dots on the graph to see the coordinates of those points.

## What’s Going On In This Graph?

1. The hours slept is on the horizontal axis, while the sleep stage is on the vertical axis.

2. The blue curve is our model, and the red line is S=-1.

3. Click at any point where the curve intersects the line and you’ll see the coordinates. For example, the first intersection is at (0.25,-1). Since is measured in hours, this translates to 0.25(60)=15 minutes.

4. Now change the sleep cycle length by using the slider in pane 2 on the left.

5. Find the new intersection points to figure out your optimal wake-up times.