View Single Post
Old 03-21-2011, 02:51 AM   #1
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default Bessel filter implementation

Hi,

I have added a low-pass Bessel filter (besselfilter.h) implementation using matched Z-transform to my WDL repository. I have extracted this implementation from from the source code of mkfilter.

I have divided the implementation into three classes: one for calculating coefficients (WDL_BesselFilterCoeffs), one for the actual filter (WDL_BesselFilterStage), and a third class combining both (WDL_BesselFilter).

Here are a couple of (pseudo) code examples of its use:

Example #1:
Code:
// 8th order anti-alias filter
#define WDL_BESSEL_FILTER_ORDER 8
#include "besselfilter.h"

int oversampling = 8;

WDL_BesselFilterCoeffs bessel;
WDL_BesselFilterStage filter;

bessel.Calc(0.5 / (double)oversampling);
filter.Reset();

for (int i = 0; i < nFrames; ++i)
{
	filter.Process(inputs[0][i], bessel.Coeffs());
	outputs[0][i] = filter.Output();
}
Example #2:
Code:
#include "besselfilter.h"

int order = 4;
int oversampling = 8;

// 2 cascaded filters
WDL_BesselFilterStage filter[2];
filter[0].Reset();
filter[1].Reset();

WDL_BesselFilterCoeffs coeffs;
coeffs.Calc(0.5 / (double)oversampling, order);

for (int i = 0; i < nFrames; ++i)
{
	filter[0].Process(inputs[0][i], &coeffs);
	filter[1].Process(filter[0].Output(), &coeffs);
	outputs[0][i] = filter[1].Output();
}
Example #3:
Code:
#include "besselfilter.h"

int order = 8;
int oversampling = 8;

WDL_BesselFilter bessel;
bessel.Calc(0.5 / (double)oversampling, order);
bessel.Reset();

for (int i = 0; i < nFrames; ++i)
{
	bessel.Process(inputs[0][i]);
	outputs[0][i] = bessel.Output();
}
Tale is offline   Reply With Quote