Class FilterDesign
Factory for creating standard FIR and IIR filter designs.
Inherited Members
Namespace: MOSAIC.Components.SignalProcessing
Assembly: MOSAIC.dll
Syntax
public static class FilterDesign
Remarks
This class provides static factory methods that compute filter coefficients and return ready-to-use FirFilter or IirFilter instances.
FIR filters are designed using the windowed-sinc method with a Hamming window. Highpass, bandpass, and bandstop variants are derived from the lowpass prototype via spectral inversion and subtraction.
IIR filters use a Butterworth analog prototype transformed to the digital domain via the bilinear transform. Bandpass and bandstop variants use the proper analog prototype frequency transformations (LP→BP and LP→BS) to produce correct responses, including narrow-band notch filters.
Frequency convention: All cutoff frequencies are specified in Hz (not normalized). The sample rate must be provided so the design methods can compute normalized frequencies internally.
Methods
BilinearTransform(Complex[], Complex[], double, bool)
Applies the bilinear transform to convert analog poles and zeros into digital filter coefficients.
Declaration
private static (double[] b, double[] a) BilinearTransform(Complex[] zeros, Complex[] poles, double wc, bool isHighpass = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Complex[] | zeros | Analog-domain zeros. |
| Complex[] | poles | Analog-domain poles. |
| double | wc | Pre-warped cutoff frequency. |
| bool | isHighpass | When true, zeros are placed at |
Returns
| Type | Description |
|---|---|
| (double[] b, double[] a) | A tuple of numerator ( |
ButterworthPrototypePoles(int)
Returns the Butterworth lowpass analog prototype poles on the unit circle (left half-plane).
Declaration
private static Complex[] ButterworthPrototypePoles(int order)
Parameters
| Type | Name | Description |
|---|---|---|
| int | order | Filter order. |
Returns
| Type | Description |
|---|---|
| Complex[] | Array of |
Convolve(double[], double[])
Computes the discrete convolution of two coefficient arrays.
Declaration
private static double[] Convolve(double[] a, double[] b)
Parameters
| Type | Name | Description |
|---|---|---|
| double[] | a | First coefficient array. |
| double[] | b | Second coefficient array. |
Returns
| Type | Description |
|---|---|
| double[] | The convolution result with length |
Remarks
Cascades two transfer functions by convolving their numerator and denominator polynomials. Currently unused: the bandpass and bandstop designs build their polynomials directly from the transformed poles and zeros via PolyFromRoots(Complex[]) rather than by cascading.
CreateFirBandpass(double, double, double, int)
Creates a bandpass FIR filter by subtracting two lowpass prototypes.
Declaration
public static FirFilter CreateFirBandpass(double sampleRate, double lowCutoff, double highCutoff, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. Must be greater than |
| int | numTaps | Number of filter coefficients. |
Returns
| Type | Description |
|---|---|
| FirFilter | A new FirFilter configured with the computed coefficients. |
CreateFirBandstop(double, double, double, int)
Creates a bandstop (notch) FIR filter via spectral inversion of a bandpass prototype.
Declaration
public static FirFilter CreateFirBandstop(double sampleRate, double lowCutoff, double highCutoff, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. Must be greater than |
| int | numTaps | Number of filter coefficients. |
Returns
| Type | Description |
|---|---|
| FirFilter | A new FirFilter configured with the computed coefficients. |
CreateFirHighpass(double, double, int)
Creates a highpass FIR filter using spectral inversion of a lowpass prototype.
Declaration
public static FirFilter CreateFirHighpass(double sampleRate, double cutoffFreq, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. Must be less than |
| int | numTaps | Number of filter coefficients. Should be odd for a symmetric highpass response. |
Returns
| Type | Description |
|---|---|
| FirFilter | A new FirFilter configured with the computed coefficients. |
CreateFirLowpass(double, double, int)
Creates a lowpass FIR filter using the windowed-sinc method with a Hamming window.
Declaration
public static FirFilter CreateFirLowpass(double sampleRate, double cutoffFreq, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. Must be less than |
| int | numTaps | Number of filter coefficients (filter order + 1). Higher values yield sharper roll-off. |
Returns
| Type | Description |
|---|---|
| FirFilter | A new FirFilter configured with the computed coefficients. |
CreateIirBandpass(double, double, double, int)
Creates a bandpass IIR Butterworth filter using the proper analog prototype transformation.
Declaration
public static IirFilter CreateIirBandpass(double sampleRate, double lowCutoff, double highCutoff, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. Must be greater than |
| int | order | Filter order of the prototype. The resulting filter has order |
Returns
| Type | Description |
|---|---|
| IirFilter | A new IirFilter with the computed numerator ( |
Remarks
Uses the standard LP→BP analog frequency transformation s → (s² + ω₀²) / (BW·s)
where ω₀ = √(ωL·ωH) and BW = ωH − ωL. Each prototype pole maps to two
bandpass poles, and N zeros are placed at DC (z = 1) and Nyquist (z = −1).
CreateIirBandstop(double, double, double, int)
Creates a bandstop (notch) IIR Butterworth filter using the proper analog prototype transformation.
Declaration
public static IirFilter CreateIirBandstop(double sampleRate, double lowCutoff, double highCutoff, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. Must be greater than |
| int | order | Filter order of the prototype. The resulting filter has order |
Returns
| Type | Description |
|---|---|
| IirFilter | A new IirFilter with the computed numerator ( |
Remarks
Uses the standard LP→BS analog frequency transformation s → (BW·s) / (s² + ω₀²).
Each prototype pole maps to two bandstop poles, and 2N zeros are placed at ±jω₀
(which map to conjugate pairs on the unit circle at the notch frequency after bilinear transform).
CreateIirHighpass(double, double, int)
Creates a highpass IIR Butterworth filter.
Declaration
public static IirFilter CreateIirHighpass(double sampleRate, double cutoffFreq, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. Must be less than |
| int | order | Filter order. |
Returns
| Type | Description |
|---|---|
| IirFilter | A new IirFilter with the computed numerator ( |
CreateIirLowpass(double, double, int)
Creates a lowpass IIR Butterworth filter.
Declaration
public static IirFilter CreateIirLowpass(double sampleRate, double cutoffFreq, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. Must be less than |
| int | order | Filter order. Higher values yield sharper roll-off but may introduce numerical instability. |
Returns
| Type | Description |
|---|---|
| IirFilter | A new IirFilter with the computed numerator ( |
DesignButterworthBandpass(double, double, double, int)
Designs a bandpass Butterworth IIR filter using the proper analog prototype transformation.
Declaration
private static (double[] b, double[] a) DesignButterworthBandpass(double sampleRate, double lowCutoff, double highCutoff, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. |
| int | order | Prototype filter order. The resulting filter has order 2N. |
Returns
| Type | Description |
|---|---|
| (double[] b, double[] a) | A tuple of numerator ( |
Remarks
The LP→BP transformation maps each prototype pole p to two analog poles:
p_bp = (p·BW/2) ± √((p·BW/2)² − ω₀²)
Zeros: N at s = 0 (map to z = 1) and N at s = ∞ (map to z = −1).
DesignButterworthBandstop(double, double, double, int)
Designs a bandstop (notch) Butterworth IIR filter using the proper analog prototype transformation.
Declaration
private static (double[] b, double[] a) DesignButterworthBandstop(double sampleRate, double lowCutoff, double highCutoff, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. |
| int | order | Prototype filter order. The resulting filter has order 2N. |
Returns
| Type | Description |
|---|---|
| (double[] b, double[] a) | A tuple of numerator ( |
Remarks
The LP→BS transformation maps each prototype pole p to two analog poles:
p_bs = BW/(2p) ± √((BW/(2p))² − ω₀²)
Zeros: 2N zeros at s = ±jω₀, which after bilinear transform become conjugate pairs
on the unit circle at the notch frequency, producing deep rejection at the center.
DesignButterworthHighpass(double, double, int)
Designs a highpass Butterworth IIR filter using the s → ωc/s frequency transformation.
Declaration
private static (double[] b, double[] a) DesignButterworthHighpass(double sampleRate, double cutoffFreq, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. |
| int | order | Filter order. |
Returns
| Type | Description |
|---|---|
| (double[] b, double[] a) | A tuple of numerator ( |
DesignButterworthLowpass(double, double, int)
Designs a lowpass Butterworth IIR filter using analog prototype poles and the bilinear transform.
Declaration
private static (double[] b, double[] a) DesignButterworthLowpass(double sampleRate, double cutoffFreq, int order)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. |
| int | order | Filter order. |
Returns
| Type | Description |
|---|---|
| (double[] b, double[] a) | A tuple of numerator ( |
DesignFirBandpass(double, double, double, int)
Designs a bandpass FIR filter by subtracting a low-cutoff lowpass from a high-cutoff lowpass.
Declaration
private static double[] DesignFirBandpass(double sampleRate, double lowCutoff, double highCutoff, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. |
| int | numTaps | Number of filter coefficients. |
Returns
| Type | Description |
|---|---|
| double[] | Bandpass filter coefficients. |
DesignFirBandstop(double, double, double, int)
Designs a bandstop FIR filter by applying spectral inversion to a bandpass prototype.
Declaration
private static double[] DesignFirBandstop(double sampleRate, double lowCutoff, double highCutoff, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | lowCutoff | Lower cutoff frequency in Hz. |
| double | highCutoff | Upper cutoff frequency in Hz. |
| int | numTaps | Number of filter coefficients. |
Returns
| Type | Description |
|---|---|
| double[] | Bandstop filter coefficients. |
DesignFirHighpass(double, double, int)
Designs a highpass FIR filter by applying spectral inversion to a lowpass prototype.
Declaration
private static double[] DesignFirHighpass(double sampleRate, double cutoffFreq, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. |
| int | numTaps | Number of filter coefficients. |
Returns
| Type | Description |
|---|---|
| double[] | Highpass filter coefficients. |
DesignFirLowpass(double, double, int)
Designs a lowpass FIR filter using the windowed-sinc method with a Hamming window.
Declaration
private static double[] DesignFirLowpass(double sampleRate, double cutoffFreq, int numTaps)
Parameters
| Type | Name | Description |
|---|---|---|
| double | sampleRate | Sample rate in Hz. |
| double | cutoffFreq | Cutoff frequency in Hz. |
| int | numTaps | Number of filter coefficients. |
Returns
| Type | Description |
|---|---|
| double[] | Normalized filter coefficients whose sum equals 1 (unity DC gain). |
PolyFromRoots(Complex[])
Expands a set of complex roots into real polynomial coefficients.
Declaration
private static double[] PolyFromRoots(Complex[] roots)
Parameters
| Type | Name | Description |
|---|---|---|
| Complex[] | roots | The roots (zeros or poles) of the polynomial. |
Returns
| Type | Description |
|---|---|
| double[] | Real-valued polynomial coefficients in descending powers. Imaginary parts are discarded (assumed negligible for conjugate-pair roots). |