I'm looking for a C# .NET library for digital filtering (lowpass, highpass, notch) to filter ECG waveforms in real-time. Any suggestions?
-
2When you say real time are you referring to a operating system with [hard or soft real time requirements](http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:rtos_concepts) or are you referring to processing the data as it comes in? – Scott Chamberlain Mar 22 '11 at 03:59
-
processing the data as it arrives – patrick Mar 22 '11 at 04:00
-
Will you need to do things like FFT's or are you just looking for the various filters? – Scott Chamberlain Mar 22 '11 at 04:05
-
I'm looking for the most time efficient way to filter data, I'm not sure if an FFT is necessary...thoughts? – patrick Mar 22 '11 at 04:23
-
2Not that efficiency isn't important, but processing a 12-lead ECG at 1kHz doesn't require much efficiency on modern hardware. You could probably process a whole hospital's worth of ECGs on a single machine. – Gabe Mar 22 '11 at 07:08
3 Answers
If this is non commercial use, I have heard good things about the Signal Lab library. It is free for non commercial use, $570 for commercial use. It it a bit overkill if you are just needing low pass, high pass, and band pass filters. but it does come with controls for visualizing the data if you do not have any yet.
If you just need the filters you may just want to write your own code for the 3 filters. You can check the wikipedia pages for psudocode examples of a Low-pass filter and High-pass filter, I did not quickly find a code example of a noch filter.
Here are some C examples of various filters, to help give you a clue on what you need to do.

- 124,994
- 33
- 282
- 431
-
1Those exponential-decay filters have non-linear phase response, which means non-constant delay. You mess with the intervals in an ECG and you will really confuse any cardiologist trying to do interpretation. – Ben Voigt Mar 22 '11 at 14:58
-
Don't forget us paramedics too. Zero phase filtering would be lovely, at 0.5 or 0.67Hz for the high-pass. Most baseline wander would be removed and we'd get a nice preservation of the ST segments and QT intervals. – user7116 Jan 17 '13 at 18:52
If your data is arriving in discrete chunks, I would use Reactive Extensions. This allows the input to control what happens next (reacting to data) instead of using "pull" operations. You can then react to this data by passing it through filters, and then react to that data by displaying it or performing additional calculations.
If you only need notch, high, and low filters, these are trivial to write. As each chunk of data arrives, you can decide whether or not to pass it to the next step (or whether or not to modify the data first). I would imagine you could write this whole section of code in less than 20 lines (maybe less than 10) using Rx. It would result in some pretty elegant code for this use case.

- 11,194
- 5
- 43
- 56
-
Efficient filtering code isn't THAT trivial (maybe 20-30 lines), and that doesn't address the problem of how you design the filters in the first place. – Ben Voigt Mar 22 '11 at 12:59
-
It depends on the algorithm you need. I have a very simple application that simply needs to accept or reject data based on allowed ranges (a non-attenuating high/low/band pass filter), and it winds up being a few lines of code, just simply accept/reject logic. If the specific filter you need can work on discrete chunks, the best solution is to just write it yourself. If it needs to work on the waveform itself, then more advanced signal processing would be needed. Just throwing my own solution out there in case it fits his use case. – drharris Mar 22 '11 at 13:06
-
It sounds like you're talking about a simple threshold test. That's not what is meant by "filter" in a DSP context. – Ben Voigt Mar 22 '11 at 13:11
-
Agreed, which is why I specified "if it fits his use case". He didn't specifically mention DSP, so I didn't assume it. But, you can build from there if you need only slightly more advanced algorithms. A first-order Butterworth filter only takes maybe 2 lines of code and knowledge of only the previous chunk of data. So, my solution is a good building point if (a) the data arrives in discrete chunks, (b) the filters required are simplistic, and (c) you don't need knowledge of the entire waveform. – drharris Mar 22 '11 at 13:16
As far as I know you can write your own, because I did.
This should be a good starter for you (coded in C++ but you can easily covert the syntax to C#) - http://www.codeproject.com/KB/cpp/ecg_dsp.aspx
Third party libraries wouldn't be very flexible on the filter equation parameters. As you only will know the characteristics of your signal (amplitudes, frequency band and sampling etc.)
I recommend using a waveshaping algorithm first to get a smooth signal on the C# side before you apply filters, if your ECG sampling rate is low.

- 87,323
- 22
- 191
- 272

- 1
- 1