# Noise filtering with QSensorFilter for QSensor?

• Hi,

I have a force sensor (not for phones) and I am recording the readings from it. There is a lot of noise and I want to reduce it using low pass filter.

Can anyone guide me if I can use QSensor class or QSensorFilter class for my requirement or is there something else?

Thank you for your time and knowledge.

• The QSensorFilter is not a filter.

Depending on what you are doing you could filter by using a simple average of many samples. If this doesn't work then you could use a weighted average and stream in data:

``````double w2(0.500);
double w1(0.866);
double w0(1.000);

double sum = in_data[last_in] * w0 + in_data[last_in - 1] * w1 + in_data[last_in - 2] * w2;
double result = sum / (w0 + w1 + w2);

// where
// in_data is the raw input data
// last_in is the index of the last input value
// result is the filtered result.
``````

The idea is that you find the average value from a sample of the previously received data. The most recent data is given the highest weight where previous data is given less weight and so on. The number of weighting values depends on how aggressive you want the filter. The more previous data that is used the more aggressive the filter.

There are standards you can follow for the weighting function (if you want to have something that follows a standard). I don't remember the ASME standard for filters off the top of my head but it does describe how to calculate the weighting functions. A good alternative is to use a normal distribution for the weighting function (google Standard Deviation and refer to the graph where w1 = 1 standard deviation, w2 = 2 standard deviations, ...).

There is a Kalman filter that is particularly good at removing heavy amounts of noise...

• @Rondog Thank you for the reply. I will try and test.