Classic FIR Filter Bank — User Guide
Finite Impulse Response filter implementations with guaranteed linear phase: windowed-sinc designs, moving average, raised-cosine, and Hilbert transform for perfect 90° phase shift.
What this does
This script implements a comprehensive Finite Impulse Response (FIR) filter bank with guaranteed linear phase characteristics. Unlike IIR filters which can introduce phase distortion, all FIR filters in this collection maintain perfect phase linearity, making them ideal for applications where phase preservation is critical. The implementation includes 9 distinct filter types: 6 windowed-sinc designs (Rectangular, Hamming, Hann, Blackman, Kaiser, Bartlett), moving average filters, raised-cosine filters for communication systems, and Hilbert transforms for analytic signal creation. Each filter is implemented with symmetric coefficients to ensure linear phase, and utilizes fast convolution for efficient processing.
Key Features:
- 9 FIR Filter Types — From simple moving average to sophisticated Hilbert transform
- Guaranteed Linear Phase — Symmetric coefficients eliminate phase distortion
- 6 Window Functions — Tradeoffs between main lobe width and sideband suppression
- Fast Convolution — Uses Praat's optimized Convolve for speed
- Complete Visualization — Frequency response, phase, and impulse response plots
- Odd-Length Enforcement — Automatic adjustment for perfect symmetry
Technical Implementation: (1) Coefficient calculation: Each filter type computes symmetric coefficients h[n] for n=0..N-1. (2) Window application: Windowed-sinc filters multiply ideal sinc by window function. (3) Symmetry enforcement: Odd filter length ensures center coefficient exists. (4) Fast convolution: Uses Praat's Convolve function (C-optimized) rather than manual filtering. (5) Highpass transformation: Spectral inversion: h_HP[n] = -h_LP[n] + δ[n-M]. (6) Response calculation: Direct DFT of coefficients for frequency/phase plots. (7) Normalization: DC gain normalized to unity for lowpass filters. The implementation prioritizes both mathematical correctness and computational efficiency.
Quick start
- In Praat, select exactly one Sound object (mono or stereo).
- Run script… →
classic_fir_filter_bank.praat. - Choose Filter_type: Start with "Windowed-sinc (Hamming)" for good balance.
- Select Filter_mode: Lowpass or Highpass (except Hilbert transform).
- Set Filter_length_(N): 101 samples typical (automatically made odd).
- Set Cutoff_frequency_(Hz): Must be below Nyquist (fs/2).
- For Kaiser window, adjust Kaiser_beta (0-10, higher = narrower main lobe).
- For Raised-cosine, set Rolloff_factor (0-1, 0.5 typical).
- Enable Plot_responses to see frequency/phase characteristics.
- Enable Plot_impulse_response to verify symmetry.
- Enable Apply_filter to process audio.
- Enable Play_result to hear output.
- Click OK — filter designed and applied with visual verification.
FIR Filter Theory & Design
Finite Impulse Response Fundamentals
🔢 Discrete Convolution Implementation
Difference equation: y[n] = Σ_{k=0}^{N-1} h[k]·x[n-k]
Impulse response: h[n] finite length N samples
Linear phase condition: h[n] = h[N-1-n] (symmetry)
Frequency response: H(ω) = Σ_{n=0}^{N-1} h[n]·e^{-jωn}
Constant group delay: τ_g = (N-1)/2 samples
FIR Filter Mathematics
Windowed-Sinc Design Method
Ideal Lowpass Filter Approximation
The window method for FIR design:
Window Function Characteristics
Rectangular Window (No Window)
📏 Simple Truncation (Poor Performance)
Formula: w[n] = 1 for all n
Main lobe width: Narrowest (4π/N)
Side lobe level: -13dB (worst)
Transition width: Sharpest but with Gibbs oscillation
Use: Theoretical reference, not recommended for practical filtering
Hamming Window
📊 Excellent General Purpose
Formula: w[n] = 0.54 - 0.46·cos(2πn/(N-1))
Main lobe width: 8π/N
Side lobe level: -43dB
Transition width: Good balance
Use: Default choice for most filtering applications
Hann (Hanning) Window
📈 Good Spectral Leakage Reduction
Formula: w[n] = 0.5 - 0.5·cos(2πn/(N-1))
Main lobe width: 8π/N
Side lobe level: -31dB
Transition width: Similar to Hamming
Use: Spectral analysis, compromise between main lobe and sidelobes
Blackman Window
📉 Excellent Sideband Suppression
Formula: w[n] = 0.42 - 0.5·cos(2πn/(N-1)) + 0.08·cos(4πn/(N-1))
Main lobe width: 12π/N (widest)
Side lobe level: -58dB (best suppression)
Transition width: Widest
Use: When stopband attenuation is critical
Kaiser Window
🎚️ Adjustable Parameter (Beta)
Formula: w[n] = I₀(β√(1-[(n-M)/M]²)) / I₀(β)
Main lobe width: Adjustable via β parameter
Side lobe level: Adjustable via β parameter
Parameter β: 0 (rectangular) to 10+ (narrow main lobe)
Use: When precise control over sidelobes vs. main lobe is needed
Bartlett (Triangular) Window
🔺 Simple Triangular Shape
Formula: w[n] = 1 - |2n/(N-1) - 1|
Main lobe width: 8π/N
Side lobe level: -25dB
Transition width: Moderate
Use: Simple smoothing, computational efficiency
Window Comparison Table
| Window | Main Lobe Width | Side Lobe Level | Transition Width | Stopband Attenuation | Typical Use |
|---|---|---|---|---|---|
| Rectangular | 4π/N | -13dB | 0.9/N | 21dB | Reference only |
| Bartlett | 8π/N | -25dB | 2.4/N | 25dB | Simple smoothing |
| Hann | 8π/N | -31dB | 3.1/N | 44dB | General purpose |
| Hamming | 8π/N | -41dB | 3.3/N | 53dB | Default choice |
| Blackman | 12π/N | -57dB | 5.5/N | 74dB | High stopband rejection |
| Kaiser (β=5) | 10π/N | -45dB | 4.6/N | 55dB | Adjustable performance |
| Kaiser (β=8) | 12π/N | -57dB | 5.7/N | 75dB | High rejection needed |
Filter Type Implementations
Windowed-Sinc Filters (Types 1-6)
🎛️ Most Common FIR Design Method
Design principle: Ideal sinc impulse response × window function
Formula: h[n] = 2f_c·sinc(2f_c(n-M)) × w[n]
Characteristics: Linear phase, controllable transition width
Window tradeoffs: Different windows provide different sidelobe/transition balances
Implementation: 6 window types with identical sinc core
Windowed-Sinc Implementation Details
Moving Average Filter (Type 7)
📊 Simplest FIR Filter
Formula: h[n] = 1/N for all n
Frequency response: H(ω) = sin(ωN/2)/(N·sin(ω/2))·e^{-jω(N-1)/2}
Characteristics: Very simple, poor frequency selectivity
Use: Simple smoothing, DC averaging, computational simplicity
Implementation: All coefficients equal, automatically symmetric
Raised-Cosine Filter (Type 8)
📡 Communication Systems Standard
Formula: h(t) = sinc(t/T)·cos(παt/T)/[1-(2αt/T)²]
Rolloff factor α: 0 (rectangular) to 1 (slow rolloff)
Characteristics: Zero intersymbol interference, controlled bandwidth
Use: Digital communications, pulse shaping, matched filtering
Implementation: Sampled raised-cosine function with rolloff parameter
Raised-Cosine Implementation
Hilbert Transform (Type 9)
🔄 90° Phase Shift for Analytic Signals
Formula: h[n] = 2/(π·n) for odd n, 0 for even n
Frequency response: H(ω) = -j·sign(ω) for |ω|≤π
Characteristics: Exactly 90° phase shift for all frequencies
Use: Analytic signal creation, single-sideband modulation, envelope detection
Implementation: Windowed ideal Hilbert transform coefficients
Hilbert Transform Implementation
Linear Phase Advantages & Characteristics
Why Linear Phase Matters
⏱️ Constant Group Delay Benefits
Phase response: ∠H(ω) = -ω·τ + constant
Group delay: τ_g = -d∠H/dω = constant
Waveform preservation: All frequencies delayed equally
No phase distortion: Critical for transient signals
Symmetry requirement: h[n] = h[N-1-n]
Linear Phase Mathematics
Constant Group Delay Implications
Applications Requiring Linear Phase
Highpass Transformation with Linear Phase
Spectral Inversion Method
Converting lowpass to highpass while maintaining linear phase:
Parameters & Specifications
Filter Selection
| Parameter | Type | Default | Description |
|---|---|---|---|
| Filter_type | option | Windowed-sinc (Hamming) | 9 FIR filter types with linear phase |
| Filter_mode | option | Lowpass | Lowpass or Highpass (Hilbert is neither) |
Core Filter Parameters
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
| Filter_length_(N) | integer | 101 | 3-4097 | Number of filter taps (automatically made odd) |
| Cutoff_frequency_(Hz) | positive | 1000 | 20 - 0.45×f_s | -6dB cutoff frequency (except Hilbert) |
Specialized Parameters
| Parameter | Type | Default | Range | Filter Types | Description |
|---|---|---|---|---|---|
| Kaiser_beta | positive | 5.0 | 0-20 | Kaiser window only | Shape parameter: 0=rectangular, higher=narrower main lobe |
| Rolloff_factor | positive | 0.5 | 0-1 | Raised-cosine only | Excess bandwidth factor: 0=rectangular, 1=full cosine rolloff |
Visualization & Output
| Parameter | Type | Default | Description |
|---|---|---|---|
| Plot_responses | boolean | 1 (yes) | Generate magnitude and phase response plots |
| Plot_impulse_response | boolean | 1 (yes) | Generate impulse response plot (verify symmetry) |
| Apply_filter | boolean | 1 (yes) | Apply filter to selected sound (fast convolution) |
| Play_result | boolean | 1 (yes) | Auto-play filtered sound |
Performance Characteristics
| Characteristic | Typical Value | Dependence | Notes |
|---|---|---|---|
| Group Delay | (N-1)/(2f_s) seconds | Linear with filter length | Constant for all frequencies |
| Transition Width | ~3.3f_s/N (Hamming) | Inversely proportional to N | Window-dependent |
| Stopband Attenuation | 53dB (Hamming) | Window-dependent | Blackman: 74dB, Rectangular: 21dB |
| Computational Cost | O(N×L) for L samples | Linear in filter length | Praat's Convolve is optimized C code |
| Memory Usage | O(N) coefficients | Linear in filter length | Plus working memory for convolution |
Applications
Audio Processing & Mastering
Use case: Equalization without phase distortion, transient preservation
Recommended filters: Windowed-sinc (Hamming or Blackman)
Typical settings: Length 101-401, cutoff as needed, verify linear phase
Digital Communications
Use case: Pulse shaping, matched filtering, raised-cosine filtering
Recommended filters: Raised-cosine (Type 8)
Workflow:
- Set rolloff_factor based on bandwidth requirements
- Use same filter for transmit and receive (matched filter)
- Verify zero intersymbol interference via impulse response
- Check linear phase for timing synchronization
Signal Analysis & Measurement
Use case: Analytic signal creation, envelope detection, phase shifting
Recommended filters: Hilbert Transform (Type 9)
Advantages:
- Perfect 90° phase shift for all frequencies
- Linear phase (constant group delay)
- Unity magnitude response (except near DC/Nyquist)
- Can create analytic signals for instantaneous frequency analysis
Practical Workflow Examples
🎵 Phase-Preserving Audio Equalization
Goal: Apply lowpass filter without smearing transients
Settings:
- Filter type: Windowed-sinc (Blackman)
- Filter mode: Lowpass
- Length: 201 samples (good sharpness)
- Cutoff: 5000Hz (gentle high-frequency rolloff)
- Plot_impulse_response: Yes (verify symmetry)
- Plot_responses: Yes (check linear phase)
Result: High frequencies attenuated with zero phase distortion
📡 Raised-Cosine Pulse Shaping
Goal: Prepare signal for digital transmission
Settings:
- Filter type: Raised-cosine
- Length: 101 samples
- Cutoff: Symbol rate/2 (e.g., 2400Hz for 4800 baud)
- Rolloff_factor: 0.35 (35% excess bandwidth)
- Plot_impulse_response: Yes (verify zero ISI at sampling instants)
Result: Bandlimited signal with controlled intersymbol interference
🔄 Analytic Signal for Envelope Detection
Goal: Extract amplitude envelope of modulated signal
Settings:
- Filter type: Hilbert Transform
- Length: 101 samples (good 90° approximation)
- Plot_responses: Yes (verify 90° phase shift and unity magnitude)
- Apply_filter: Yes (produces imaginary part)
Result: Analytic signal x_a[n] = x[n] + j·H{x[n]} for envelope calculation
Advanced Techniques
- Lowpass + Highpass = Bandpass: Convolution of both impulse responses
- Multiple identical filters = Sharper rolloff: h_total[n] = h[n] * h[n] (convolution)
- Parallel filters = Filter banks: Different cutoffs, sum or select outputs
- Hilbert + Delay = Analytic signal delay correction: Compensate for group delay
Remember: Cascading preserves linear phase if all filters have linear phase
- General audio: 101-201 taps (good compromise)
- Sharp cutoff needed: 401-801 taps (longer = sharper)
- Simple smoothing: 21-51 taps (moving average or short FIR)
- Hilbert transform: 101-201 taps (good 90° approximation)
- Rule of thumb: Transition width ≈ (window_constant × f_s)/N
Always check frequency response plots to verify performance
Troubleshooting Common Issues
Cause: Window with high sidelobes (Rectangular), or filter too short
Solution: Use Blackman or Kaiser window, increase filter length
Cause: Filter too short, or window with wide main lobe
Solution: Increase filter length, use Kaiser with lower beta
Cause: Even filter length (script should fix this)
Solution: Ensure filter_length is odd, check script adjustment
Cause: Numerical precision, or response near zeros
Solution: Normal phase wrapping is okay; check magnitude response