<!--order=18-->


<h1>Filters</h1>
<p>A filter passes some frequencies and attenuates others. The concept is simple; the details of how steeply they roll off, how flat the passband is, and whether there's ripple or ringing determine which type to use and how to design it. Filters show up in almost every analog signal path — speaker crossovers, radio receivers, anti-aliasing before ADCs, audio equalizers, switching supply output smoothing.</p>

<h2>Filter Types by Frequency Response</h2>

<table>
  <thead><tr><th>Type</th><th>Passes</th><th>Attenuates</th><th>Common uses</th></tr></thead>
  <tbody>
    <tr><td>Low-pass</td><td>Frequencies below f_c</td><td>Frequencies above f_c</td><td>Anti-aliasing, PWM smoothing, noise reduction, crossover to woofer</td></tr>
    <tr><td>High-pass</td><td>Frequencies above f_c</td><td>Frequencies below f_c (DC blocked)</td><td>AC coupling, rumble removal, crossover to tweeter, microphone input</td></tr>
    <tr><td>Band-pass</td><td>Band around centre frequency f₀</td><td>Below and above the band</td><td>Radio IF stages, audio tone controls, instrument pickups, PLL reference</td></tr>
    <tr><td>Band-stop (notch)</td><td>Everything except the notch</td><td>Specific frequency range</td><td>60/50Hz hum removal, power line interference, DSP anti-resonance</td></tr>
    <tr><td>All-pass</td><td>All frequencies (unchanged amplitude)</td><td>Nothing — but phase is shifted</td><td>Phase compensation, signal delay, phaser audio effects</td></tr>
  </tbody>
</table>

<h2>Filter Order and Rolloff</h2>
<p>Filter order determines how steeply the response rolls off past the cutoff frequency:</p>

<table>
  <thead><tr><th>Order</th><th>Rolloff (dB/decade)</th><th>Rolloff (dB/octave)</th><th>Complexity</th></tr></thead>
  <tbody>
    <tr><td>1st</td><td>−20 dB/decade</td><td>−6 dB/octave</td><td>Single RC stage</td></tr>
    <tr><td>2nd</td><td>−40 dB/decade</td><td>−12 dB/octave</td><td>Two RC stages or one op-amp Sallen-Key</td></tr>
    <tr><td>3rd</td><td>−60 dB/decade</td><td>−18 dB/octave</td><td>Three stages or one Sallen-Key + one RC</td></tr>
    <tr><td>4th</td><td>−80 dB/decade</td><td>−24 dB/octave</td><td>Two cascaded 2nd-order sections</td></tr>
    <tr><td>nth</td><td>−20n dB/decade</td><td>−6n dB/octave</td><td>—</td></tr>
  </tbody>
</table>

<p>The −3dB point is where output drops to 70.7% of input (by convention, this is the cutoff frequency). A decade means ×10 in frequency; an octave means ×2.</p>

<h2>Passive Filters (RC and LC)</h2>

<h3>First-Order RC</h3>
<pre>
Low-pass:   f_c = 1 / (2πRC)   — R series, C to GND
High-pass:  f_c = 1 / (2πRC)   — C series, R to GND
</pre>
<p>Simple, cheap, no power needed. Problems: −20dB/decade rolloff is gentle; loading by downstream stages shifts the cutoff; no gain. Fine for rough filtering, EMI suppression, and audio coupling. Not appropriate where you need a sharp boundary between pass and stop bands.</p>

<h3>LC Filters</h3>
<pre>
Resonant frequency: f₀ = 1 / (2π√LC)

Advantages over RC:
  - No DC resistance in the path (lossless in ideal case)
  - 2nd order from a single L and C
  - Higher Q possible → sharper resonance

LC low-pass (series L, shunt C):   L in series with signal, C to GND
LC band-pass (series resonant):    L and C in series, resonates at f₀
</pre>
<p>LC filters shine at RF and power line frequencies. For audio, the inductor's size, cost, and non-ideal behaviour (DCR, nonlinear core) make active RC filters preferable.</p>

<h2>Active Filters</h2>
<p>An op-amp with RC feedback achieves any filter characteristic without inductors, with no loading issues, and with optional gain in the passband:</p>

<h3>Sallen-Key — 2nd Order Low-Pass</h3>
<pre>
        R1        R2
Vin ──[   ]──┬──[   ]──(+) op-amp (−)──┬── Vout
             |                  |       |
            [C2]               [C1]     └── (unity gain: − connects to output)
             |                  |
            GND                GND

f_c = 1 / (2π × √(R1 × R2 × C1 × C2))

For equal R and C: R1=R2=R, C1=C2=C → f_c = 1/(2πRC)
</pre>

