High Pass Filter


The HighPassFilter class implements a first-order infinite-impulse-response (IIR) high pass filter. The HighPassFilter is part of the Preprocessing Modules.

High Pass Filter Example
An example of a signal (sine wave at 0.1Hz, 0.5Hz, 1Hz, 2Hz, 4Hz and 8Hz) filtered using a high pass filter. The cutoff frequency of the filter is set to 2Hz. The red signal is the raw signal and the green signal is the filtered signal. The signal and filtered data was generated using the example code below HighPassFilterExampleImage1.jpg


The HighPassFilter is good for removing a small amount of low frequency noise from an N dimensional signal. You can either remove this noise from the N dimensional signal by setting the filterFactor of the filter to a low value (i.e. a filterFactor value of 0.1 will result in a large amount of low frequency signal attenuation), alternatively, if you know the exact frequency of the noise you want to remove from the signal then you can explicitly set the cutoff frequency of the filter (using the setCutoffFrequency(...) function).


Given that this filter is only a first-order filter, it may not give you a step enough cutoff frequency for the application you need.

Example Code

 GRT HighPassFilter Example
 This example demonstrates how to create and use the GRT HighPassFilter PreProcessing Module.

 The HighPassFilter implements a first-order infinite-impulse-response (IIR) high pass filter.

 In this example we create an instance of a HighPassFilter and use this to filter some
 dummy data, generated from a series of sine waves (with increasing frequency ranging from 0.1Hz to 8Hz).
 The test signal and filtered signals are then saved to a file (so you can plot the results in Matlab,
 Excel, etc. if needed).

 This example shows you how to:
 - Create a new HighPassFilter instance a 1 dimensional signal
 - Set a specific filter cutoff frequency
 - Filter some data using the HighPassFilter
 - Save the HighPassFilter settings to a file
 - Load the HighPassFilter settings from a file

#include "GRT.h"
using namespace GRT;

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

    //Save the HighPassFilter settings to a file

    //We can then load the settings later if needed

    return EXIT_SUCCESS;

Code & Resources



You can find the documentation for this class at High Pass Filter documentation.