ysmnyol
Posts: 36
Joined: Thu Jan 24, 2019 9:19 pm

Real time ECG filtering

Thu Apr 11, 2019 1:27 pm

Hello everybody. I am dealing with raspi3B+ and python 2.7.

I am using AD8232 heart rate sensor and MCP3008 analog-digital converter.

I am plotting the sensor data with matplotlib lib but it is too noisy.

I have to filter to ECG data but I did not know how to I apply.

Can I do filter real-time or I have to save the data into the txt file and then apply filtering,after filtering plotting data into the new txt file?

I did not save the data into the txt or csv file. How can I filter?

User avatar
MrYsLab
Posts: 449
Joined: Mon Dec 15, 2014 7:14 pm
Location: Noo Joysey, USA

Re: Real time ECG filtering

Thu Apr 11, 2019 2:09 pm

Here is a link that might give you some ideas on how to smooth out your data within your code:
https://stackoverflow.com/questions/304 ... matplotlib

ghp
Posts: 2492
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: Real time ECG filtering

Thu Apr 11, 2019 8:38 pm

Hello,
asking google for ecg filtering brings up more than 3 million entries. I did not read everything, but basically you will need a band pass filter (low pass and high pass filter combined) for an effective band of prox 0.05Hz to 150Hz. It could be a good idea to add an analog low pass filter between the analog input and ADC to reduce higher frequency noise before the ADC. An analog second order low pass filter with low noise and low PMRR at prox 150Hz edge is quite easy to implement. And to add filters against radio wave inputs before the acquisition chip.

For 150 Hz, you need to sample at min 300Hz. A digital filter can be executed in the data processing pipeline. Look for FIR-filters, there is lot of literature around. FIR filter consist of a pile of stages the signal is send through, so a continuous feed of data is quite good. These are simple to implement and to test. Important is a constant sample rate, up to 1kHz is almost no problem for a linux system on a pi.
Depending on your environment, add comb filters for 50Hz, 60Hz and multiples of this. As these sit in the middle of the interesting bandwidth, more effort might be needed.

Heater
Posts: 19103
Joined: Tue Jul 17, 2012 3:02 pm

Re: Real time ECG filtering

Fri Apr 12, 2019 1:46 pm

What kind of circuit do you have around your AD8232?

According to the data sheet it has all the means to do high and low pass filtering before ever outputting anything to an ADC. The data sheet includes reference schematics as to how to do this:
https://www.analog.com/media/en/technic ... AD8232.pdf

It is preferable to do such filtering as close to the sensor input as possible. Certainly don't leave it up to software to do it.

What do you mean by noisy?

Where is that noise coming from? It's always better to try an eliminate source of noise rather than rely on filtering them out later.
Memory in C++ is a leaky abstraction .

Return to “Python”