Which filter to use to remove baseline wander on ECG

I have ECG values recorded for two minutes from an ECG sensor with an Arduino board with a sample rate of 60S/s. Those are in form of a value with a time stamp. I changed them to mili-voltage. Now I have a lot of baseline wander and it is not linear so I am not sure how to remove it?I have used butter filter of order 2 and does remove some of the noise but does not help at all with baseline. Any help will be appreciated.

 Risposta accettata

Your signal is unfortunately sampled at a relatively low rate, so signal processing is difficult. Your signal also has harmonics of what appear to be a 1.5 Hz signal that are propagated through the entire signal. This noise may give the appearance of baseline wander that actually does not exist, since it is simply the summation of these harmonics. Those are essentially impossible to eliminate without also eliminating parts of your signal.
This analysis and filter appear to work acceptably well:
F = openfig('Normal ECG Signal2.fig');
f = gca;
EKG = findobj(f, 'Type','line');
t = EKG.XData; % Recover Data
s = EKG.YData;
L = numel(t); % Signal Length
Ts = mean(diff(t));
St = std(diff(t)); % Test For Uniform Sampling
tr = linspace(min(t), max(t), L); % New, Regularly-Sampled Time Vector
Tsr = mean(diff(tr)) * 1E-3; % Convert To Seconds
sr = resample(s, tr); % Resample To Regularly-Sampled Signal
Fsr = 1/Tsr; % Sampling Frequency (Hz)
Fnr = Fsr/2;
figure
plot(tr, sr)
grid
FTsr = fft(sr-mean(sr))/L; % Fourier Transform Of Mean-Corrected Signal
Fv = linspace(0, 1, fix(L/2)+1)*Fnr;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTsr(Iv))*2)
grid
Fs = Fsr; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Ws = 0.5/Fn; % Passband Frequency Vector (Normalised)
Wp = 1.5/Fn; % Stopband Frequency Vector (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Attenuation (dB)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp,'high'); % Default Here Is A Lowpass Filter
[sos,g] = zp2sos(z,p,k); % Use Second-Order-Section Implementation For Stability
sr_filtered = filtfilt(sos,g,sr); % Filter Signal (Here: ‘sr’)
figure
freqz(sos, 2^14, Fs) % Bode Plot Of Filter
set(subplot(2,1,1), 'XLim',[0 Fn]) % Optional, Change Limits As Necessary
set(subplot(2,1,2), 'XLim',[0 Fn]) % Optional, Change Limits As Necessary
figure
plot(tr, sr_filtered)
grid
I use an elliptical filter here rather than a Butterworth filter because it is shorter and therefore computationally more efficient. It also gives the filter characteristics I want.

6 Commenti

Thank you for your quick answer. In your opinion can this signal be used for analysis or should I retake the signal with increased sample rate? And what can be done to remove or avoid these harmonics in future readings as they appear in every readings I have taken till now.
As always, my pleasure.
I am not familiar with the Arduino hardware, so I do not know what it uses. Higher sample rates are always better, and sample rates of at least 250 Hz (and at best 1000 Hz) are best for EKG data acquisition. Ideally, you need to implement a Bessel analog anti-aliasing lowpass filter in hardware to avoid such problems. Apply it to the analog signal before you sample (digitise) it. The cutoff frequency of the anti-aliasing is one-half of your sampling frequency.
I would use the data you have, because I believe valid data (and this appears to be such) are best not discarded. I would also suggest that (as I mentioned here) you increase the sampling frequency and add an anti-aliasing filter. I do not know your experimental set-up, however you also must be sure to use a reference electrode (usually and inaccurately called a ‘ground’ electrode) to subtract out line-frequency noise and other noise sources from your signal. Webster and other reputable references on biomedical instrumentation discuss this.
If you want to, you can use the resample (link) function to have a uniform sampling frequency for all your signals in order to make subsequent analysis easier. Using it with this study will not otherwise change your data.
Hi ,I used the code you provided to filter further signals which did not apparently had harmonics but it is giving me these weird ripples in the start of the plot.Later on it is clearly filtered the signals nicely. Can you have a look into it?
I have no idea. I would experiment, making ‘Wp’ slightly larger, perhaps 2.0.
The two EKGs you attached do not look like the same signals, before and after filtering. They have different lengths, and may have different sampling frequencies or other parameters.
My code is designed to filter the data you originally posted. If you have different data, you may need to change the filter parameters to accommodate it.
I might have added two different before and after. Here is the updated one and yes after I updated wp a bit higher it got better. Thank you
Hi just an update . The ripples that was in the signals later by applying the filter are most probably ringing effect or gibbs phenomena. Any thoughts will be welcomed

Accedi per commentare.

Più risposte (0)

Richiesto:

FSB
il 18 Set 2018

Commentato:

FSB
il 13 Nov 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by