Tutorials › Calculus I › Fitting Sinusoidal Models to Repeating Data

Trigonometric Function Toolkit · Tutorial 131 of 1495

Fitting Sinusoidal Models to Repeating Data

Build a practical sinusoidal model from repeating data, estimate its key parameters, and assess how well it predicts separate observations.

Beginner 10 min read

What You'll Learn

  • Organize repeated measurements to identify corresponding peaks and troughs
  • Estimate a period from the spacing between repeated peaks or troughs
  • Calculate a model's midline and amplitude from observed high and low values
  • Assemble a cosine model with a peak at a chosen reference input
  • Check predictions using data points kept separate from the fitting observations
  • Interpret prediction differences as residuals and recognize limits of a simple fit

From Repeating Measurements to a Model

A sinusoidal model is useful when measurements rise and fall in a regular repeating pattern. Examples include approximate daily temperature cycles, seasonal measurements, and the height of a rotating object above the ground. Real data are rarely perfect: measurements may be noisy, and the pattern may not repeat at exactly the same values each time.

The aim here is to build a reasonable model from observed data, rather than to claim that every measurement lies exactly on one ideal curve. We will estimate a cycle length, a typical high and low, and then use those estimates to make predictions. Crucially, we will check predictions against observations that were not used to choose the model.

The Model and Its Parameters

For data that repeat approximately every \(P\) input units, a convenient cosine model is

$$ y=M+A\cos\!\left(\frac{2\pi}{P}(x-C)\right). $$

Here \(x\) is the input, \(y\) is the measured output, \(M\) is the midline, \(A\) is the amplitude, \(P\) is the period, and \(C\) is a reference input chosen to correspond to a peak. We take \(A\) and \(P\) to be positive. The formula uses radians: one full cosine cycle corresponds to an increase of \(2\pi\) in its angle.

Definition: The midline is the center level about which the model oscillates. The amplitude is the distance from that level to a peak or trough. The period is the input interval over which one complete cycle repeats.

In an exact model, the maximum output is \(M+A\) and the minimum is \(M-A\). A peak at \(x=C\) fixes the horizontal reference point: substituting \(x=C\) makes the cosine equal to \(1\). If the input has units, \(P\) and \(C\) have those same units; \(M\) and \(A\) have the output's units.

Earlier material on sinusoidal models establishes how these parameters determine the graph. The practical task here is to estimate them from repeated measurements, where observed highs and lows may differ slightly from cycle to cycle.

Turning Observed Extremes into Estimates

Start by arranging measurements in order of input and looking for repeated peaks and troughs. Peaks are observations near local highs; troughs are observations near local lows. A local high need not be the largest value in the entire data set: it is a high relative to nearby measurements. Once corresponding peaks have been identified, estimate the period from the gaps between their input values. The same can be done with repeated troughs.

Because observations can vary, it is often sensible to average several measured highs and several measured lows. Let \(H\) be the average of the selected high values and \(L\) the average of the selected low values. Then estimate the midline and amplitude by

$$ M=\frac{H+L}{2}, \qquad A=\frac{H-L}{2}. $$

These formulas come from the maximum and minimum levels of the model. If its upper level is \(H=M+A\) and its lower level is \(L=M-A\), adding the equations gives \(H+L=2M\), while subtracting the lower-level equation from the upper gives \(H-L=2A\). Dividing by \(2\) yields the estimates above. When measurements are noisy, the equations are approximate descriptions of the data, not claims that every observed extreme equals the fitted model's extreme exactly.

For peak inputs \(x_1,x_2,\ldots,x_n\) observed in order, there are \(n-1\) intervals between successive peaks. A useful period estimate is their average:

$$ P\approx \frac{(x_2-x_1)+(x_3-x_2)+\cdots+(x_n-x_{n-1})}{n-1}. $$

Averaging multiple intervals can reduce the effect of small measurement or timing differences. It is important to compare like with like: the gap from a peak to the next peak estimates a full period, while the gap from a peak to the next trough is about half a period.

A Practical Fitting Sequence

1
Identify repeating features.
Locate several plausible peaks and troughs, recording their input and output values. Keep track of which observations will be used to estimate the model.
2
Estimate the period.
Measure the input gaps between successive peaks or successive troughs, then average the gaps if there is more than one.
3
Estimate vertical parameters.
Average the selected high outputs and low outputs to obtain \(H\) and \(L\), then calculate \(M=(H+L)/2\) and \(A=(H-L)/2\).
4
Set the horizontal reference.
Choose an observed peak input as \(C\), then write the cosine model using the estimated \(M\), \(A\), \(P\), and \(C\).
5
Check separate observations.
Substitute inputs that were not used to estimate the parameters, compare each prediction with its observed output, and describe the differences.

