/*************************************************
 *                   bwf.h
 *
 *************************************************/

#ifndef __BWF_H__
#define __BWF_H__

#ifndef PI
#define PI 3.141592653589793238462643383279
#endif

enum BWFilterType {HP, LP};

class BWF_n1
{
public:
    void create(double tau, double fc, BWFilterType hp);
    double pass(double x);
    void reset();
    
private:
    double tau_;
    double fc_;
    BWFilterType hp_;
    
    double a1_;
    double b0_;
    double y_;
};

class BWF_n2
{
public:
    void create(double tau, double fc, double theta, BWFilterType hp);
    double pass(double x);
    void reset();

private:
    double tau_;
    double fc_;
    double theta_;
    double ss_, cs_;
    double a1_, a2_, b1_;
    double x1_;
    double y1_, y2_;
    BWFilterType hp_;
};

class BWF
{
public:
    BWF(){}
    BWF(double tau, // サンプリング周期[sec]
        double fc,  // カットオフ周波数[Hz]
        int dim,    // フィルターの次元
        BWFilterType hp);
    ~BWF();
    void create(double tau, double fc, int dim, BWFilterType hp);
    double pass(double x);
    void reset(double offset=0.0);
    
private:
    double tau_;
    double fc_;
    int	dim_;
    int n1_;
    int	n2_;
    int	fnum_;
    BWF_n1 *n1_filter_;
    BWF_n2 *n2_filters_;
    BWFilterType hp_;
    double offset_;
};


#endif // __BWF_H__
