Butterworth Filter
Maximally flat frequency response filter. No ripple in passband. Smooth rolloff. Used in audio and signal processing.
Visualization
Interactive visualization for Butterworth Filter
Butterworth Filter:
- • Maximally flat passband
Interactive visualization with step-by-step execution
Implementation
1class ButterworthFilter {
2 private a: number[];
3 private b: number[];
4
5 constructor(order: number, cutoff: number, sampleRate: number, type: 'lowpass' | 'highpass') {
6 const wc = 2 * Math.PI * cutoff / sampleRate;
7 const { a, b } = this.designFilter(order, wc, type);
8 this.a = a;
9 this.b = b;
10 }
11
12 filter(signal: number[]): number[] {
13 const output: number[] = new Array(signal.length);
14 const x: number[] = new Array(this.b.length).fill(0); // Input history
15 const y: number[] = new Array(this.a.length).fill(0); // Output history
16
17 for (let i = 0; i < signal.length; i++) {
18 // Shift input history
19 x.unshift(signal[i]);
20 x.pop();
21
22 // Apply difference equation
23 let sum = 0;
24 for (let j = 0; j < this.b.length; j++) {
25 sum += this.b[j] * x[j];
26 }
27 for (let j = 1; j < this.a.length; j++) {
28 sum -= this.a[j] * y[j - 1];
29 }
30
31 output[i] = sum;
32
33 // Shift output history
34 y.unshift(sum);
35 y.pop();
36 }
37
38 return output;
39 }
40
41 private designFilter(order: number, wc: number, type: string): { a: number[], b: number[] } {
42 // Simplified coefficient calculation
43 // Real implementation uses scipy.signal or similar
44 return { a: [1], b: [1] };
45 }
46}Deep Dive
Theoretical Foundation
Transfer function: H(s) = 1/√(1+(ω/ωc)^(2n)). n = order (steeper rolloff). ωc = cutoff frequency. Flat passband, monotonic. Poles on Butterworth circle. Can be lowpass, highpass, bandpass, bandstop.
Complexity
Time
O(n)
O(n)
O(n)
Space
O(order)
Applications
Industry Use
Audio equalizers and crossover networks
Anti-aliasing filters in ADCs
Biomedical signal processing (ECG, EEG)
Communications system filtering
Control system noise reduction
Instrumentation and measurement systems
Use Cases
Related Algorithms
A* Search Algorithm
Informed search algorithm combining best-first search with Dijkstra's algorithm using heuristics. Widely used in pathfinding and graph traversal, A* is optimal and complete when using admissible heuristic. Used in games, GPS navigation, and robotics. Invented by Peter Hart, Nils Nilsson, and Bertram Raphael in 1968.
Convex Hull (Graham Scan)
Find smallest convex polygon containing all points. Graham Scan invented by Ronald Graham in 1972, runs in O(n log n). Essential in computational geometry, computer graphics, and pattern recognition.
Line Segment Intersection
Determine if two line segments intersect. Fundamental geometric primitive used in graphics, CAD, GIS. Uses orientation and collinearity tests.
Caesar Cipher
The Caesar Cipher is one of the oldest and simplest encryption techniques, named after Julius Caesar who used it to protect military messages around 100 BC. It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet. For example, with a shift of 3, A becomes D, B becomes E, and so on. Despite being used for over 2000 years, it's extremely weak by modern standards with only 25 possible keys, making it trivially breakable by brute force or frequency analysis.