/*************************************************
 *                   test-bwf.cpp
 *
 *************************************************/
#include "bwf.h"
#include <math.h>
#include <iostream>
#include <fstream>


int test1();
int test3();

int main(){
    test1();
    test3();
    return 0;
}


int test1(){
    FILE* f;
    f = fopen("bwf_eval.log", "w");

    // Filter 作成
    BWF hp1(0.01, 1.0, 2, HP);
    BWF lp1(0.01, 1.0, 2, LP);
    
    BWF hp2(0.01, 10.0, 2, HP);
    BWF lp2(0.01, 10.0, 2, LP);
    
    BWF hp3(0.01, 30.0, 2, HP);
    BWF lp3(0.01, 30.0, 2, LP);    

    
    double time=0;
    double x, y1, y2, y3, y4, y5, y6;

    //
    for(int i=0; i<100; i++){
        time += 0.01;
        // サンプルの波の作成 0.1
        x = 0;
        //x += sin ((2*PI/100)*i * 20);//20fps
        x += sin ((2*PI/100)*i * 5);//10fps
        x += sin ((2*PI/100)*i * 1); //1fps
        
        y1 = hp1.pass(x);
        y2 = hp2.pass(x);
        y3 = hp3.pass(x);
        
        y4 = lp1.pass(x);
        y5 = lp2.pass(x);
        y6 = lp3.pass(x);        
        
        fprintf(f,"%f %f %f %f %f %f %f %f\n",time,x,y1,y2,y3,y4,y5,y6);
    }

    
    fclose(f);
    return 0;
}


// resetのチェック
int test3(){
    FILE* f;
    f = fopen("bwf_eval3.log", "w");
    BWF lp(0.01, 10.0, 2, LP);

    double time = 0;
    double input;
    double output;
    double offset = 1;

    //
    for(int i=0; i<100; i++){
        time += 0.01;
        // サンプルの波の作成 0.1
        input = 0;
        input += sin ((2*PI/100)*i *  5); //5fps
        input += sin ((2*PI/100)*i *  1); //1fps

        // BWF
        output = lp.pass(input);

        // Log
        fprintf(f,"%f %f %f\n",time, input, output);
    }

    //
    lp.reset(offset);
    for(int i=0; i<100; i++){
        time += 0.01;
        // サンプルの波の作成 0.1
        input = offset;
        input += sin ((2*PI/100)*i *  5); //5fps
        input += sin ((2*PI/100)*i *  1); //1fps

        // BWF
        output = lp.pass(input);

        // Log
        fprintf(f,"%f %f %f\n",time, input, output);
    }    
    fclose(f);
    return 0;
}
