Published on

Understanding the Fourier Transform Through Tides

Authors

The Fourier transform takes a signal that changes over time and reveals which frequencies are hiding inside it. If you haven't encountered it before, 3Blue1Brown's visual explanation is the best introduction I know of.

Any repeating signal, no matter how complicated, can be built by adding together simple sine waves of different frequencies. A tide chart, a heartbeat, a musical chord. Each is just a sum of pure oscillations. The Fourier transform works in reverse. Given a messy signal, it tells you which sine waves were added together to create it, and how strong each one is.

We've known for centuries, thanks to astronomy, exactly which frequencies should appear in the tides. This makes tide data a perfect test case. We can check whether our Fourier analysis actually works by seeing if the expected peaks show up.

Tides and Their Causes

People have been predicting tides for millennia. Water rises and falls roughly twice a day, and the heights vary with the phases of the Moon. But the details get complicated fast.

Tides come from the gravitational pull of the Moon and Sun. As the Earth rotates, different parts of the surface move through regions of higher and lower gravitational pull, and the water sloshes back and forth. The important thing is that these gravitational influences have very specific periods.

Major Tidal Constituents

PeriodNameCause
12.42 hoursM2Earth rotating under the Moon's tidal bulge
12.00 hoursS2Earth rotating under the Sun's tidal bulge
12.66 hoursN2Moon's elliptical orbit (perigee vs apogee)
23.93 hoursK1Moon and Sun's declination (tilt relative to equator)
25.82 hoursO1Moon's changing declination
24.07 hoursP1Sun's changing declination
~14 daysMfMoon and Sun coming into/out of alignment
~6 monthsSsaSolar semi-annual
~1 yearSaSeasonal changes

The naming convention (M2, S2, K1, etc.) comes from 19th-century tidal analysis. "M" means lunar (Moon), "S" means solar (Sun), and the number indicates roughly how many cycles occur per day.

If the Fourier transform works, we should see peaks at exactly these periods.

Getting the Data

NOAA maintains tide gauges across the US coast and provides free historical data through their API. I pulled 20 years of hourly water level measurements from San Francisco (2004-2023), which comes out to about 175,000 data points.

Here's what a few days of tide data looks like:

3 days of tide data

You can see the roughly twice-daily pattern, with the two daily high tides often having different heights (that's the "diurnal inequality" caused by K1 and O1).

Zooming out to a month:

1 month of tide data

Now a longer pattern emerges. The tidal range varies over about a two-week cycle. These are "spring tides" (large range, when Moon and Sun align) and "neap tides" (small range, when they're at right angles).

A First Attempt at the Fourier Transform

The Fourier transform takes our sequence of water heights and outputs an "amplitude" for each possible frequency. High amplitude means that frequency is strongly present in the signal.

Here's the power spectrum (amplitude squared) of our tide data:

Unlabeled spectrum

There are clear peaks jumping out of the noise. Let's see if they match our predictions.

The Hann Window

There's a subtlety when computing the Fourier transform of real data. The FFT assumes your signal repeats forever, with the end wrapping around to the beginning. But our tide data doesn't line up neatly. The water level at the end of our 20-year chunk has no reason to match the level at the beginning, so there's a discontinuity where the signal "jumps" when it wraps around.

This discontinuity creates problems. Sharp jumps require high frequencies to represent, so the FFT sees frequencies that aren't really in the data. Energy from the true peaks spreads into neighboring frequencies. This is called "spectral leakage."

The solution is to multiply our signal by a smoother window function before computing the FFT. The Hann window (named after Julius von Hann) tapers gradually to zero at both ends.

This smooth tapering has a much cleaner frequency response, and the ripples are greatly reduced.

Windowing comparison

The top panel shows the spectrum computed without windowing. Notice the elevated "skirt" around each peak where energy has leaked into neighboring frequencies. The bottom panel applies the Hann window first, and the peaks are sharper with a lower noise floor between them.

Windowing doesn't change where the peaks are. The frequencies are still correct. It just makes them easier to see and measure accurately.

Matching Peaks to Physics

Now let's look at the full spectrum with our expected tidal constituents labeled:

Labeled spectrum

Every major peak corresponds to a known gravitational effect. There are also many smaller peaks, so let's zoom in.

Semidiurnal Region (11-14 hours)

Semidiurnal zoom

Besides the big three (M2, S2, N2), we can see numerous minor constituents:

PeriodNameCause
11.61h2SM2Shallow water compound (interaction of S2 and M2)
11.97hK2Lunisolar declination effects
12.02hT2Solar elliptic variation
12.19hL2Lunar elliptic (variation in Moon's angular speed)
12.22hλ2Secondary lunar elliptic term
12.63hν2Evection (Sun's perturbation of Moon's orbit)
12.87hμ2Variational (Moon's speed variation near new/full moon)
12.91h2N2Second-order elliptic effect
13.13hMNS2Shallow water compound tide
13.39h2MS2Shallow water compound tide

Diurnal Region (22-28 hours)

Diurnal zoom
PeriodNameCause
22.31hOO1Second-order lunar diurnal
23.10hJ1Smaller lunar elliptic
24.84hM1Smaller lunar diurnal
26.72hρ1Larger lunar evectional
26.87hQ1Larger lunar elliptic
27.85hσ1Lunar diurnal
28.01h2Q1Second-order elliptic

Long-Period Signals (days to years)

With 20 years of data, we can also detect very low-frequency signals:

Long period
PeriodNameCause
~14 daysMfLunar fortnightly (spring-neap cycle)
~6 monthsSsaSolar semi-annual
~1 yearSaAnnual/seasonal cycle

The annual signal includes both gravitational effects and meteorological factors (barometric pressure, wind patterns, river discharge).

Why This Matters

The tidal example demonstrates several key concepts:

  1. The Fourier transform reveals hidden periodicity. The raw tide signal looks complex, but it's actually a sum of pure sinusoids at specific frequencies.

  2. Windowing reduces spectral leakage. Multiplying by a smooth window before the FFT gives cleaner results.

  3. The physics determines the frequencies. Each peak in the spectrum corresponds to a real gravitational phenomenon.


Appendix: Complete Constituent Reference

Semidiurnal Constituents (~12 hours)

These arise from the Earth rotating under the gravitational bulge twice per day.

NamePeriodDescriptionPhysical Mechanism
M212.42hPrincipal lunar semidiurnalThe dominant tidal constituent. As Earth rotates, a point passes through the Moon's tidal bulge twice per lunar day (24h 50m). Half of that is 12.42h.
S212.00hPrincipal solar semidiurnalSame mechanism as M2, but caused by the Sun. Period is exactly 12h because the solar day is exactly 24h by definition.
N212.66hLarger lunar ellipticThe Moon's orbit is elliptical. At perigee (closest), gravitational pull is ~15% stronger than at apogee. This modulates M2 at the anomalistic month (27.55 days).
K211.97hLunisolar semidiurnalCombined effect of lunar and solar declination changes on the semidiurnal tide.
L212.19hSmaller lunar ellipticArises from variation in the Moon's angular velocity as it moves through its elliptical orbit.
T212.02hLarger solar ellipticEarth's orbital eccentricity causes the Sun's tidal force to vary over the year.
2N212.91hLunar elliptic second orderSecond-order term in the expansion of lunar elliptic effects.
μ212.87hVariationalThe Moon's orbital speed varies due to solar perturbation. Faster near new/full moon, slower at quarters.
ν212.63hLarger lunar evectionalEvection: the Sun perturbs the Moon's orbit, causing a ~31.8-day oscillation in orbital eccentricity.
λ212.22hSmaller lunar evectionalA secondary term arising from the same evection perturbation as ν2.
2SM211.61hShallow waterCompound tide from nonlinear interaction of S2 and M2 in shallow water.
MNS213.13hShallow waterCompound tide generated by nonlinear interactions in shallow coastal waters.
2MS213.39hShallow waterAnother shallow-water compound tide from M2 and S2 interaction.

Diurnal Constituents (~24 hours)

These arise because the Moon and Sun are usually not directly over the equator, creating asymmetry between the two daily tidal bulges.

NamePeriodDescriptionPhysical Mechanism
K123.93hLunisolar diurnalThe largest diurnal constituent. When the Moon or Sun is north or south of the equator, the two daily high tides have different heights.
O125.82hPrincipal lunar diurnalThe Moon's declination varies over ~27.3 days as it orbits. This creates a once-daily modulation of the tide.
P124.07hPrincipal solar diurnalThe Sun's declination varies over the year (±23.4°). This creates a once-daily solar tide component.
Q126.87hLarger lunar elliptic diurnalThe diurnal equivalent of N2. Modulation of O1 by the Moon's orbital eccentricity.
J123.10hSmaller lunar elliptic diurnalSmaller elliptic perturbation of the diurnal tide.
M124.84hSmaller lunar diurnalA secondary lunar diurnal term from the geometry of the Moon's orbit.
OO122.31hLunar diurnal second orderSecond-order term in the lunar diurnal expansion.
ρ126.72hLarger lunar evectional diurnalEvection effect on the diurnal tide.
σ127.85hLunar diurnalRelated to the regression of the Moon's orbital nodes.
2Q128.01hLarger elliptic second orderSecond-order lunar elliptic effect on diurnal tide.

Long-Period Constituents (days to years)

These are low-frequency oscillations caused by longer-term orbital variations.

NamePeriodDescriptionPhysical Mechanism
Mf13.66 daysLunar fortnightlyThe beating between M2 and S2 creates the spring-neap cycle. When Moon and Sun align (new/full moon), their tidal forces add; at quarter moons, they partially cancel.
Ssa182.6 daysSolar semi-annualEarth's orbital eccentricity causes the Sun to be closest in January and farthest in July, creating a 6-month cycle.
Sa365.25 daysSolar annualCombination of gravitational effects and meteorological seasonality (temperature-driven density changes, river discharge, prevailing winds).

Data: NOAA CO-OPS, San Francisco station 9414290. 175,320 hourly observations from 2004-2023.