コード例 #1
0
// Tests the filter factor setter
TEST(HighPassFilter, TestCutoffFrequencySet) {
  
  HighPassFilter hpf;

  //Check the id's matches
  EXPECT_TRUE( hpf.getId() == HighPassFilter::getId() );

  const Float delta = 1.0 / 500.0f; //Set a delta for 500Hz

  //Set the gain with a valid value
  EXPECT_TRUE( hpf.setCutoffFrequency( 10, delta ) );
  EXPECT_EQ( hpf.getFilterFactor(), GET_FILTER_FACTOR( 10.0, delta ) );

  //Set the gain with a non valid value
  EXPECT_FALSE( hpf.setCutoffFrequency( -1, delta ) );
  EXPECT_EQ( hpf.getFilterFactor(), GET_FILTER_FACTOR( 10.0, delta ) ); //The gain should not have changed

  //Set the gain with a non valid value
  EXPECT_FALSE( hpf.setCutoffFrequency( 0, delta ) );
  EXPECT_EQ( hpf.getFilterFactor(), GET_FILTER_FACTOR( 10.0, delta ) ); //The gain should not have changed

  //Set the gain with a non valid value
  EXPECT_FALSE( hpf.setCutoffFrequency( 10, 0 ) );
  EXPECT_EQ( hpf.getFilterFactor(), GET_FILTER_FACTOR( 10.0, delta ) ); //The gain should not have changed
}
コード例 #2
0
// Tests the default constructor
TEST(HighPassFilter, TestDefaultConstructor) {
  
  HighPassFilter hpf;

  //Check the id's matches
  EXPECT_TRUE( hpf.getId() == HighPassFilter::getId() );

  //Check the hpf is not trained
  EXPECT_TRUE( !hpf.getTrained() );
}
コード例 #3
0
// Tests the equals operator
TEST(HighPassFilter, TestEqualsOperator) {
  
  HighPassFilter hpf;

  //Check the id's matches
  EXPECT_TRUE( hpf.getId() == HighPassFilter::getId() );

  //Check the hpf is not trained
  EXPECT_TRUE( !hpf.getTrained() );

  HighPassFilter hpf2 = hpf;

  //Check the id's matches
  EXPECT_TRUE( hpf2.getId() == HighPassFilter::getId() );

  //Check the hpf is not trained
  EXPECT_TRUE( !hpf2.getTrained() );
}
コード例 #4
0
// Tests the filter factor getter/setter
TEST(HighPassFilter, TestFilterFactorGetSet) {
  
  HighPassFilter hpf;

  //Check the id's matches
  EXPECT_TRUE( hpf.getId() == HighPassFilter::getId() );

  //Set the gain with a valid value
  EXPECT_TRUE( hpf.setFilterFactor( 0.9 ) );
  EXPECT_EQ( hpf.getFilterFactor(), 0.9 );

  //Set the gain with a non valid value
  EXPECT_FALSE( hpf.setFilterFactor( -1 ) );
  EXPECT_EQ( hpf.getFilterFactor(), 0.9 ); //The gain should not have changed

  //Set the gain with a non valid value
  EXPECT_FALSE( hpf.setFilterFactor( 1.1 ) );
  EXPECT_EQ( hpf.getFilterFactor(), 0.9 ); //The gain should not have changed
}
コード例 #5
0
// Tests the save/load functions
TEST(HighPassFilter, TestSaveLoad) {
  
  HighPassFilter hpf;

  //Check the id's matches
  EXPECT_TRUE( hpf.getId() == HighPassFilter::getId() );

  const Float delta = 1.0 / 500.0f; //Set a delta for 500Hz

  //Set the gain with a valid value
  EXPECT_TRUE( hpf.setCutoffFrequency( 10, delta ) );
  EXPECT_EQ( hpf.getFilterFactor(), GET_FILTER_FACTOR( 10.0, delta ) );

  EXPECT_TRUE( hpf.save("hpf_unit_test_model.grt") );

  EXPECT_TRUE( hpf.clear() );

  EXPECT_TRUE( hpf.load("hpf_unit_test_model.grt") );
  EXPECT_EQ( ROUND( hpf.getFilterFactor() ), ROUND( GET_FILTER_FACTOR( 10.0, delta ) ) ); //Due to differences in how things are load from the file, we need to round the expected value
}
コード例 #6
0
int main (int argc, const char * argv[])
{
    //Create a new instance of a high pass filter, using the default constructor
    HighPassFilter hpf;
    
    //Set the cutoff frequency of the filter to 2.0Hz
    hpf.setCutoffFrequency( 2, 1.0/1000.0);
    
    //Create some varaibles to help generate the signal data
    const UINT numSeconds = 60;                         //The number of seconds of data we want to generate
    double t = 0;                                       //This keeps track of the time
    double tStep = 1.0/1000.0;                          //This is how much the time will be updated at each iteration in the for loop
    double freq = 0;                                    //Stores the frequency
    map< UINT, double > freqRates;                      //Holds the frequency rates
    map< UINT, double >::iterator iter;                 //An iterator for the frequency rates map
    
    //Add the freq rates
    //The first value is the time in seconds and the second value is the frequency that should be set at that time
    freqRates[ 0 ] = 0.1;
    freqRates[ 10 ] = 0.5;
    freqRates[ 20 ] = 1;
    freqRates[ 30 ] = 2;
    freqRates[ 40 ] = 4;
    freqRates[ 50 ] = 8;
    
    //Create and open a file to save the data
    fstream file;
    file.open("HighPassFilterData.txt", iostream::out);
    
    //Generate the signal and filter the data
    for(UINT i=0; i<numSeconds*1000; i++){
        
        //Check to see if we should update the freq rate to the next value
        iter = freqRates.find( i/1000 );
        if( iter != freqRates.end() ){
            //Set the new frequency value
            freq = iter->second;
        }
        
        //Generate the signal
        double signal = sin( t * TWO_PI*freq );
        
        //Filter the signal
        double filteredValue = hpf.filter( signal );
        
        //Write the signal and the filtered data to the file
        file << signal << "\t" << filteredValue << endl;
        
        //Update the t
        t += tStep;
    }
    
    //Close the file
    file.close();
    
    //Save the HighPassFilter settings to a file
    hpf.saveSettingsToFile("HighPassFilterSettings.txt");
    
    //We can then load the settings later if needed
    hpf.loadSettingsFromFile("HighPassFilterSettings.txt");
    
    return EXIT_SUCCESS;
}