How to add baseline drift to an ECG signal

25 views (last 30 days)
I am at the beginning of the study of ECG signal processing and I am at the start of learning MATLAB. I cannot tell if I am doing the correct operations.
the image presented above presents the operations to be performed to add the baseline drift to the starting signal.
I don't know if it is wrong or not. But when I plot the signal with the addition of the baseline drift, it seems almost unchanged.
To perform these operations I used the signal found in this database (name of the file: 100m.mat)
(to download the file in the .mat version follow the link: https://archive.physionet.org/cgi-bin/atm/ATM to download the .mat version file follow the link: https://archive.physionet.org/cgi-bin/atm/ATM and select the database called "MIT-BIH Arrhythmia Database (mitdb) and select 100 as Record, than Toolbox and selcet export as .mat")
The one below is the code I wrote:
%% Original ECG Signal
load('100m.mat');
original_signal = val(1,:);
fs = 360; % Hz
% T = 1/fs;
L = length(original_signal);
t = (0 : L - 1)/fs;
plot(t, original_signal);
title('plot of the original ECG signal');
xlabel ('time [sec]');
ylabel ('ECG Amplitute [mV]');
grid on
%% Add Noise to the ECG signal
Noise = awgn(original_signal, 20, 'measured');
plot(t, Noise, 'b');
grid on
xlabel('time [sec]');
ylabel('ECG Amplitute [mV]');
title('ECG signal with added noise');
%% Add Baseline drift to ECG signal
x = linspace(0,2*pi,L);
A = 0.8;
N = 60;
BaselineDrift = A*cos(x./N);
subplot(2,1,1)
plot(t, Noise); % Noise is the original signal with noise add to it
xlabel('time [sec]');
ylabel('ECG Amplitute [mV]');
title("Noisy ECG Signal");
subplot(2,1,2)
Dirty_Signal = Noise + BaselineDrift;
plot(t, Dirty_Signal)
xlabel('time [sec]');
ylabel('ECG Amplitute [mV]');
title("Corrupted ECG Signal (Noise + Baseline Drift)");
Thanks in advance for the help

Accepted Answer

Image Analyst
Image Analyst on 19 Feb 2022
That's not all the code. Where do you define L, t, and Noise?
Try
minDriftOffset = 0; % Whatever
maxDriftOffset = 10; % Whatever.
BaselineDrift = linspace(minDriftOffset, maxDriftOffset, length(Noise));
Dirty_Signal = Noise + BaselineDrift;
  5 Comments
Sabaudian
Sabaudian on 19 Feb 2022
I try it and it works thank. I hope it is consistent with what is presented in the document I plot above.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!