1
$\begingroup$

I have read in a couple of papers that the noise from an ECG signal can be removed via median filter. One such example I found was on stackoverflow, where multiple methods were suggested and one of them being the median filter. The following image is taken from the post on stackoverflow. enter image description here

The main idea of the median filter is to run through the signal entry by entry, replacing each entry with the median of neighboring entries. The pattern of neighbors is called the "window", which slides, entry by entry, over the entire signal.

What I do not understand is, why doesn't the QRS complex get removed as well? When I tried it using matlab, the bigger I set the window, the better the signal got filtered, should't it be the opposite?

$\endgroup$
  • $\begingroup$ There is a optimum size for the window, if you set the window size very large (about 500) certainly you will get bad results. $\endgroup$ – Mohammad M Aug 19 '17 at 8:06
  • $\begingroup$ The pattern of neighbors is not called window. Window is the same as a neighborhood. $\endgroup$ – Mohammad M Aug 19 '17 at 8:14
2
$\begingroup$

You are certainly doing something very wrong. You should upload your data in order to get better responses. You can upload your data into any upload sites you wish and provide its link here, practically.

Median filter is a highly highly nonlinear filter (it re-orders the sample positions!). The output of the median filter at a position $n$ is the median of the values that reside in the window scope; i.e., it's the value that resides in the middle when the samples are sorted in order. Hence median filtering requires sorting for each computation. This makes it quite slow as well (a deailed answer actually depends on the architecture...)

Median filter is mainly used for speckle or salt and pepper noise removal, in essence these are local noise samples whose frequency domain filtering is not possible without degrading the whole signal. Such local (in time) peaks will have wide band frequency spectrums which inhibit frequency domain attacks to remove them, therefore, leaving only the time domain (or time-frequency domain) approaches possible.

Median filter has a tendency to preserve edges, therefore quite preferred in certain image enhancement operations. However it also has the side effect of washed out results (texture details are lost and only strong edges remain) which indicates that their use should be performed with care.

In principle, the longer the window size, the stronger will be the washed out effect. So it's customary to use as short as possible window sizes (unless otherwise dictated by the particular application)

Coming to your example plot. Using a window size larger than 50 samples will wash out local details that might be important to you, so you should use a window size less than 50, I guess (based on the plot you provided).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.