<h3>Multiple Feedback (MFB) — Inverting 2nd Order</h3>
<p>Commonly used for higher Q values — the MFB topology is more flexible for Q adjustment than Sallen-Key. One op-amp, three resistors, two capacitors. Inverts the signal.</p>

<h2>Filter Characteristics (Approximations)</h2>

<table>
  <thead><tr><th>Type</th><th>Passband</th><th>Stopband rolloff</th><th>Phase response</th><th>Best for</th></tr></thead>
  <tbody>
    <tr><td>Butterworth</td><td>Maximally flat (no ripple)</td><td>Moderate (−20n dB/decade)</td><td>Moderate non-linear</td><td>General purpose, when passband flatness matters</td></tr>
    <tr><td>Chebyshev Type I</td><td>Equiripple (ripple in passband)</td><td>Steeper than Butterworth at same order</td><td>More non-linear</td><td>When sharp cutoff is more important than flat passband</td></tr>
    <tr><td>Chebyshev Type II</td><td>Flat (no passband ripple)</td><td>Equiripple in stopband</td><td>Moderate</td><td>When flat passband AND good stopband attenuation needed</td></tr>
    <tr><td>Elliptic (Cauer)</td><td>Equiripple</td><td>Steepest possible for given order; equiripple</td><td>Highly non-linear</td><td>Minimum order for required attenuation; tight space constraints</td></tr>
    <tr><td>Bessel</td><td>Flat but wider transition</td><td>Gentlest rolloff</td><td>Maximally linear (linear phase)</td><td>Pulse/waveform fidelity — no ringing or shape distortion</td></tr>
  </tbody>
</table>

<h2>Anti-Aliasing Filter</h2>
<p>When sampling an analog signal with an ADC, any frequency above half the sample rate (the Nyquist frequency) gets folded back into the audio spectrum as aliasing — phantom frequencies that don't exist in the original signal. The anti-aliasing filter prevents this:</p>
<pre>
ADC sample rate: 44.1 kHz (CD quality)
Nyquist frequency: 22.05 kHz

The anti-aliasing low-pass filter must:
  - Pass everything up to 20 kHz (human hearing limit) with minimal loss
  - Sharply attenuate everything above 22.05 kHz

A 5th-order Butterworth or 3rd-order Chebyshev typically achieves this.
</pre>

<h2>Digital Filters</h2>
<p>Once a signal is sampled, filtering happens in software. Two families:</p>

<table>
  <thead><tr><th>Type</th><th>Full name</th><th>Characteristics</th><th>When to use</th></tr></thead>
  <tbody>
    <tr><td>FIR</td><td>Finite Impulse Response</td><td>Always stable, linear phase possible, computationally expensive (many multiplications)</td><td>When linear phase (waveform shape) matters; audio; linear-phase EQ</td></tr>
    <tr><td>IIR</td><td>Infinite Impulse Response</td><td>Computationally cheap, can be unstable if coefficients wrong, non-linear phase</td><td>Real-time processing, microcontrollers, where CPU budget is tight</td></tr>
  </tbody>
</table>

<pre>
Simple IIR low-pass (exponential moving average) in code:
  alpha = 0.1   // 0 = no filtering, 1 = instant response
  filtered = alpha × new_sample + (1 - alpha) × filtered

Equivalent time constant: τ ≈ (1/alpha) × sample_period
</pre>

<h2>Filter Design Workflow</h2>
<ol>
  <li>Define requirements: passband (f_pass, max attenuation), stopband (f_stop, min attenuation)</li>
  <li>Choose approximation (Butterworth/Bessel for flat passband, Chebyshev/Elliptic for steep rolloff)</li>
  <li>Calculate required order: n = log((10^(A_s/10) − 1)/(10^(A_p/10) − 1)) / (2 × log(f_s/f_p))</li>
  <li>Look up or calculate component values (filter design tables, FilterPro, Analog Devices Filter Wizard)</li>
  <li>Simulate in SPICE or LTspice before building</li>
  <li>Build, measure on a spectrum analyser, iterate</li>
</ol>

<h2>References</h2>
<ul>
  <li>Williams &amp; Taylor — <em>Electronic Filter Design Handbook</em>, 4th ed.</li>
  <li>Horowitz &amp; Hill — <em>The Art of Electronics</em>, 3rd ed. Chapter 6</li>
  <li><a href="https://www.analog.com/en/design-center/design-tools-and-calculators/filter-design-tool.html" target="_blank" rel="noopener">Analog Devices Filter Wizard ↗</a></li>
  <li><a href="https://tools.analog.com/en/filterwizard/" target="_blank" rel="noopener">Analog Devices Filter Wizard (direct) ↗</a></li>
  <li><a href="https://www.ti.com/tool/FILTERPRO" target="_blank" rel="noopener">Texas Instruments FilterPro ↗</a></li>
</ul>
