153 views (last 30 days)

I am using the AD8232 and the Arduino pro mini 328-3V. I want to remove the motion artifacts from my signal. I am using matlab for the signal processing and this code for the serial communication with arduino. How can I do the motion artifacts removal?

clc

close all

clear all

if ~isempty(instrfind)

fclose(instrfind);

delete(instrfind);

end

%close all

clc

disp('Serial Port Closed')

s = serial('COM5','BaudRate',9600);

fopen(s);

fprintf(s,'*IDN?');

i = 1;

while true

x(i) = str2double(fscanf(s));

i = i + 1;

plot(x)

pause(0.1)

end

Star Strider
on 4 Sep 2019

1)So I can't use a digital filter for processing the real time signal continuously?

I’m not aware of any MATLAB ability to do real-time digital filtering. The Audio Toolbox may have this ability, however I don’t have it so I have no experience with it.

2)I probably can save let's say 5 minutes of the signal and then filter it with a digital filter?

That’s certainly an option. The highpass and bandpass functions (R2018a and later) make the filter design much easier. (Return the second argument as the designeed filter, then use it with your signals with the filtfilt function to filter other signals.) If you don’t have those functions, it is easy to design an efficient ellliptic filter to do what you want.

For example:

Fs = 1000; % Sampling Frequency

Fn = Fs/2; % Nyquist Frequency

Wp = [859 862]/Fn; % Passband Normalised

Ws = [855 865]/Fn; % Stopband Normalised

Rp = 1; % Passband Ripple (Irrelevant in Butterworth)

Rs = 50; % Stopband Attenuation

[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Order Calculation

[z,p,k] = ellip(n,Rp,Rs,Wp); % Zero-Pole-Gain

[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability

figure

freqz(sos, 2^16, Fs) % Filter Bode Plot

s_filt = filtfilt(sos, g, s); % Filter Signal

This designs a bandpass filter with passband frequencies of 859 to 862 Hz, and uses it fo filter signal vector ‘s’. For EKG signal processing, the passband would be 1 Hz to 100 Hz, with the stopbands of 0.5 Hz and 105 Hz.

Sign in to comment.

Anna Karima
on 21 Sep 2019

Star Strider
on 19 Jan 2020

For the data you describe:

Fs = 1000;

Ts = 1/Fs;

RR_Interval = diff([117 141])*Ts

HR = 1/RR_Interval

the R-R interval is 0.024 seconds, or 0.0004 minutes, producing a heart rate of 2500 BPM. Something is wrong.

I went back and looked at ‘ecg1.mat’ and got similarly strange numbers:

D = load('ecg1.mat');

Fs = D.Fs;

Ts = 1/Fs;

EKG = D.x;

t = D.t*Ts;

figure

plot(t*Ts, EKG)

grid

[pks,locs] = findpeaks(EKG, 'MinPeakHeight',2.25)

RR_Interval = mean(diff(locs)) % Mean R-R Interval (samples)

RR_Interval_s = RR_Interval*Ts % Mean R-R Interval (sec)

RR_Interval_m = RR_Interval_s/60 % Mean R-R Interval(min)

HR = 1/RR_Interval_m % Heart Rate (BPM)

Looking at that trace, it has about 8 beats/second, which would be about 480 beats/minute. Something is wrong somewhere, and it may be the reported sampling frequency.

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/478819-remove-baseline-wander-from-ecg#comment_742066

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/478819-remove-baseline-wander-from-ecg#comment_742066

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/478819-remove-baseline-wander-from-ecg#comment_742173

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/478819-remove-baseline-wander-from-ecg#comment_742173

Sign in to comment.