eResult team data engineering
ECG digital signal processing (Tpeak-Tend) for Omniaplace big data pipeline

Omniaplace is eResult integrated data management platform. It offer a wide range of application function and is the heart of company solution offering.
In this article I will explain a path to determine an emerging electrocardiographic parameters capable of predicts increased risk of sudden cardiac arrest (Tpeak-Tend).
This algorithm is implemented inside our Omniaplace big data pipeline.
I’m going to start with a little bit of background.
In the image below is represented an healty heartbeat split into the main components:

The P wave represents the depolarization of the atria; the QRS complex, represents the depolarization of the ventricles; and the T wave represents the repolarization of the ventricles.
Tpeak-Tend is defined as the interval in time from the peak to the end of the T wave:

The goal was to realize an algorithm suitable to be executed into our Omniaplace big data pipeline, in particular inside our Spark structured streaming module.
At the time of writing there isn’t any library or other solution available, so I searched the Internet for some building blocks in Python or Matlab.
I was able to find a good and extensible Matlab library capable of determining the T peak:
Below you can find a graphical example of determination of this peak using QRS Multilevel Teager Energy Operator (MTEO):

After that I needed a method to determine T-end instant.
After some other research I ended founding this:
In this article is describe a solution named “the method of small windows” whose meaning is illustrated below:

So I decided to extend BioSigKit applet with the algorithm described above.
Below you can find the core matlab code:
function [R,Q,S,T,P_w,TpTe] = ER_Tpeak_Tend(ecg,fs,gr)
%% ================= Determine Tpeak Tend interval ======= %%%% Initilization%R = zeros(length(ecg),2); % stores the R peak info on lowpassed sig
%Q = zeros(length(ecg),2); % stores the Q peak info on lowpassed sig
%S = zeros(length(ecg),2); % stores the S peak info on lowpassed sig
%T = zeros(length(ecg),2); % stores the T peak info on lowpassed sig
%P_w = zeros(length(ecg),2); % stores the P peak info on lowpassed sigTimeStep = 1/fs;
TpTeMax = 0.25;% launch MTEO_qrst[R,Q,S,T,P_w] = MTEO_qrst(ecg,fs,0);TpTe = zeros(length(T(:, 1)),3); % stores the TpTe interval info on lowpassed sig% loop through T peaks array
for k = 1:length(T(:, 1))
%fprintf('Number at position %d = %6.2f\n', k, T(k,2))
% for each peak verify if signal >0
if (T(k, 2) > 0)
% if signal >0 apply 12SL algorithm
% SLCum = T(k, 2);
SLCum = ecg(T(k, 1));
j = 1;
while (ecg(T(k, 1)+j)/SLCum > 0.02) && (T(k, 1)+j < length(ecg)) && (j * TimeStep < TpTeMax)
SLCum = SLCum + ecg(T(k, 1)+j);
j = j + 1;
end
% battito elaborato
TpTe(k, 1) = T(k, 1);
TpTe(k, 2) = T(k, 1) + j;
TpTe(k, 3) = j * TimeStep;
else
% impossibile elaborare questo battito
TpTe(k, 1) = T(k, 1);
TpTe(k, 2) = 0;
TpTe(k, 3) = 0;
end
endif gr
figure,plot(ecg);
hold on,scatter(R(:,1),R(:,2),'r');
hold on,scatter(Q(:,1),Q(:,2),'g');
hold on,scatter(S(:,1),S(:,2),'k');
hold on,scatter(T(:,1),T(:,2),'m');
hold on,scatter(TpTe(:,1),T(:,3),'y');
endend
And this is the final result (in purple T-peak instant, in green T-end instant):

That’s all, no magic into this.
But the interesting thing here, in my opinion, is the power of Internet, where you can find what you need most of the time. Maybe not exactly what you need, maybe not in the platform you need …
But with a little bit of imagination “and expertise of course” you can find building block that you can glue together, developing just the missing module and getting this way the result you need.
Thank’s for reading.