mathnet / mathnet-filtering

Math.NET Filtering (formerly Neodym)
http://filtering.mathdotnet.com
Other
238 stars 82 forks source link

The IIR Filter ProcessSample is broken - will always return 0 #1

Closed thethereza closed 10 years ago

thethereza commented 11 years ago

If you look at the code, it quickly discards the input value

   public override double ProcessSample(double sample)    {
    double un = _leftCoefficients[0] * sample;
    for(int i = 0, j = _halfSize - _offset + 1; i < _halfSize - 1; i++, j++)
        un = _buffer[i] * _leftCoefficients[j];

    _offset = (_offset != 0) ? _offset - 1 : _halfSize - 1;
    _buffer[_offset] = un - _buffer[_offset] * _leftCoefficients[1];

    double yn = 0d;
    for(int i = 0, j = _halfSize - _offset; i < _halfSize; i++, j++)
        yn += _buffer[i] * _rightCoefficients[j];

    return yn;
}
cdrnet commented 10 years ago

Fixed, finally... ;)