This sequence is a transparent hand-fitting method. It does not guarantee the single “best” model under every possible definition of best. Instead, it gives estimates that can be explained and checked directly against the data.

Worked Examples

Worked Example: Estimating a Daily Cycle from Repeated Highs and Lows

Suppose measurements \(y\), in degrees, are taken at input values \(x\), in hours. Three observed peaks occur at \(x=1,25,49\), with outputs \(20,22,21\). Two observed troughs occur at \(x=13,37\), with outputs \(8,10\). Use these extrema to fit a cosine model. Then check observations \(y=15.3\) at \(x=7\) and \(y=14.8\) at \(x=31\), which were not used in fitting.

The successive peak gaps are

$$ 25-1=24,\qquad 49-25=24. $$

Their average is \((24+24)/2=24\), so estimate the period as \(P=24\) hours. The trough inputs are also separated by \(37-13=24\) hours, consistent with that estimate.

The average high output and average low output are

$$ H=\frac{20+22+21}{3}=\frac{63}{3}=21, \qquad L=\frac{8+10}{2}=\frac{18}{2}=9. $$

Thus

$$ M=\frac{21+9}{2}=\frac{30}{2}=15, \qquad A=\frac{21-9}{2}=\frac{12}{2}=6. $$

Choose the observed peak at \(C=1\). The fitted model is

$$ y=15+6\cos\!\left(\frac{2\pi}{24}(x-1)\right) =15+6\cos\!\left(\frac{\pi}{12}(x-1)\right). $$

At \(x=7\), the angle is \(\frac{\pi}{12}(7-1)=\frac{\pi}{2}\), and \(\cos(\pi/2)=0\). The predicted output is \(15+6(0)=15\) degrees. The residual, defined here as observed output minus predicted output, is \(15.3-15=0.3\) degrees.

At \(x=31\), the angle is \(\frac{\pi}{12}(31-1)=\frac{30\pi}{12}=\frac{5\pi}{2}\), and \(\cos(5\pi/2)=0\). The predicted output is again \(15+6(0)=15\) degrees. The residual is \(14.8-15=-0.2\) degrees. Both separate observations are within \(0.3\) degrees of the model's predictions, which is a useful check, though it does not prove that the model will be accurate at every input.

Worked Example: Using Noisy Extreme Measurements

A repeating measurement has observed peaks at \(x=3,13,23\), with outputs \(9,8.8,9.2\), and troughs at \(x=8,18\), with outputs \(3.1,2.9\). Estimate a model and check separate observations \(y=6.2\) at \(x=5.5\) and \(y=5.8\) at \(x=10.5\).

The peak gaps are \(13-3=10\) and \(23-13=10\), so their average is \((10+10)/2=10\). The trough gap is \(18-8=10\), supporting the estimate \(P=10\).

The average of the three high outputs is

$$ H=\frac{9+8.8+9.2}{3}=\frac{27}{3}=9. $$

The average low output is \(L=(3.1+2.9)/2=6/2=3\). Therefore,

$$ M=\frac{9+3}{2}=6, \qquad A=\frac{9-3}{2}=3. $$

With \(C=3\), the model is

$$ y=6+3\cos\!\left(\frac{2\pi}{10}(x-3)\right) =6+3\cos\!\left(\frac{\pi}{5}(x-3)\right). $$

For \(x=5.5\), the angle is \(\frac{\pi}{5}(5.5-3)=\frac{\pi}{5}(2.5)=\frac{\pi}{2}\). The prediction is \(6+3\cos(\pi/2)=6\). Its residual is \(6.2-6=0.2\).

For \(x=10.5\), the angle is \(\frac{\pi}{5}(10.5-3)=\frac{\pi}{5}(7.5)=\frac{3\pi}{2}\). The prediction is \(6+3\cos(3\pi/2)=6\). Its residual is \(5.8-6=-0.2\). These check inputs are distinct from the peak and trough inputs used in the fit. The small differences are consistent with measurement variation around the idealized curve.

Worked Example: Estimating a Cycle from Repeated Features

Suppose peaks are observed at \(x=0,8,16\), with outputs \(5,6,5.5\), and troughs at \(x=4,12\), with outputs \(-1,-0.5\). Estimate a cosine model, then check observations \(y=2.5\) at \(x=2\) and \(y=2.2\) at \(x=6\).

The peak gaps are \(8-0=8\) and \(16-8=8\), with average \((8+8)/2=8\). The trough gap is \(12-4=8\). Estimate \(P=8\).

