Code Packages  1
Add-on code processing modules
Static Public Member Functions | List of all members
dsp.FIR Class Reference

Provides finite impulse response (FIR) filters More...

Static Public Member Functions

static double [] BandPass (double fc_Low, double fc_High, double fs, int samples, Window.Type w)
 Returns a normalized band pass filter kernel using the specified window. More...
 
static double [] BandStop (double fc_Low, double fc_High, double fs, int samples, Window.Type w)
 Returns a normalized band stop filter kernel using the specified window. More...
 
static double [] DC_Unity (double[] A)
 DC unity gain More...
 
static double [] Filter (double[] A, double[] kernel)
 Filter operation used to filter data using the specified filter kernel. More...
 
static double [] HBandH (int samples, Window.Type w)
 Returns a normalized high pass half band filter kernel using the specified window More...
 
static double [] HBandL (int samples, Window.Type w)
 Returns a normalized low pass half band filter kernel using the specified window More...
 
static double [] HighPass (double fc, double fs, int samples, Window.Type w)
 Returns a normalized high pass filter kernel using the specified window. More...
 
static double [] LowPass (double fc, double fs, int samples, Window.Type w)
 Returns a normalized low pass filter kernel using the specified window. More...
 
static double [] Sinc (double f_fs, int samples)
 Returns a rectangular sinc filter kernel, that is a truncated and shifted version of the ideal sinc function More...
 
static double [] SpectralInverse (double[] kernel)
 Invert the frequency spectrum of the specified filter kernel. More...
 

Detailed Description

Provides finite impulse response (FIR) filters

Member Function Documentation

◆ BandPass()

static double [] dsp.FIR.BandPass ( double  fc_Low,
double  fc_High,
double  fs,
int  samples,
Window.Type  w 
)
static

Returns a normalized band pass filter kernel using the specified window.

The impulse response has unity gain at DC and left-right symmetry.

Parameters
fc_Lowlow cut-off frequency (Hz)
fc_Highhigh cut-off frequency (Hz)
fssampling rate (Hz)
sampleskernel size, should be an odd number
wWindow type

Example

double[] kernel = FIR.BandPass(25, 75, 200, 11, Window.Type.Blackman);
kernel = NArray.Round(kernel, 8);
Console.WriteLine(NArray.ToString(kernel));
0 0 -0.00320435 -0.17950679 -0.04066185 0.44674597 -0.04066185 -0.17950679 -0.00320435 0 0

◆ BandStop()

static double [] dsp.FIR.BandStop ( double  fc_Low,
double  fc_High,
double  fs,
int  samples,
Window.Type  w 
)
static

Returns a normalized band stop filter kernel using the specified window.

The impulse response has unity gain at DC and left-right symmetry.

Parameters
fc_Lowlow cut-off frequency (Hz)
fc_Highhigh cut-off frequency (Hz)
fssampling rate (Hz)
sampleskernel size, should be an odd number
wWindow type

Example

double[] kernel = FIR.BandStop(25, 75, 200, 11, Window.Type.Blackman);
kernel = NArray.Round(kernel, 8);
Console.WriteLine(NArray.ToString(kernel));
0 0 0.00320435 0.17950679 0.04066185 0.55325403 0.04066185 0.17950679 0.00320435 0 0

◆ DC_Unity()

static double [] dsp.FIR.DC_Unity ( double []  A)
static

DC unity gain

Parameters
Areal array

Example

double[] kernel = FIR.Sinc(0.25, 11);
kernel = FIR.DC_Unity(kernel);
kernel = NArray.Round(kernel, 4);
Console.WriteLine(NArray.ToString(kernel));
0.0605 0 -0.1009 0 0.3027 0.4754 0.3027 0 -0.1009 0 0.0605

◆ Filter()

static double [] dsp.FIR.Filter ( double []  A,
double []  kernel 
)
static

Filter operation used to filter data using the specified filter kernel.

FIR filter function runs the convolution function Signal.Convolution and removes the extra samples from the end.
The output signal has the same size as the input signal.
Note: If the same filter kernel is to be used by many signals, run the kernel function just once, and apply the filter function per signal.

Parameters
Areal array
kernelfilter kernel

Example
The following example shows how to filter an input signal (A) using a low pass filter.

double[] A = new double[] { 3, 7, -2, 1, -5, 3, 9, 4 };
double[] kernel = FIR.LowPass(5, 20, 10, Window.Type.Rectangular);
double[] result = FIR.Filter( A, kernel);
result = NArray.Round(result, 2);
Console.WriteLine(NArray.ToString(result));
0 -0.32 -0.75 1.18 3.67 4.4 1.24 -3.04

