I try to implement a generic IIR filter. The main is as follows:
// Loop over all SOS sections:
value_type y = x;
BOOST_FOREACH( Sos& n, m_sos )
{
y = update( n, y );
}
with:
...update( Sos& sos, const value_type& x ) const
{
const value_type xs = sos.m_s * x;
const value_type w0 = xs
- sos.m_a( 1 ) * sos.m_w( 0 )
- sos.m_a( 2 ) * sos.m_w( 1 );
const value_type y = w0
+ sos.m_b( 1 ) * sos.m_w( 0 )
+ sos.m_b( 2 ) * sos.m_w( 1 );
sos.m_w( 1 ) = sos.m_w( 0 );
sos.m_w( 0 ) = w0;
return y;
}
The coefficients m_a, m_b are variable and read from a file once during runtime. Therefore the values are unknown during compile time. Depending on the designed filter it can happen that some coefficients are 1.0 or 0.0. Therefore the corresponding operation can be omitted. This will save a lot performance. For sure I can now optimize the code to be fast for one dedicated filter but as mentioned the implementation shall be very generic. My first idea was some kind of self modifiying algorithm...but maybe someone has a cool idea or hint... :)