The average high and low outputs are

$$ H=\frac{5+6+5.5}{3}=\frac{16.5}{3}=5.5, \qquad L=\frac{-1+(-0.5)}{2}=\frac{-1.5}{2}=-0.75. $$

Hence

$$ M=\frac{5.5+(-0.75)}{2}=\frac{4.75}{2}=2.375, \qquad A=\frac{5.5-(-0.75)}{2}=\frac{6.25}{2}=3.125. $$

Choose \(C=0\), giving

$$ y=2.375+3.125\cos\!\left(\frac{2\pi}{8}x\right) =2.375+3.125\cos\!\left(\frac{\pi}{4}x\right). $$

At \(x=2\), the angle is \(\frac{\pi}{4}(2)=\frac{\pi}{2}\), so the prediction is \(2.375+3.125(0)=2.375\). The residual is \(2.5-2.375=0.125\).

At \(x=6\), the angle is \(\frac{\pi}{4}(6)=\frac{3\pi}{2}\), so the prediction is again \(2.375\). The residual is \(2.2-2.375=-0.175\). The two checks are near the fitted midline, as expected at these quarter-cycle positions.

Why the Parameter Estimates Work

The vertical estimates follow directly from the model's extreme values. At a peak, the cosine value is \(1\), so the model output is \(M+A\). Half a period later, the cosine value is \(-1\), so the output is \(M-A\). If the observed high and low levels are represented by \(H\) and \(L\), then solving those two equations gives

$$ H=M+A,\qquad L=M-A, $$
$$ H+L=2M \quad\Longrightarrow\quad M=\frac{H+L}{2}, \qquad H-L=2A \quad\Longrightarrow\quad A=\frac{H-L}{2}. $$

The period estimate has a similarly direct basis. The cosine function completes a cycle when its angle increases by \(2\pi\). In the fitted model, increasing \(x\) by \(P\) changes the angle by \(\frac{2\pi}{P}P=2\pi\). Thus the model repeats after an input interval \(P\). Successive peaks correspond to the same phase of the cycle, so their input separation estimates this period.

Checking a Fit and Avoiding Common Mistakes

A check is most informative when its observation was not used to choose the model parameters. If a measured high helped determine \(H\), comparing the model to that same high is not an independent test. It can still confirm that the arithmetic was carried out consistently, but it provides little evidence about how well the model predicts other data. Set aside some observations for checking whenever the data set allows it.

For each check, calculate the prediction by substituting its input into the fitted equation. Then calculate the residual as observed output minus predicted output. A positive residual means the observation is above the prediction; a negative residual means it is below. Residuals are measured in the output's units. Their sizes help describe the fit, but a few small residuals do not establish that every future prediction will be close.

A common period error is to mistake a peak-to-trough gap for a full cycle. For example, if peaks are 24 hours apart, a trough about 12 hours after a peak is expected. Calling that 12-hour gap the period would produce a model that repeats twice as quickly as the data. Check whether the features being compared are the same phase: peak to peak or trough to trough gives a full cycle; peak to the next trough gives about half a cycle.

Another mistake is to treat noisy observations as exact extremes. In the second example, the three peak outputs were not identical. Their average, \(9\), represents a typical high; it does not mean that each observed peak must equal \(9\). Averaging estimates can be useful, but the resulting model remains an approximation.

Finally, a sinusoidal model is appropriate only when the pattern is reasonably periodic and its typical high, low, and cycle length remain broadly stable. A strong upward trend, irregular cycles, or changing amplitudes can make a single sinusoid misleading. Inspect the data before fitting, and judge the equation by separate checks as well as by how plausible its parameters are.

Key takeaway: Estimate the period from repeated same-phase features, estimate the midline and amplitude from representative highs and lows, and test the resulting equation on observations that were not used to fit it.

Check Your Understanding

Use the definitions and fitting steps above to answer these questions.

  1. Observed peaks occur at \(x=2,14,27\). What are the successive peak gaps, and what is their average period estimate?
  2. If the average observed high is \(18\) and the average observed low is \(6\), calculate the estimated midline and amplitude.
  3. For a cosine model with period \(P=8\) and a peak at \(C=1\), what angle is used when \(x=3\), and what fraction of a cycle after the peak is this?
  4. Why is a data point used to estimate a model parameter a less informative check than a point held back from fitting?
  5. A model predicts \(12.4\) units at a check input, while the observed output is \(12.1\) units. Find the residual using observed minus predicted, and interpret its sign.

Test yourself: Calculus I final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon