The Goertzel Algorithm for Cycle Detection
How spectral analysis extracts dominant frequencies from market data, and why Goertzel outperforms FFT for our purposes.
About this content: This page describes observable market structure through the Fractal Cycles framework. It does not provide forecasts, recommendations, or trading instructions.
The Challenge of Finding Cycles
How do you find periodic patterns in noisy data? This is not a trivial problem. Price data contains trend components, random noise, and potentially multiple overlapping cycles of different lengths. Separating these elements requires mathematical tools designed for frequency analysis.
The standard approach in signal processing is the Fast Fourier Transform (FFT), which decomposes a signal into its constituent frequencies. However, FFT has limitations for market analysis that led us to prefer the Goertzel algorithm.
What Is the Goertzel Algorithm?
The Goertzel algorithm, developed by Gerald Goertzel in 1958, computes the power spectrum at specific frequencies. Unlike FFT, which calculates power across all frequencies simultaneously, Goertzel lets us target the frequencies we care about.
For cycle detection in markets, this targeted approach offers several advantages:
- Computational efficiency: We only calculate what we need
- Flexible frequency selection: We can focus on tradeable cycle lengths
- Better handling of non-stationary data: Markets are not stationary signals
- Cleaner peak detection: Less spectral leakage between adjacent frequencies
How It Works
The algorithm processes price data through a recursive filter that accumulates phase and magnitude information for each target frequency. In simplified terms:
- Choose a set of cycle lengths to test (e.g., 5 to 200 bars)
- For each cycle length, calculate the Goertzel coefficient
- The squared magnitude of this coefficient gives us the power at that frequency
- Plot power against cycle length to get the power spectrum
- Peaks in the spectrum indicate dominant cycle lengths
The mathematics involve complex numbers and trigonometric identities, but the concept is straightforward: we are measuring how much of the signal oscillates at each frequency.
Why Not Just Use FFT?
FFT is powerful and fast, but it assumes the input signal is stationary (its statistical properties do not change over time). Market data violates this assumption continuously. Volatility changes, trends emerge and fade, and the dominant cycles themselves evolve.
In our testing, we found that Goertzel produced cleaner, more interpretable spectra for market data compared to FFT. The peaks were sharper, and false positives were fewer. This matters because each detected cycle undergoes further validation; starting with cleaner candidates improves the entire pipeline.
From Spectrum to Cycles
The power spectrum shows us where energy is concentrated across frequencies. But not every peak represents a genuine, tradeable cycle. The next step is validation.
Our process:
- Peak detection: Identify local maxima in the power spectrum
- Threshold filtering: Remove peaks below minimum power threshold
- Bartels testing: Validate each candidate cycle statistically
- Phase calculation: Determine current phase for validated cycles
This multi-stage process transforms raw price data into a set of statistically validated cycles with known lengths and current phases.
The Importance of Detrending
Before applying Goertzel analysis, we must remove the trend component from price data. Trends appear as very low frequency components that can mask the cycles we are looking for.
Common detrending methods include:
- First-difference: Subtracting each value from the previous (removes linear trend)
- Hodrick-Prescott filter: Separates trend from cycle component (smoothness parameter controls separation)
- Linear detrending: Fitting and subtracting a linear regression line
Each method has trade-offs. First-difference is simple but can distort cycle amplitudes. HP filter preserves amplitudes better but requires choosing an appropriate smoothness parameter. We use different methods depending on the analysis context.
Interpreting the Power Spectrum
A typical power spectrum for market data shows several peaks. Larger peaks indicate stronger cycles; their position on the x-axis indicates cycle length. But interpretation requires nuance:
- Harmonics: A strong cycle at 40 bars may show secondary peaks at 20 and 80 bars
- Noise floor: Some apparent peaks are just random noise; Bartels testing filters these
- Transient cycles: Some cycles appear strongly in recent data but lack historical persistence
The spectrum is a starting point for analysis, not the final answer. Human judgment, combined with statistical validation, determines which cycles merit attention.
Practical Application
In the FractalCycles platform, Goertzel analysis runs automatically on uploaded data. Users see the resulting power spectrum along with detected peaks and their Bartels significance scores. This visualization helps users understand the cyclical structure of their data without requiring signal processing expertise.
The goal is not to find the cycle that will predict the next move. The goal is to understand the structural frequencies present in the data, validated by statistical methods, to provide orientation within market behavior.
Framework: This analysis uses the Fractal Cycles Framework, which identifies market structure through spectral analysis rather than narrative explanation.
Written by Ken Nobak
Market analyst specializing in fractal cycle structure
Disclaimer
This content is for educational purposes only and does not constitute financial, investment, or trading advice. Past performance does not guarantee future results. The analysis presented describes observable market structure and should not be interpreted as predictions, recommendations, or signals. Always conduct your own research and consult with qualified professionals before making trading decisions.
See cycles in your own data
Apply the Fractal Cycles framework to any market using our analysis tools. Start with a free account.