Low, High and/or Band-Pass Filters

Hi there!

While I was measuring with noisy ECG signals, I need something that take cares of filtering the measured signals.

I came across the following filter library: Arduino-signal-filtering-library
It seems pretty easy to create a filter with this... It sounds really nice, it generates some code, and we need to change the libraries with the generated code? Anyhow... after editing my library files with the generated code I encountered several errors:

such like:

This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.5-r2 (Windows NT (unknown)), Board: "Teensy 3.1"
In file included from newFilter.ino:4:0:
C:\Arduino\libraries\Filter/newFilter.h:12:10: error: ISO C++ forbids declaration of 'filter' with no type [-fpermissive]
newFilter:6: error: cannot declare variable 'Filter' to be of abstract type 'newFilter'
In file included from newFilter.ino:4:0:
C:\Arduino\libraries\Filter/newFilter.h:9:7: note:   because the following virtual functions are pure within 'newFilter':
In file included from C:\Arduino\libraries\Filter/newFilter.h:7:0,
                 from newFilter.ino:4:
C:\Arduino\libraries\Filter/Filter.h:20:17: note: 	virtual int Filter::run(int)
newFilter.ino: In function 'void setup()':
newFilter:14: error: 'class newFilter' has no member named 'begin'
In file included from C:\Arduino\libraries\Filter/newFilter.h:7:0,
                 from newFilter.ino:4:
C:\Arduino\libraries\Filter/Filter.h: In function 'void loop()':
C:\Arduino\libraries\Filter/Filter.h:20:17: error: 'virtual int Filter::run(int)' is private
newFilter:20: error: within this context

Anyone knows what's causing this? Or how to implement the generated code into a new library file? It's not very clear to me what i actually need to change?

At this moment i have edited 'newFilter.h' to this:

// Arduino Signal Filtering Library
// Copyright 2012-2013 Jeroen Doggen (jeroendoggen@gmail.com)

#ifndef newFilter_h
#define newFilter_h
#include <Arduino.h>
#include <Filter.h>

class newFilter : public Filter
{
	public:
		newFilter()
		{
			for(int i=0; i <= 10; i++)
				v[i]=0.0;
		}
	private:
		float v[11];
	public:
		float step(float x) //class II 
		{
			v[0] = v[1];
			v[1] = v[2];
			v[2] = v[3];
			v[3] = v[4];
			v[4] = v[5];
			v[5] = v[6];
			v[6] = v[7];
			v[7] = v[8];
			v[8] = v[9];
			v[9] = v[10];
			v[10] = (2.766929730595e-3 * x)
				 + ( -0.0808708884 * v[0])
				 + (  0.8744889062 * v[1])
				 + ( -4.4332135268 * v[2])
				 + ( 13.8481537992 * v[3])
				 + (-29.4860113999 * v[4])
				 + ( 44.7006874561 * v[5])
				 + (-48.8754142978 * v[6])
				 + ( 38.0698269619 * v[7])
				 + (-20.2086326211 * v[8])
				 + (  6.5906492691 * v[9]);
			return 
				 (v[10] - v[0])
				+5 * (v[2] - v[8])
				+10 * (v[6] - v[4]);
		}
};
#endif

You hosed that link royally.

Why are you deriving from the Filter class? Why are you deriving your library in the Filter library?

Why do you have the sketch and the derived library using the same name?

PaulS:
You hosed that link royally.

Arduino-signal-filtering-library

Why are you deriving from the Filter class? Why are you deriving your library in the Filter library?

Why do you have the sketch and the derived library using the same name?

Well, i was using this code as example from his library, in the example is also used the same names tho?

Chopsticks:
Hi there!
While I was measuring with noisy ECG signals, I need something that take cares of filtering the measured signals.

Do you really need a complex, custom filter, or would a simple low pass do it?

If you have noisy analog data, you can simply accumulate "X" number of samples, then divide the sum by "X" (i.e. simple averaging). This takes out noise, and it's a low pass filter (that is, rapid changes will get averaged out and not seen).

See if something like this will work for you:

// port is the Arduino port number (i.e. "A0")
// avg is the number of samples to average
uint16_t getAnalog (uint8_t port, uint16_t avg)
{
    uint16_t x;
    uint32_t sum;
    sum = 0; // init accumulator
    for (x = 0; x < avg; x++) {
        sum += analogRead (port); // add up "avg" number of samples
    }
    return (sum / x); // return averaged reading
}

Hope this helps.

Do you really need a complex, custom filter, or would a simple low pass do it?

I want to create a filter below 10 Hz and above 40 Hz (band-pass) because in this area are the most interesting signals (heartbeat)

With your example, i dont lose information because of the averaging? And is it possible to set a frequency?