PoleFilter.h
#ifndef IIR1_POLEFILTER_H
#define IIR1_POLEFILTER_H
#include "Common.h"
#include "MathSupplement.h"
#include "Cascade.h"
#include "State.h"
namespace Iir {
/***
* Base for filters designed via algorithmic placement of poles and zeros.
*
* Typically, the filter is first designed as a half-band low pass or
* low shelf analog filter (s-plane). Then, using a transformation such
* as the ones from Constantinides, the poles and zeros of the analog filter
* are calculated in the z-plane.
*
***/
class DllExport PoleFilterBase2 : public Cascade
{
public:
// This gets the poles/zeros directly from the digital
// prototype. It is used to double check the correctness
// of the recovery of pole/zeros from biquad coefficients.
//
// It can also be used to accelerate the interpolation
// of pole/zeros for parameter modulation, since a pole
// filter already has them calculated
std::vector<PoleZeroPair> getPoleZeros () const
{
std::vector<PoleZeroPair> vpz;
const int pairs = (m_digitalProto.getNumPoles () + 1) / 2;
for (int i = 0; i < pairs; ++i)
vpz.push_back (m_digitalProto[i]);
return vpz;
}
protected:
LayoutBase m_digitalProto;
};
template <class AnalogPrototype>
class DllExport PoleFilterBase : public PoleFilterBase2
{
protected:
void setPrototypeStorage (const LayoutBase& analogStorage,
const LayoutBase& digitalStorage)
{
m_analogProto.setStorage (analogStorage);
m_digitalProto = digitalStorage;
}
protected:
AnalogPrototype m_analogProto;
};
//------------------------------------------------------------------------------
template <class BaseClass,
class StateType,
int MaxAnalogPoles,
int MaxDigitalPoles = MaxAnalogPoles>
struct PoleFilter : BaseClass
, CascadeStages <(MaxDigitalPoles + 1) / 2 , StateType>
{
PoleFilter ()
{
// This glues together the factored base classes
// with the templatized storage classes.
BaseClass::setCascadeStorage (this->getCascadeStorage());
BaseClass::setPrototypeStorage (m_analogStorage, m_digitalStorage);
}
private:
Layout <MaxAnalogPoles> m_analogStorage;
Layout <MaxDigitalPoles> m_digitalStorage;
};
//------------------------------------------------------------------------------
class DllExport LowPassTransform
{
public:
LowPassTransform (double fc,
LayoutBase& digital,
LayoutBase const& analog);
private:
complex_t transform (complex_t c);
double f;
};
//------------------------------------------------------------------------------
class DllExport HighPassTransform
{
public:
HighPassTransform (double fc,
LayoutBase& digital,
LayoutBase const& analog);
private:
complex_t transform (complex_t c);
double f;
};
//------------------------------------------------------------------------------
class DllExport BandPassTransform
{
public:
BandPassTransform (double fc,
double fw,
LayoutBase& digital,
LayoutBase const& analog);
private:
ComplexPair transform (complex_t c);
double wc;
double wc2;
double a;
double b;
double a2;
double b2;
double ab;
double ab_2;
};
//------------------------------------------------------------------------------
class DllExport BandStopTransform
{
public:
BandStopTransform (double fc,
double fw,
LayoutBase& digital,
LayoutBase const& analog);
private:
ComplexPair transform (complex_t c);
double wc;
double wc2;
double a;
double b;
double a2;
double b2;
};
}
#endif
Iir::PoleFilterBase
Definition: PoleFilter.h:89
Iir::Layout< MaxAnalogPoles >
Iir::ComplexPair
Definition: Types.h:48
Iir::CascadeStages
Definition: Cascade.h:127
Iir::PoleFilter
Definition: PoleFilter.h:112
Iir::CascadeStages<(MaxAnalogPoles+1)/2, StateType >::getCascadeStorage
const Cascade::Storage getCascadeStorage()
Definition: Cascade.h:175
Iir::Cascade
Definition: Cascade.h:50
Iir
Definition: Biquad.cpp:41
Iir::BandStopTransform
Definition: PoleFilter.h:207
Iir::BandPassTransform
Definition: PoleFilter.h:180
Iir::PoleFilterBase2
Definition: PoleFilter.h:59
Iir::LayoutBase
Definition: Layout.h:63
Iir::HighPassTransform
Definition: PoleFilter.h:162
Iir::LowPassTransform
Definition: PoleFilter.h:144