◆ HBandH()

static double [] dsp.FIR.HBandH ( int  samples,
Window.Type  w 
)
static

Returns a normalized high pass half band filter kernel using the specified window

The cut off frequency is set to 0.25 as a fraction of the sampling rate. The impulse response has unity gain at DC and left-right symmetry.

Parameters
sampleskernel size, should be an odd number
wWindow type

Example

double[] kernel = FIR.HBandH(11, Window.Type.Blackman);
kernel = NArray.Round(kernel, 8);
Console.WriteLine(NArray.ToString(kernel));
0 0 0.02134438 0 -0.27085136 0.49901394 -0.27085136 0 0.02134438 0 0

◆ HBandL()

static double [] dsp.FIR.HBandL ( int  samples,
Window.Type  w 
)
static

Returns a normalized low pass half band filter kernel using the specified window

The cut off frequency is set to 0.25 as a fraction of the sampling rate. The impulse response has unity gain at DC and left-right symmetry.

Parameters
sampleskernel size, should be an odd number
wWindow type

Example

double[] kernel = FIR.HBandL(11, Window.Type.Blackman);
kernel = NArray.Round(kernel, 8);
Console.WriteLine(NArray.ToString(kernel));
0 0 -0.02134438 0 0.27085136 0.50098606 0.27085136 0 -0.02134438 0 0

◆ HighPass()

static double [] dsp.FIR.HighPass ( double  fc,
double  fs,
int  samples,
Window.Type  w 
)
static

Returns a normalized high pass filter kernel using the specified window.

The impulse response has unity gain at DC and left-right symmetry.

Parameters
fccut-off frequency (Hz)
fssampling rate (Hz)
sampleskernel size, should be an odd number
wWindow type


Example

double[] kernel = FIR.HighPass(25, 200, 11, Window.Type.Blackman);
kernel = NArray.Round(kernel, 8);
Console.WriteLine(NArray.ToString(kernel));
0 0 -0.01826524 -0.09838329 -0.23177828 0.69685363 -0.23177828 -0.09838329 -0.01826524 0 0

◆ LowPass()

static double [] dsp.FIR.LowPass ( double  fc,
double  fs,
int  samples,
Window.Type  w 
)
static

Returns a normalized low pass filter kernel using the specified window.

The impulse response has unity gain at DC and left-right symmetry.

Parameters
fccut-off frequency (Hz)
fssampling rate (Hz)
sampleskernel size, should be an odd number
wWindow type


Example

double[] kernel = FIR.LowPass(25, 200, 11, Window.Type.Blackman);
kernel = NArray.Round(kernel, 8);
Console.WriteLine(NArray.ToString(kernel));
0 0 0.01826524 0.09838329 0.23177828 0.30314637 0.23177828 0.09838329 0.01826524 0 0

◆ Sinc()

static double [] dsp.FIR.Sinc ( double  f_fs,
int  samples 
)
static

Returns a rectangular sinc filter kernel, that is a truncated and shifted version of the ideal sinc function

Parameters
f_fsfrequency as a fraction of the sampling rate (0..0.5).
sampleskernel size, should be an odd number

Example

double[] kernel = FIR.Sinc(0.25, 11);
kernel = NArray.Round(kernel, 8);
Console.WriteLine(NArray.ToString(kernel));
0.2 0 -0.33333333 0 1 1.57079633 1 0 -0.33333333 0 0.2

◆ SpectralInverse()

static double [] dsp.FIR.SpectralInverse ( double []  kernel)
static

Invert the frequency spectrum of the specified filter kernel.

Spectral inversion is performed in time domain and results the frequency response of the impulse to being flipped top-for-bottom.

Parameters
kernelfilter kernel with unity gain at DC

Example

double[] kernel = FIR.Sinc(0.125, 11);
kernel = FIR.DC_Unity(kernel);
kernel = NArray.Round(kernel, 4);
Console.WriteLine(NArray.ToString(kernel));
kernel = FIR.SpectralInverse(kernel);
Console.WriteLine(NArray.ToString(kernel));
-0.0417 0 0.0696 0.1476 0.2087 0.2318 0.2087 0.1476 0.0696 0 -0.0417
0.0417 0 -0.0696 -0.1476 -0.2087 0.7682 -0.2087 -0.1476 -0.0696 0 0.0417