A comprehensive DSP library with 23 window functions, advanced FIR/IIR filter design, biquad combination, and interactive visualization
npm install dsp-filter-librarybash
npm install dsp-filter-library
`
Usage
$3
`javascript
import { FilterDSP } from 'dsp-filter-library';
// Design a 6th order Butterworth lowpass filter
const spec = {
family: 'butter',
kind: 'lowpass',
N: 6,
Fs: 48000,
f1: 4000
};
const filter = FilterDSP.designIIR(spec);
// Get frequency response
const response = filter.frequencyGrid(1024);
console.log(response.magdB); // Magnitude in dB
console.log(response.phaseDeg); // Phase in degrees
console.log(response.freqHz); // Frequency points in Hz
// Get impulse response
const impResp = filter.impulseResponse(256);
// Get filter coefficients
console.log(filter.sections); // Second-order sections
`
$3
`javascript
// Design a 101-tap Hamming window lowpass filter
const spec = {
kind: 'lowpass',
taps: 101,
Fs: 48000,
f1: 4000,
window: 'hamming'
};
const filter = FilterDSP.designFIR(spec);
// Get filter taps
console.log(filter.taps);
// Get zeros
console.log(filter.zeros());
`
$3
`javascript
// Kaiser window with custom β parameter
const kaiserFilter = FilterDSP.designFIR({
kind: 'lowpass',
taps: 101,
Fs: 48000,
f1: 4000,
window: 'kaiser',
beta: 8.6 // Adjustable sidelobe level
});
// Tukey window with custom α parameter
const tukeyFilter = FilterDSP.designFIR({
kind: 'bandpass',
taps: 201,
Fs: 48000,
f1: 2000,
f2: 8000,
window: 'tukey',
alpha: 0.5 // Taper ratio (0=rectangular, 1=hann)
});
// Gaussian window with custom σ parameter
const gaussianFilter = FilterDSP.designFIR({
kind: 'highpass',
taps: 151,
Fs: 48000,
f1: 6000,
window: 'gauss',
sigma: 0.4 // Width parameter
});
// Flat-top window for accurate measurements
const flatTopFilter = FilterDSP.designFIR({
kind: 'lowpass',
taps: 301,
Fs: 48000,
f1: 4000,
window: 'flatTop' // Optimized for amplitude accuracy
});
`
$3
`javascript
// Elliptic bandpass filter with custom ripple
const spec = {
family: 'ellip',
kind: 'bandpass',
N: 8,
Rp: 1.0, // Passband ripple (dB)
Rs: 60, // Stopband ripple (dB)
Fs: 48000,
f1: 2000, // Lower cutoff
f2: 8000 // Upper cutoff
};
const filter = FilterDSP.designIIR(spec);
`
Interactive Demo
Open example/index.html in your browser to see the interactive filter design tool with real-time visualization.
$3
- Real-time parameter adjustment with sliders and dropdowns
- Tabbed interface for different analysis views (Frequency, Time Domain, Poles & Zeros, Coefficients)
- Properly centered poles and zeros visualization with unit circle
- Fixed y-axis ranges for consistent comparison (Group Delay: -50 to +50 samples)
- 23 window functions with dynamic parameter controls
- Complete coefficient display (all FIR taps, all IIR sections)
- Responsive design with modern dark theme
- Real-time filter redesign on parameter changes
API Reference
$3
Designs an IIR filter based on the specification object.
Parameters:
- spec.family: Filter family ('butter', 'cheby1', 'cheby2', 'ellip', 'linkwitz', 'bessel')
- spec.kind: Filter type ('lowpass', 'highpass', 'bandpass', 'bandstop')
- spec.N: Filter order
- spec.Rp: Passband ripple in dB (for Chebyshev I and Elliptic)
- spec.Rs: Stopband ripple in dB (for Chebyshev II and Elliptic)
- spec.Fs: Sampling frequency in Hz
- spec.f1: First cutoff frequency in Hz
- spec.f2: Second cutoff frequency in Hz (for bandpass/bandstop)
$3
Designs an FIR filter using windowed-sinc method.
Parameters:
- spec.kind: Filter type ('lowpass', 'highpass', 'bandpass', 'bandstop')
- spec.taps: Number of filter taps (must be odd)
- spec.Fs: Sampling frequency in Hz
- spec.f1: First cutoff frequency in Hz
- spec.f2: Second cutoff frequency in Hz (for bandpass/bandstop)
- spec.window: Window function (see supported windows below)
- spec.beta: Kaiser window β parameter (default: 8.6)
- spec.alpha: Tukey window α parameter (default: 0.5)
- spec.sigma: Gaussian window σ parameter (default: 0.4)
- spec.poissonAlpha: Poisson window α parameter (default: 2.0)
Supported Window Functions:
- 'rect', 'hann', 'hamming', 'blackman'
- 'blackmanHarris', 'blackmanNuttall', 'nuttall', 'exactBlackman'
- 'bartlett', 'bartlettHann', 'welch', 'triangular'
- 'gauss', 'tukey', 'poisson', 'parzen', 'bohman'
- 'lanczos', 'cosine', 'flatTop', 'dolphChebyshev', 'taylor', 'kaiser'
$3
#### frequencyGrid(nPoints)
Returns frequency response data.
- nPoints: Number of frequency points to compute
Returns:
- magdB: Magnitude response in dB
- phaseDeg: Phase response in degrees (unwrapped)
- freqHz: Frequency points in Hz
- gdSamples: Group delay in samples
- pdSamples: Phase delay in samples
#### impulseResponse(nSamples)
Returns impulse response data.
- nSamples: Number of samples to compute
#### sections (IIR only)
Array of second-order sections with coefficients a and b.
#### taps (FIR only)
Array of filter tap coefficients.
#### zeros()
Returns array of filter zeros as complex numbers.
#### zPoles (IIR only)
Array of filter poles as complex numbers.
#### zZeros (IIR only)
Array of filter zeros as complex numbers.
Building
`bash
npm install
npm run build
`
This will generate the library files in the lib/ directory:
- dsp-filter-library.js - UMD build
- dsp-filter-library.min.js - Minified UMD build
- dsp-filter-library.esm.min.js - ES module build
Advanced Window Functions
The library includes 23 different window functions for FIR filter design, each with specific characteristics:
$3
- Rectangular: Sharpest transition, highest sidelobes
- Hann: Good balance of main lobe width and sidelobe level
- Hamming: Optimized for reduced first sidelobe
- Blackman: Lower sidelobes, wider main lobe
$3
- Blackman-Harris: 4-term window with very low sidelobes
- Blackman-Nuttall: Alternative 4-term window
- Nuttall: Another 4-term variant
- Exact Blackman: 3-term with exact coefficients
$3
- Bartlett: Triangular window
- Bartlett-Hann: Hybrid triangular-cosine window
- Welch: Parabolic window
- Tukey: Raised cosine with adjustable taper (α parameter)
$3
- Gaussian: Adjustable width (σ parameter)
- Poisson: Exponential decay (α parameter)
- Parzen: Smooth polynomial window
- Bohman: Smooth window with good sidelobe suppression
- Lanczos: Sinc-based window
- Cosine: Simple cosine window
$3
- Flat-top: Optimized for accurate amplitude measurements
- Dolph-Chebyshev: Controlled sidelobe level
- Taylor: Antenna design window
- Kaiser: Adjustable sidelobe level (β parameter)
Examples
$3
`javascript
// Design a lowpass filter for audio
const filter = FilterDSP.designIIR({
family: 'butter',
kind: 'lowpass',
N: 4,
Fs: 44100,
f1: 8000
});
// Process audio samples
const audioSamples = [/ your audio data /];
const filteredSamples = filter.process(audioSamples);
`
$3
`javascript
// Analyze filter characteristics
const response = filter.frequencyGrid(2048);
// Find -3dB cutoff frequency
const cutoffIndex = response.magdB.findIndex(mag => mag <= -3);
const cutoffFreq = response.freqHz[cutoffIndex];
// Check stability (poles inside unit circle)
const isStable = filter.zPoles.every(pole =>
Math.sqrt(pole.re pole.re + pole.im pole.im) < 1
);
``