---
title: "Fit a period and measure the risk of a false peak"
description: "Derive a weighted floating-mean search, calibrate its full-grid maximum and separate signal detection from choosing the correct alias."
canonical_url: "https://sandboxphysics.com/stories/observing-cadence/period-search/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/observing-cadence/period-search/"
last_modified: "2026-10-28"
---

[Choose when to observe a changing sky](https://sandboxphysics.com/stories/observing-cadence/)

AC07 · L3

# Fit a period and measure the risk of a false peak

Sandbox Physics · 2026-10-28

A period search fits a family of models, one at each frequency. Its peak can tell us which model best matches the samples. To assess a false detection, we must also measure how high the largest peak becomes when the same search sees noise.

## Before you begin

Complete “Count the cycles between exposures”. A weighted mean gives more influence to precise measurements; least squares chooses coefficients that minimize squared residuals. The two-equation system below is solved by substitution, so no matrix algebra is assumed.

## Fit an offset at every frequency

Write each observation as a constant offset plus cosine and sine components and an error. At a fixed frequency this is linear in three unknown coefficients. The cosine and sine together allow any sinusoidal phase. Quoted standard errors supply inverse-variance weights when errors are independent and Gaussian.

A sample mean can differ from the true mean if visits miss part of a cycle. Subtracting it once and forcing the fitted wave through zero can suppress a real signal. Let the constant float with each trial frequency instead. This is the generalized, or floating-mean, Lomb–Scargle fit.

Keep times in days and frequency in cycles per day. The browser fits normalized linear intensity; the real tutorial fits I-band magnitudes. Both are numerical sinusoid fits, but their amplitudes describe different physical quantities.

$$
y_j=c+a\cos(2\pi ft_j)+b\sin(2\pi ft_j)+\epsilon_j,\qquad \chi^2=\sum_j\frac{[y_j-c-a\cos(2\pi ft_j)-b\sin(2\pi ft_j)]^2}{\sigma_j^2}
$$

At each f, choose a, b and c to minimize this dimensionless error measure. The assumptions on errors determine its statistical interpretation.

Reading: Zechmeister & Kürster, generalized Lomb–Scargle, arXiv v1 · VanderPlas, Understanding the Lomb–Scargle Periodogram, arXiv v1

## Eliminate the constant, then solve two equations

A derivative measures how the mismatch changes when one coefficient is nudged. At a smooth minimum that first-order change is zero. Differentiating a squared residual brings down twice the residual, multiplied by the negative coefficient of the nudged term. Setting each resulting weighted sum to zero gives the fit equations.

Normalize the inverse-variance weights so their sum is one. Call the weighted means of the data, cosine and sine Y, C and S. Setting the derivative with respect to the constant to zero gives the constant as the data mean minus the two fitted trigonometric means.

Substituting that constant centers both trigonometric columns. Define CC and SS as their weighted squared deviations, CS as their weighted cross product, and YC and YS as their cross products with the centered data. Differentiating with respect to the remaining coefficients gives two simultaneous equations.

Multiply the first equation by SS and the second by CS, then subtract to isolate a. Reverse that elimination to get b. The determinant vanishes if the sampled trigonometric columns supply no independent information at that frequency; the program then skips that trial.

$$
w_j=\frac{\sigma_j^{-2}}{\sum_k\sigma_k^{-2}},\quad Y=\sum_jw_jy_j,\quad C=\sum_jw_j\cos(2\pi ft_j),\quad S=\sum_jw_j\sin(2\pi ft_j),\quad c=Y-aC-bS
$$

Weighted centering accounts for an incomplete phase distribution instead of assuming it averages to zero.

$$
CC\,a+CS\,b=YC,\qquad CS\,a+SS\,b=YS,\qquad D=CC\,SS-CS^2
$$

For example, CC is the weighted sum of squared cosine-minus-C; YC is the weighted product of data-minus-Y and cosine-minus-C. The other terms follow the same definition.

$$
a=\frac{SS\,YC-CS\,YS}{D},\qquad b=\frac{CC\,YS-CS\,YC}{D}
$$

These formulas are the two-equation elimination result. The saved Python replay independently uses weighted orthogonal projections.

Reading: Zechmeister & Kürster, generalized Lomb–Scargle, arXiv v1 · VanderPlas, Understanding the Lomb–Scargle Periodogram, arXiv v1

## Turn fit improvement into a periodogram

Fit a constant-only reference using the same weights. At each frequency compare its squared residual sum with the best sine/cosine/constant fit. Divide the improvement by the reference value. The resulting standard power lies between zero and one: zero means no improvement, one means a perfect fit to the samples.

A power of 0.9 is not a ninety-percent chance that a period is correct. With few points, a flexible sinusoid can achieve large improvements even for noise. Searching more frequencies offers more chances to find a high peak.

A finite observing span makes narrow frequency structure on a scale comparable to one divided by that span. Use several grid points across it. The real replay chooses a spacing one fifth of that scale and saves its full frequency grid. The frequency limits are declared choices tied to the physical question.

$$
P(f)=1-\frac{\chi^2(f)}{\chi^2_0},\qquad \Delta f_{\rm grid}=\frac1{5T_{\rm span}}
$$

The fine grid samples finite-baseline peaks; the baseline and alias pattern still set the available information.

Reading: Astropy 8.0.2 Lomb–Scargle documentation · VanderPlas, Understanding the Lomb–Scargle Periodogram, arXiv v1

## Calibrate the maximum over the whole search

The null model for the replay is a constant source with independent Gaussian errors of the quoted sizes. Draw one noisy value at each actual timestamp, fit every declared frequency, and save the largest power. Repeat this entire process many times. The distribution of maxima includes both the observing window and the number of frequencies searched.

Count null maxima at least as high as the measured maximum. With B trials and K exceedances, the finite Monte Carlo rank below provides a nonzero result even if no exceedance is seen. Its numerical resolution is about one over B. A very small claimed false-alarm probability requires many trials; a short simulation cannot certify an arbitrarily rare tail.

Use an independent noise sample to test the chosen threshold. The real-data tutorial calibrates a five-percent threshold using 4096 null searches and tests it with 1024 fresh searches. The observed held-out rates are 4.39 and 4.49 percent for the full and sparse timestamp patterns. These checks address the declared independent-Gaussian model; red noise or shared calibration errors require another null model.

$$
\mathrm{FAP}(z)=\Pr\!\left[\max_{f\in\mathcal G}P(f)\ge z\mid\text{constant source and stated noise}\right],\qquad p_{\rm MC}=\frac{K+1}{B+1}
$$

The conditioning is on a noise model. It is neither the probability that the source is constant given the data nor the probability that the selected frequency is correct.

Reading: Astropy 8.0.2 Lomb–Scargle documentation · VanderPlas, Understanding the Lomb–Scargle Periodogram, arXiv v1

## Worked comparison: a higher peak can mean weaker evidence

The frozen OGLE first-season sample has twenty-five measurements. Its maximum power is 0.6418 and the finite Gaussian-null tail rank is 0.004882. Keeping every third measured point leaves nine points. Their maximum power rises to 0.8992, yet the corresponding tail rank rises to 0.2060.

The sparse fit explains more of its selected samples, but noise with only nine samples also fits impressively somewhere in this wide search. Comparing peak heights without recalibrating the sampling would reverse the lesson. The two actual timestamp patterns each receive their own null simulation and use the same explicit search grid.

The synthetic browser examples below provide a separate controlled comparison. Their known source period lets us label the once-nightly alias directly.

Synthetic exposures, seed 707; fixed source period 0.635 days. Generated by freeze-synthetic.ts.

| Schedule | Exposures | Strongest period (days) | Flash triggers |
| --- | --- | --- | --- |
| Once nightly | $24$ | $2.352941$ | $0$ |
| Three visits per night | $72$ | $0.634921$ | $0$ |
| Jitter and gaps | $19$ | $0.634921$ | $0$ |
| Missed flash | $96$ | $0.634921$ | $0$ |
| Caught flash | $96$ | $0.634921$ | $4$ |

Reading: OGLE-IV LMC RR Lyrae official data README · Zechmeister & Kürster, generalized Lomb–Scargle, arXiv v1 · Astropy 8.0.2 Lomb–Scargle documentation

## Count wrong aliases separately from missed signals

A false-alarm rate asks how often noise is mistaken for a detection. It does not tell us how often a real signal is missed or assigned a wrong period. Inject a specified signal into new noise at the same timestamps, run the unchanged search and threshold, and compare the recovered frequency with the known input.

The real replay uses 128 synthetic sinusoidal magnitude signals with semi-amplitude 0.1 mag, random phases and frequencies between 0.3 and 4.8 cycles per day. A correct recovery lies within one inverse baseline of the injected frequency. In the full twenty-five-point schedule, 112 injections cross threshold: 36 choose the correct-frequency neighborhood and 76 choose another alias. Sixteen miss threshold.

Those counts describe that signal family, amplitude, frequency range and error model. A different population needs another injection experiment. The distinction is useful even before a population model is finalized: a detection threshold and a period-identification rule answer different questions.

$$
\text{correct detected}+\text{aliased detected}+\text{missed}=\text{all injections}
$$

These categories are defined before measuring the recovery rate. False positives come from the separate null sample.

Reading: VanderPlas, Understanding the Lomb–Scargle Periodogram, arXiv v1 · Astropy 8.0.2 Lomb–Scargle documentation

## Exercises and explanations

1. A colleague widens the frequency search after calibrating a five-percent threshold on a smaller range. Can they keep that threshold?

   Read the explanation

   The larger search supplies more opportunities for a noise maximum. Recalibrate using the expanded grid and the same timestamps/noise model. A threshold belongs to the complete search procedure.

2. Ninety injections pass a threshold, thirty-five have the right frequency and fifty-five choose aliases. Ten are missed. What are the detection and correct-period recovery fractions?

   Read the explanation

   Detection is ninety out of one hundred. Correct-and-detected recovery is thirty-five out of one hundred; it is not ninety percent. Among detected cases, thirty-five out of ninety select the declared correct-frequency neighborhood.

3. Every residual at neighboring times tends to have the same sign. What should change before trusting an independent-noise FAP?

   Read the explanation

   Investigate time-correlated noise or trends. A Gaussian simulation with independent draws misses that correlation. Use a physically justified covariance or another validated correlated-noise null, and repeat the entire search calibration.

## Try the prediction

### [Diagnose a convincing wrong peak](https://sandboxphysics.com/labs/observing-cadence-aliases/)

1. With once-nightly visits, compare the strongest trial period with the known synthetic source period. Locate other aliases before changing anything.
2. Select the same preset again and export both records. Their timestamps stay fixed and the detector seed changes; compare peak height with the persistence of the alias family.
3. Use the measured OGLE replay to compare full-search false alarms with correct-period injection recovery.

[Previous: Count the cycles between exposures](https://sandboxphysics.com/stories/observing-cadence/sampling-windows/) [Next: Search an observed OGLE variable star and count the aliases](https://sandboxphysics.com/stories/observing-cadence/ogle-lightcurve/)

## Sources and calculation scope

1. [VanderPlas, Understanding the Lomb–Scargle Periodogram, arXiv v1](https://arxiv.org/pdf/1703.09824v1)

   28 March 2017; Sections 3.2/4.2 and Figures 7–14 for windows and aliases; Sections 6.1–6.2 for weighted floating mean; Section 7.1 and 7.4.2/Figure 26 for grid and FAP. Published journal counterpart: ApJS 236,16 (2018). This guide pins the arXiv version.

2. [Zechmeister & Kürster, generalized Lomb–Scargle, arXiv v1](https://arxiv.org/html/0901.2573v1)

   16 January 2009, Section 2 equations 4–18 and Appendix A.1: weighted sine/cosine/offset normal equations and normalized chi-square reduction. The replay uses orthogonal projections as an independent numerical formulation.

3. [Astropy 8.0.2 Lomb–Scargle documentation](https://docs.astropy.org/en/stable/timeseries/lombscargle.html)

   Consulted 28 October 2026; page updated 15 October 2026. Additional Arguments, standard normalization, peak significance and RR Lyrae example. Default floating mean, same-times/same-grid FAP, and no general average-Nyquist cutoff for irregular data.

4. [OGLE-IV LMC RR Lyrae official data README](https://www.astrouw.edu.pl/ogle/ogle4/OCVS/lmc/rrlyr/README)

   Column definitions for HJD minus 2450000, I-band magnitude and uncertainty; public-data citation requirement. Frozen per-object file OGLE-LMC-RRLYR-00001.dat and catalog row are retained with SHA-256 and HTTP metadata.
