State.h
#ifndef IIR1_STATE_H
#define IIR1_STATE_H
#include "Common.h"
#include "Biquad.h"
#include <stdexcept>
#define DEFAULT_STATE DirectFormII
namespace Iir {
class DllExport DirectFormI
{
public:
DirectFormI ()
{
reset();
}
void reset ()
{
m_x1 = 0;
m_x2 = 0;
m_y1 = 0;
m_y2 = 0;
}
inline double filter(const double in,
const Biquad& s)
{
const double out = s.m_b0*in + s.m_b1*m_x1 + s.m_b2*m_x2
- s.m_a1*m_y1 - s.m_a2*m_y2;
m_x2 = m_x1;
m_y2 = m_y1;
m_x1 = in;
m_y1 = out;
return out;
}
protected:
double m_x2 = 0; // x[n-2]
double m_y2 = 0; // y[n-2]
double m_x1 = 0; // x[n-1]
double m_y1 = 0; // y[n-1]
};
//------------------------------------------------------------------------------
class DllExport DirectFormII
{
public:
DirectFormII ()
{
reset ();
}
void reset ()
{
m_v1 = 0;
m_v2 = 0;
}
inline double filter(const double in,
const Biquad& s)
{
const double w = in - s.m_a1*m_v1 - s.m_a2*m_v2;
const double out = s.m_b0*w + s.m_b1*m_v1 + s.m_b2*m_v2;
m_v2 = m_v1;
m_v1 = w;
return out;
}
private:
double m_v1 = 0; // v[-1]
double m_v2 = 0; // v[-2]
};
//------------------------------------------------------------------------------
class DllExport TransposedDirectFormII
{
public:
TransposedDirectFormII ()
{
reset ();
}
void reset ()
{
m_s1 = 0;
m_s1_1 = 0;
m_s2 = 0;
m_s2_1 = 0;
}
inline double filter(const double in,
const Biquad& s)
{
const double out = m_s1_1 + s.m_b0*in;
m_s1 = m_s2_1 + s.m_b1*in - s.m_a1*out;
m_s2 = s.m_b2*in - s.m_a2*out;
m_s1_1 = m_s1;
m_s2_1 = m_s2;
return out;
}
private:
double m_s1 = 0;
double m_s1_1 = 0;
double m_s2 = 0;
double m_s2_1 = 0;
};
}
#endif
Iir::DirectFormII
Definition: State.h:103
Iir::Biquad
Definition: Biquad.h:52
Iir::DirectFormI
Definition: State.h:56
Iir
Definition: Biquad.cpp:41
Iir::TransposedDirectFormII
Definition: State.h:137