2.44 The Filter Coefficient Cookbook: One Equation for EMA, LPF, HPF, BPF
EMA, low-pass, high-pass, band-pass, band-stop are one second-order equation with different coefficients, built from the period via alpha. One engine and a recipe table, not a drawer of indicators.
The old article "The Trader's Guide to Low-Pass Filters" built smoothers, the old article "High-Pass Filters for Traders" built detrenders, and the old article "Band-Pass Filters: The Most Underused Tool in Technical Analysis" built cycle isolators. They look like different machines. They are not. Every one of them is the same second-order equation with different numbers plugged in. This article gives you that equation and the table of numbers, so you can stop installing a separate indicator for every job and instead run one filter engine and swap six coefficients. Once you see the cookbook, the named-indicator zoo collapses into one recipe card.
One engine: the second-order transfer function
Take the general filter from the recursive-versus-non-recursive split and keep terms up to two bars back. That second-order form is enough to build every standard trading filter.
$$ \text{output} = \frac{b_0 + b_1 z^{-1} + b_2 z^{-2}}{1 + a_1 z^{-1} + a_2 z^{-2}}\;\text{input} $$
Rearranged for code, the output is b0 times input, plus b1 times input one bar ago, plus b2 times input two bars ago, minus a1 times output one bar ago, minus a2 times output two bars ago. That is the whole engine: three input taps, two feedback taps, one line of arithmetic. A low-pass, a high-pass, a band-pass, a band-stop, and the plain EMA are all this same line with different b and a values. Build it once and you never write another filter from scratch; you look up coefficients.
The two constants every recipe is built from
The coefficients are not arbitrary. They all derive from the critical period you want, the cycle length at the boundary between pass and stop, through one smoothing constant alpha.
$$ \alpha = \frac{\cos\omega + \sin\omega - 1}{\cos\omega}, \qquad \omega = \frac{2\pi}{\text{period}} $$
You pick the period in bars, convert it to an angle omega, and out comes alpha, a number between zero and one that sets how aggressively the filter smooths. The low-pass and high-pass recipes need only alpha. The band-pass and band-stop need one more input, a bandwidth, which produces a second constant that controls how narrow the passed or rejected band is and a center term tied to the period. So the user-facing dials are honest and few: a period for everything, plus a bandwidth for the band filters. Everything else is bookkeeping the cookbook does for you.
The recipe card
Here is the table. Pick the filter you want, compute alpha from your period, and fill in the coefficients. The leading denominator coefficient a0 is always one.
| Filter | b0 | b1 | b2 | a1 | a2 |
|---|---|---|---|---|---|
| EMA (1-pole low-pass) | α | 0 | 0 | −(1−α) | 0 |
| 2-pole low-pass | α² | 0 | 0 | −2(1−α) | (1−α)² |
| High-pass (1-pole) | 1−α/2 | −(1−α/2) | 0 | −(1−α) | 0 |
| 2-pole high-pass | (1−α/2)² | −2(1−α/2)² | (1−α/2)² | −2(1−α) | (1−α)² |
| Band-pass | (1−σ)/2 | 0 | −(1−σ)/2 | −λ(1+σ) | σ |
| Band-stop | (1+σ)/2 | −λ(1+σ) | (1+σ)/2 | −λ(1+σ) | σ |
Read the structure and the families from the earlier article jump out. The low-pass recipes have all their weight in the numerator's b0 with feedback in the denominator, so they pass the slow trend. The high-pass recipes put a minus sign between b0 and b1, a difference that cancels the DC level and keeps the fast deviation, which is why a one-pole high-pass is close to taking the difference of consecutive bars. The band-pass and band-stop use the extra constants lambda, the cosine of the center period angle, and sigma, set by the bandwidth, to carve out or notch a middle band. Doubling a pole, going from one-pole to two-pole, squares the relevant terms and steepens the rolloff at the cost of more lag, exactly the trade the low-pass article priced.
What the cookbook is for, and what it is not
The practical win is real. You implement one second-order section, expose a period dial and a filter-type selector, and you have replaced a drawer full of separate indicators with one tested routine. Need a steeper cut? Cascade two sections and the orders add. Need a roofing filter? Run a high-pass into a low-pass. The composition is the polynomial multiplication from the transfer-function article, done with coefficient blocks instead of named products. This is the engineering posture the old article "Why Traders Should Analyze Indicators Mathematically" was pushing toward: you stop collecting indicators and start configuring one.
The cookbook does not, however, tell you which filter to want, and that is the part that decides whether you make money. Choosing the period sets which cycles you keep, choosing the type sets the job, and both are bets about your instrument that the table cannot make for you. A perfectly implemented two-pole low-pass tuned to the wrong period is a clean answer to the wrong question. And every recipe here is linear, so it carries the lag its structure implies; the cookbook makes lag easy to compute, not easy to avoid. Use it to build filters fast and correctly, then spend your real effort on the only hard questions it leaves open: which band carries edge on your data, and whether the lag fits your holding period.

KEY POINTS
- Every standard trading filter is the same second-order transfer function with different coefficients: three input taps (b0, b1, b2) and two feedback taps (a1, a2), one line of arithmetic.
- All the coefficients derive from the critical period through one smoothing constant alpha equals (cos w plus sin w minus 1) over cos w, with w equal to two pi over period. Band filters need one extra bandwidth constant.
- The recipe table gives EMA, 1- and 2-pole low-pass, 1- and 2-pole high-pass, band-pass, and band-stop. Low-pass weight sits in b0; high-pass uses a minus between b0 and b1 to cancel DC; band filters use lambda (center) and sigma (bandwidth).
- Doubling a pole (1-pole to 2-pole) squares the relevant terms and steepens the rolloff at the cost of more lag, the trade from the old article "The Trader's Guide to Low-Pass Filters."
- The payoff: implement one second-order section, expose a period dial and a type selector, and replace a drawer of separate indicators. Cascade sections for steeper cuts; compose by multiplying transfer functions.
- The cookbook cannot tell you which filter to want. Period and type are bets about your instrument; a perfect filter on the wrong period answers the wrong question, and every recipe carries the lag its structure implies.
References
- Statistically Sound Indicators for Financial Market Prediction - Timothy Masters (Amazon)
- Cycle Analytics for Traders - John Ehlers (Amazon)
- Digital biquad filter: the second-order section (Wikipedia)
- Introduction to Digital Filters: transfer functions and coefficients (Stanford CCRMA)
- The Scientist and Engineer's Guide to Digital Signal Processing: Recursive Filters
- Ehlers 2-pole filter coefficients from period (QuantWave)