Skip to content

Commit 5f74d49

Browse files
committed
Update readme.md
1 parent fa4977c commit 5f74d49

1 file changed

Lines changed: 14 additions & 38 deletions

File tree

readme.md

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,34 @@ npm install digital-filter
1616
```
1717

1818
```js
19-
import { onePole } from 'digital-filter'
19+
import { butterworth, filter, onePole } from 'digital-filter'
20+
// import butterworth from 'digital-filter/iir/butterworth.js'
2021

21-
// Smooth a signal with a 100 Hz lowpass
22-
onePole(data, { fc: 100, fs: 44100 })
23-
24-
// Process blocks with persistent state:
25-
let params = { fc: 100, fs: 44100 }
26-
onePole(block1, params) // state preserved
27-
onePole(block2, params) // seamless continuation
28-
```
22+
onePole(data, { fc: 100, fs: 44100 }) // smooth in-place
2923

30-
```js
31-
// Individual imports:
32-
import nlms from 'digital-filter/adaptive/nlms.js'
24+
let sos = butterworth(4, 1000, 44100) // design a 4th-order lowpass
25+
filter(data, { coefs: sos }) // apply in-place
3326

34-
// Cancel echo: feed far-end and microphone arrays, get clean signal
35-
let params = { order: 512, mu: 0.5 }
36-
nlms(farEnd, microphone, params)
37-
let clean = params.error
27+
let params = { coefs: sos }
28+
filter(block1, params) // state persists between blocks
29+
filter(block2, params)
3830
```
3931

40-
> [!NOTE]
4132
> For audio-domain filters (weighting, EQ, synth, measurement) see [audio-filter](https://github.com/audiojs/audio-filter).
4233
43-
4434
## Intro
4535

46-
**What is a filter?** Takes an array of samples, outputs an array of samples. `output[i] = (input[i] + input[i-1] + input[i-2]) / 3` is a filter – it smooths out fast changes. That's a lowpass.
36+
**What is a filter?** Takes an array of samples, outputs an array of samples. `output[i] = (input[i] + input[i-1] + input[i-2]) / 3` smooths out fast changes – that's a lowpass.
4737

48-
**What is frequency response?** Every filter passes some frequencies and cuts others. The plots show how much each frequency is kept (magnitude, in dB) and how much it's delayed (phase, in degrees). 0dB = unchanged, –3dB = half power.
38+
**What is frequency response?** Every filter passes some frequencies and cuts others. The plots show how much each frequency is kept (magnitude, in dB) and how much it's delayed (phase). 0 dB = unchanged, –3 dB = half power.
4939

50-
**What is IIR vs FIR?** IIR uses feedback (output depends on previous output). Few multiplies, low latency, but can't do linear phase and can blow up. FIR has no feedback – always stable, linear phase possible, but needs many taps (100–1000+) for a sharp cutoff, which can tax on performance.
40+
**What is IIR vs FIR?** IIR uses feedback – few multiplies, low latency, but can't do linear phase and can blow up. FIR has no feedback – always stable, linear phase possible, but needs 100–1000+ taps for a sharp cutoff.
5141

52-
**What is SOS?** Second-Order Sections – an IIR filter split into a chain of biquads (2nd-order, 5 coefficients each). A 4th-order Butterworth = 2 biquads. All design functions in this library return SOS arrays. This avoids the precision loss that happens with high-order polynomials in float64.
53-
54-
**How to read the plots?** Four panels per filter. Top-left: magnitude (dB vs Hz). Top-right: phase (degrees vs Hz). Bottom-left: group delay (samples vs Hz) – flat means no distortion. Bottom-right: impulse response. Dashed line = cutoff $f_c$.
55-
56-
**How to design and apply a filter?** Design functions return coefficients (SOS array or Float64Array). Pass them to `filter()` to process data in-place. State persists in `params` between calls for block processing.
57-
58-
```js
59-
let sos = butterworth(4, 1000, 44100) // design: 4th-order lowpass at 1 kHz
60-
filter(data, { coefs: sos }) // apply: modifies data in-place
61-
62-
// seamless processing
63-
let params = { coefs: butterworth(4, 1000, 44100) }
64-
filter(block1, params) // state preserved
65-
filter(block2, params) // seamless continuation
66-
```
42+
**What is SOS?** Second-Order Sections – an IIR filter split into a chain of biquads (2nd-order, 5 coefficients each). A 4th-order Butterworth = 2 biquads. All design functions return SOS arrays to avoid float64 precision loss.
6743

68-
**How to read the plots?** Four panels per filter. Top-left: magnitude (dB vs Hz). Top-right: phase (degrees vs Hz). Bottom-left: group delay (samples vs Hz)flat means no distortion. Bottom-right: impulse response. Dashed line = cutoff $f_c$.
44+
**How to read the plots?** Four panels. Top-left: magnitude (dB vs Hz). Top-right: phase (degrees vs Hz). Bottom-left: group delay (samples vs Hz), flat = no distortion. Bottom-right: impulse response. Dashed line = $f_c$.
6945

70-
**How to read the formulas?** $|H(j\omega)|^2$: how the analog prototype shapes magnitude. $H(z)$: what the code computes per sample. $h[n]$: the impulse response / FIR coefficients.
46+
**How to read the formulas?** $|H(j\omega)|^2$: analog prototype magnitude. $H(z)$: digital transfer function. $h[n]$: impulse response / FIR coefficients.
7147

7248

7349
## IIR

0 commit comments

Comments
 (0)