5.8 KiB
HOMOD: Ehlers Homodyne Discriminator
The homodyne discriminator locks onto a cycle's frequency by comparing successive analytic signal rotations.
| Property | Value |
|---|---|
| Category | Cycle |
| Inputs | Source (close) |
| Parameters | minPeriod (default 6.0), maxPeriod (default 50.0) |
| Outputs | Single series (Homod) |
| Output range | Varies (see docs) |
| Warmup | maxPeriod * 2 bars (default 100) |
| PineScript | homod.pine |
- HOMOD estimates the dominant cycle period of a market using homodyne mixing, a technique from radio engineering where a signal is multiplied by a d...
- Similar: HT_Phasor, HT_Sine | Complementary: Cycle period for context | Trading note: Homodyne discriminator; Ehlers' phase detection for cycle turning points.
- Validated against TA-Lib, Skender, and Tulip reference implementations where available.
HOMOD estimates the dominant cycle period of a market using homodyne mixing, a technique from radio engineering where a signal is multiplied by a delayed copy of itself to expose the angular phase change between samples. The output is a continuously varying period measurement (in bars) that tracks the market's instantaneous cycle length, enabling adaptive indicator tuning. Developed by John Ehlers, it offers better noise rejection and stability than the raw Hilbert Transform period estimator.
Historical Context
John Ehlers introduced the Homodyne Discriminator in Rocket Science for Traders (2001) and refined it in Cybernetic Analysis for Stocks and Futures (2004). In RF engineering, homodyne detection multiplies a signal with a local oscillator at the same frequency to extract phase information. Ehlers adapted this by multiplying the complex analytic signal z_t = I_t + jQ_t by its own conjugate delayed by one bar, yielding the phase rotation per sample. The angular velocity directly encodes the instantaneous frequency (and hence period). Compared to the raw Hilbert Transform discriminator which estimates phase absolutely, homodyne detection measures phase differences, making it less sensitive to amplitude variations and more stable during noisy market conditions.
Architecture & Physics
1. Pre-Processing (4-Bar WMA)
Smooth_t = \frac{4P_t + 3P_{t-1} + 2P_{t-2} + P_{t-3}}{10}
2. Analytic Signal Generation
The Hilbert Transform FIR generates quadrature components using Ehlers' 4-tap approximation with coefficients A = 0.0962 and B = 0.5769:
Detrender_t = A \cdot Smooth_t + B \cdot Smooth_{t-2} - B \cdot Smooth_{t-4} - A \cdot Smooth_{t-6}
In-Phase (I_1) is the detrender delayed by 3 bars. Quadrature (Q_1) is the Hilbert transform of the detrender. Both are further refined:
I_2 = I_1 - jQ, \qquad Q_2 = Q_1 + jI
Smoothed with EMA (\alpha = 0.2).
3. Homodyne Mixing
Multiplying the complex signal by its one-bar-delayed conjugate:
Re_t = I_{2,t} \cdot I_{2,t-1} + Q_{2,t} \cdot Q_{2,t-1}
Im_t = I_{2,t} \cdot Q_{2,t-1} - Q_{2,t} \cdot I_{2,t-1}
Both smoothed with EMA (\alpha = 0.2).
4. Period Extraction
\theta = \operatorname{atan2}(Im_t, Re_t)
Period_{raw} = \frac{2\pi}{\theta}
Clamped to [MinPeriod, MaxPeriod] and smoothed with EMA (\alpha = 0.33).
5. Complexity
O(1) per bar with O(1) memory. The pipeline consists entirely of fixed-depth IIR filters and short delay lines.
Mathematical Foundation
Parameters
| Parameter | Description | Default | Constraint |
|---|---|---|---|
minPeriod |
Minimum detectable period | 6.0 | > 0 |
maxPeriod |
Maximum detectable period | 50.0 | > minPeriod |
Output Interpretation
| Output | Meaning |
|---|---|
period |
Dominant cycle length in bars |
| Stable period | Market exhibiting regular cyclical behavior |
| Period drifting to maxPeriod | Trending market; cycle measurement unreliable |
| Rapidly fluctuating period | Noisy or transitioning market regime |
Performance Profile
Operation Count (Streaming Mode)
| Operation | Count per bar | Notes |
|---|---|---|
| 4-bar WMA | ~5 | 3 MUL + 1 ADD + 1 DIV (precomputed as ×0.1) |
| Hilbert FIR (detrender) | ~7 | 4-tap FIR: 4 MUL + 3 ADD |
| Hilbert FIR (Q1) | ~7 | Same 4-tap structure on det buffer |
| Hilbert FIR (jI, jQ) | ~14 | Two additional 4-tap Hilbert passes |
| Phasor EMA (I2, Q2) | ~8 | 2 SUB/ADD + 4 FMA |
| Homodyne mixing | ~8 | 4 MUL + 2 ADD/SUB per Re/Im |
| Homodyne EMA smoothing | ~4 | 2 FMA for Re, Im |
| ATAN2 | ~20 | Math.Atan2 transcendental (~15-20 cycles) |
| Period clamp + EMA | ~4 | 2 comparisons + 1 FMA |
| Buffer management | ~8 | 4 circular buffer writes + index updates |
| Total | ~85 | O(1) fixed; dominated by ATAN2 |
Batch Mode (SIMD Analysis)
| Aspect | Assessment |
|---|---|
| SIMD vectorizable | No: cascaded IIR filters and Hilbert FIR with sequential state dependencies |
| Bottleneck | Math.Atan2 transcendental (~20 cycles); Hilbert FIR circular buffer lookups |
| Parallelism | None: each bar depends on previous bar's I2, Q2, Re, Im state |
| Memory | O(1): ~7-element circular buffers × 4 + 6 scalar EMA states (~300 bytes) |
| Throughput | Moderate; ~3× slower than simple EMA due to multi-stage Hilbert pipeline |
Resources
- Ehlers, J.F. Rocket Science for Traders. Wiley, 2001.
- Ehlers, J.F. Cybernetic Analysis for Stocks and Futures. Wiley, 2004.
- Haykin, S. Communication Systems. 4th ed., Wiley, 2001. (Homodyne detection theory)