\documentclass[conference]{IEEEtran}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{cite}
\usepackage{url}
\usepackage{amssymb}
\usepackage{xcolor} % needed for \textcolor

% ==== IEEE-required preprint notice in footer ====
\usepackage{fancyhdr}
\fancypagestyle{firstpage}{
  \fancyhf{} % clear header and footer
  \fancyfoot[C]{\small \textit{This work has been submitted to the IEEE for possible publication. 
  Copyright may be transferred without notice, after which this version may no longer be accessible.}}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}

\begin{document}
\title{An AI-Driven Deep Learning Hybrid CNN--LSTM and LSTM--RNN--FC--SMP AI-Agents' Architecture for High-Precision ECG PQRST Detection and Classification in IoMT-Based Healthcare Systems \\ \large \textit{Preprint submitted to IEEE ASIANComNet 2025}}

\author{\IEEEauthorblockN{Lakis Christodoulou\IEEEauthorrefmark{1}, 
Andreas Chari\IEEEauthorrefmark{1}, 
Iacovos Ioannou\IEEEauthorrefmark{2}, 
and Michael Georgiades\IEEEauthorrefmark{3}}
\IEEEauthorblockA{\IEEEauthorrefmark{1}R\&D -- Technologies and Innovation Department, BIOMED Medical Systems,\\
Emails: lakis.christodoulou@gmail.com, andreaschari88@gmail.com}
\IEEEauthorblockA{\IEEEauthorrefmark{2}Department of Computer Science, European University Cyprus,\\
Email: ia.ioannou@euc.ac.cy}
\IEEEauthorblockA{\IEEEauthorrefmark{3}Department of Computer Science, Neapolis University Cyprus,\\
Email: m.georgiades@nup.ac.cy}}


\maketitle
\thispagestyle{firstpage}

\begin{abstract}
This research addresses the integration of Artificial Intelligence (AI) into electrocardiogram (ECG) signal processing to improve detection and classification of cardiac anomalies. \textcolor{black}{We present an AI-driven ECG analysis framework that employs reinforcement learning (RL) together with a hybrid CNN--LSTM architecture to enhance PQRST complex detection and arrhythmia classification. AI agents autonomously detect and label ECG features using RL for adaptive peak detection, while the CNN--LSTM model performs arrhythmia classification.} Using the MIT-BIH Arrhythmia Database, the system achieved 99.58\% PQRST detection accuracy, 99.85\% classification accuracy, and 99.85\% anomaly detection precision. A CNN extracts key ECG features, an LSTM models temporal dependencies, and \textcolor{black}{a Softmax prediction module (SMP)} produces the final classification. The proposed AI model advances real-time cardiovascular monitoring and IoT-based diagnostics, offering a highly accurate, automated solution for early cardiac disease detection.
\end{abstract}

\begin{IEEEkeywords}
Artificial Intelligence (AI), Reinforcement Learning (RL), Convolutional Neural Network (CNN), LSTM, ECG signal processing, PQRST detection, arrhythmia classification, Internet of Things (IoT), Healthcare.
\end{IEEEkeywords}


\section{Introduction}

The integration of Artificial Intelligence (AI) into healthcare has transformed electrocardiogram (ECG) signal interpretation, particularly in the detection and classification of PQRST complexes. Intelligent ECG analysis systems now enable real-time monitoring and diagnostic support, significantly improving cardiovascular disease detection and prevention. Christodoulou \emph{et al.}~\cite{Christodoulou2024,georgiades2025federated} developed a series of AI-enhanced Healthcare IoT frameworks for real-time cardiovascular monitoring, extending from advanced machine learning--based PQRST detection and classification to federated learning models for cross-silo IoMT environments, thereby improving both diagnostic precision and data privacy. Likewise, Ramya \emph{et al.}~\cite{ramya2025automated} proposed an automated ECG classification system using a deep learning framework that integrates optimized hyperparameter selection and convolutional architectures, achieving high performance on benchmark datasets.

Reinforcement Learning (RL) has recently emerged as a promising paradigm for dynamic ECG analysis due to its self-adaptive and feedback-driven optimization properties. Bhardwaj \emph{et al.}~\cite{bhardwaj2024adaptive} introduced an adaptive neural network with reinforcement learning for real-time ECG diagnosis, demonstrating high diagnostic accuracy even in dynamic clinical environments. Similarly, Aabdalla and Vasumathi~\cite{aabdalla2025novel} proposed a hybrid deep learning and reinforcement learning approach for multimodal cardiovascular disease prediction, showing improved robustness through the fusion of heterogeneous data modalities. In parallel, hybrid architectures such as CNN--transformer models~\cite{kim2025novel} and wavelet--based RCNN classifiers~\cite{singh2023wavelet} have achieved superior arrhythmia detection accuracy by capturing both spatial and temporal dependencies within ECG waveforms. Complementary studies, including Singh \emph{et al.}~\cite{singh2019arrhythmia}, performed a comparative analysis of traditional machine learning methods on the MIT-BIH ECG dataset, underscoring its enduring value for algorithm benchmarking and reproducibility.

These advancements establish the foundation for the present study, which develops an adaptive ECG analysis framework combining reinforcement learning--based dynamic PQRST detection with a hybrid Convolutional Neural Network--Long Short-Term Memory (CNN--LSTM) classifier. The proposed system is evaluated using the MIT-BIH Arrhythmia Database~\cite{Goldberger2000}, demonstrating enhanced interpretability and accuracy in ECG pattern recognition under varying physiological and noise conditions.

\section{Literature Review}

Accurate identification of electrocardiogram (ECG) waveform components such as the P wave, QRS complex, and T wave is fundamental for diagnosing arrhythmias and assessing overall cardiac health. A representative annotated ECG waveform based on established clinical and computational standards~\cite{Pan1985,Goldberger2000,AAMI1999} is presented in Fig.~\ref{fig:pqrst_overview}. The illustration outlines the principal morphological elements and electrophysiological intervals that define a complete cardiac cycle, including the PR segment, ST segment, QRS wave complex, PR interval, and QT interval, each corresponding to distinct phases of atrial depolarization, ventricular depolarization, and ventricular repolarization.

Foundational studies have quantitatively characterized these features. The real-time QRS detection algorithm developed by Pan and Tompkins~\cite{Pan1985} established key temporal relationships among ECG peaks, with the Q peak typically occurring approximately 40~ms before the R peak and the S peak about 40~ms after, producing QRS durations between 80 and 120~ms. Goldberger \emph{et al.}~\cite{Goldberger2000} further defined physiological baselines for P and T wave intervals, providing reference ranges for normal cardiac conduction. Complementing these works, the ANSI/AAMI~EC38~\cite{AAMI1999} standard codified the clinical definitions and timing tolerances for ECG waveform morphology, forming the foundation for subsequent algorithmic and machine learning–based ECG interpretation.

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig0.png}
  \caption{Annotated ECG waveform illustrating key morphological components of the cardiac cycle, adapted from established clinical and computational standards~\cite{Pan1985,Goldberger2000,AAMI1999}. The diagram highlights the P wave, QRS wave complex, and T wave, as well as diagnostically significant segments and intervals (PR segment, ST segment, PR interval, and QT interval) corresponding to atrial depolarization, ventricular depolarization, and ventricular repolarization.}
  \label{fig:pqrst_overview}
\end{figure}

With the rise of deep learning, automated ECG classification has advanced dramatically. Ramya \emph{et al.}~\cite{ramya2025automated} developed a deep learning framework that automates hyperparameter optimization and feature extraction, achieving robust classification across multiple arrhythmia types. Kim \emph{et al.}~\cite{kim2025novel} introduced a CNN--transformer hybrid leveraging the Stockwell transform to perform arrhythmia detection without explicit R-peak identification, demonstrating improved time--frequency feature capture. Complementary to this, Singh \emph{et al.}~\cite{singh2023wavelet} employed wavelet--based feature extraction combined with a region-based convolutional neural network (RCNN) to isolate localized frequency signatures and improve PQRST delineation. A prior comparative analysis by Singh \emph{et al.}~\cite{singh2019arrhythmia} validated the efficiency of traditional classifiers such as support vector machines and decision trees using MIT-BIH ECG data, forming a baseline for evaluating modern deep models.

While deep learning approaches have achieved notable success, they often suffer from overfitting, high computational cost, and limited adaptability to new patients or data sources. Reinforcement learning (RL) techniques have recently been proposed to address these shortcomings by dynamically refining decision policies based on feedback from model performance. Bhardwaj \emph{et al.}~\cite{bhardwaj2024adaptive} demonstrated that reinforcement learning can enhance real-time ECG diagnostics through continuous weight updates and self-improving inference under streaming conditions. Similarly, Aabdalla and Vasumathi~\cite{aabdalla2025novel} designed a hybrid RL--DL architecture capable of integrating multimodal cardiovascular data, thereby improving diagnostic consistency and patient-specific adaptability. These works illustrate a paradigm shift toward more autonomous, reinforcement-driven ECG analysis systems that combine adaptability, precision, and generalization.

Building upon these developments, the present research integrates reinforcement learning for adaptive ECG peak detection with a CNN--LSTM architecture for temporal pattern recognition, validated using the MIT-BIH Arrhythmia Database~\cite{Goldberger2000}. This combined approach bridges the gap between traditional signal processing and intelligent self-learning models, supporting scalable deployment in clinical and IoT-based cardiac monitoring environments.


\section{Data Provision and Research Utilization}

\subsection{Database and ECG Signal Data}

The MIT-BIH Arrhythmia Database~\cite{Goldberger2000} was used as the primary benchmark dataset for this study. It comprises 48 half-hour two-channel ECG recordings obtained from 47 subjects, sampled at 360~Hz, and manually annotated by clinical experts for various arrhythmia types. The dataset is publicly available through the PhysioNet repository~\cite{Goldberger2000}, which provides standardized access to annotated physiological signals.

Data extraction and preprocessing were performed using Python with the WFDB package. The following steps summarize the signal preparation workflow:

\begin{itemize}
    \item \textbf{Fetching ECG Signals:} Raw ECG signals and annotations were retrieved directly using the WFDB API.
    \item \textbf{Preprocessing and Noise Reduction:} A bandpass filter (0.5--50~Hz) was applied to remove baseline wander and high-frequency noise.
    \item \textbf{Baseline Correction:} A moving average filter was used to eliminate slow-varying trends in the signal.
    \item \textbf{Normalization:} Each ECG segment was standardized to zero mean and unit variance to improve training stability and comparability across subjects.
\end{itemize}

The dataset was split into training (80\%) and testing (20\%) sets. We ensured a mix of normal and arrhythmic segments in each split. The processed data were used by our AI agents (see below) for peak detection and classification.

\section{System Algorithm Methodology and Research-Development Analysis}

Figure~\ref{fig:pipeline} illustrates the modular AI-agent architecture designed for ECG signal processing. 
The proposed system is composed of four main modules: pre-processing, feature extraction, reinforcement learning, and classification.

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig1.png}
  \caption{AI agent-based ECG data processing pipeline for PQRST detection and arrhythmia classification.}
  \label{fig:pipeline}
\end{figure}

\subsection{Pre-processing AI Agent}
The pre-processing AI agent performs initial conditioning of the raw ECG signal to remove noise, correct baseline drift, and normalize amplitude. 
As shown in Fig.~\ref{fig:preproc}, it executes denoising, baseline correction, and normalization prior to feature extraction.

\subsubsection{Sampling Representation}
In real-world applications, ECG signals are discrete-time sequences sampled at a specific frequency \( f_s \). 
Instead of using the continuous-time signal \( x(t) \), the ECG signal is represented as a discrete sequence:
\begin{equation}
x[n] = x(nT_s), \quad n \in \mathbb{Z}
\end{equation}
where \( T_s = \frac{1}{f_s} \) is the sampling period and \( x[n] \) denotes the sampled ECG signal at discrete time index \( n \).

\subsubsection{Bandpass Filtering (0.5--50~Hz) in Discrete Time}
A Butterworth bandpass filter is used to suppress noise and retain the relevant frequency components of the ECG signal. 
The discrete-time transfer function of an \(m^{\text{th}}\)-order Butterworth filter is defined as:
\begin{equation}
H(z) = \frac{\sum_{k=0}^{m} b_k z^{-k}}{1 + \sum_{k=1}^{m} a_k z^{-k}}
\end{equation}
Applying this filter to the noisy ECG signal yields:
\begin{equation}
y[n] = \sum_{k=0}^{m} b_k\,x[n-k] - \sum_{k=1}^{m} a_k\,y[n-k]
\end{equation}
where:
\begin{itemize}
    \item \( b_k \) and \( a_k \) are the filter coefficients, and
    \item \( y[n] \) is the filtered ECG signal.
\end{itemize}

A 4th-order, m=4, Butterworth filter (0.5--50~Hz) is typically used in ECG pre-processing, with coefficients obtained using a bilinear transform from the continuous to the discrete domain.

\subsubsection{Baseline Wander Removal using Moving Average Filter}
Baseline drift is a low-frequency component that affects ECG signal quality. 
It can be mitigated using a moving average filter, defined as:
\begin{equation}
x_b[n] = \frac{1}{N} \sum_{k=0}^{N-1} x[n-k]
\end{equation}
where \( N \) is the window size, typically between 50 and 100 samples, depending on the sampling frequency \( f_s \). 
In this study, we used \( f_s = 360~\text{Hz} \), consistent with the MIT-BIH sampling rate.

The corrected ECG signal is then expressed as:
\begin{equation}
x_c[n] = x[n] - x_b[n]
\end{equation}
which effectively removes slow-varying baseline trends from the ECG signal.

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig2.png}
  \caption{Pre-processing AI-Agent for ECG signal denoising, baseline correction, and normalization.}
  \label{fig:preproc}
\end{figure}

\subsubsection{ECG Signal Data Normalization}
Normalization ensures that the ECG signal remains within a fixed range, 
enhancing detection accuracy and classification performance. The normalization is defined as:
\begin{equation}
x_n[n] = \frac{x_c[n] - \mu_x}{\sigma_x}
\end{equation}
\noindent
where:
\begin{equation}
\mu_x = \frac{1}{M} \sum_{n=0}^{M-1} x_c[n]
\end{equation}
\begin{equation}
\sigma_x = \sqrt{\frac{1}{M} \sum_{n=0}^{M-1} \left( x_c[n] - \mu_x \right)^2}
\end{equation}

Here, \( \mu_x \) and \( \sigma_x \) represent the mean and standard deviation of the ECG signal, respectively.  
This normalization ensures:
$x_n[n] \in [-1, 1]$,
which standardizes the ECG signal for reinforcement learning and further AI-based analysis.

\subsection{ECG Feature Extraction based on AI-Agent for PQRST Complex Detection}
This module detects the P, Q, R, S, and T peaks adaptively using a reinforcement learning-inspired search mechanism. 
The complete process for identifying these characteristic ECG peaks is illustrated in Fig.~\ref{fig:features}.

\subsubsection{R-Peak Detection -- Pan--Tompkins Algorithm}
The R-peak is detected using the first derivative and squaring function:
\begin{equation}
y(n) = \left( \frac{d x_n(n)}{d n} \right)^2
\end{equation}
A moving window integration of width \(N\) (dependent on the sampling frequency) is subsequently applied to smooth the signal, such as:
\begin{equation}
z(n) = \frac{1}{N} \sum_{i=0}^{N-1} y(n - i)
\end{equation}
R-peaks are then identified using two adaptive thresholds, following the approach of Lakis Christodoulou \emph{et al.}~\cite{Christodoulou2024,georgiades2025federated}.

\subsubsection{Detection of Q, S, P, and T Peaks}
After R-peak identification, additional peaks are located within predefined temporal windows relative to \(R\):
\begin{itemize}
    \item Q peak: 30--50~ms before R (e.g., Q = R--40~ms),
    \item S peak: 30--50~ms after R (e.g., S = R+40~ms),
    \item P wave: 120--160~ms before R (e.g., P = R--150~ms),
    \item T wave: 180--300~ms after R (e.g., T = R+200~ms).
\end{itemize}
Local extrema within these intervals determine the respective peak positions. 
Table~\ref{tab:peaks} summarizes typical physiological timing ranges derived from established literature.

\begin{table}[htbp]
\centering
\caption{Typical PQRST peak timing relative to the R peak (adapted from \cite{Pan1985, Goldberger2000, AAMI1999}).}
\label{tab:peaks}
\resizebox{\columnwidth}{!}{
\begin{tabular}{lccccc}
\toprule
\textbf{Study} & \textbf{Q (ms)} & \textbf{S (ms)} & \textbf{P (ms)} & \textbf{T (ms)} & \textbf{Other Metrics} \\
\midrule
Pan \& Tompkins (1985) & R--40 & R+40 & R--150 & R+200 & QRS: 80--120 \\
Goldberger \emph{et al.} (2000) & R--40 & R+40 & R--140--160 & R+180--250 & PR: 120--200; QT: 350--450 \\
ANSI/AAMI EC38 (1999) & R--30--50 & R+30--50 & R--120--160 & R+180--300 & -- \\
\bottomrule
\end{tabular}}
\end{table}

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig3.png}
  \caption{Feature Extraction AI-Agent identifying P, Q, R, S, and T peaks from the preprocessed ECG signal.}
  \label{fig:features}
\end{figure}

\subsection{Reinforcement Learning (RL) AI-Agent}
The reinforcement learning (RL) agent learns optimal detection policies through a reward-based mechanism. 
This model is a reward-driven approach designed to adapt PQRST peak detection thresholds based on feedback from a reward system. 
In this study, the RL agent was trained to detect and label ECG peaks using a Markov Decision Process (MDP) framework.

\subsubsection{Markov Decision Process (MDP) Formulation}
The RL agent dynamically identifies ECG features by maximizing a reward function corresponding to correct and incorrect peak detections.  
An MDP is formally defined by the tuple \((S, A, R, P)\), where:
\begin{itemize}
    \item \textbf{State} \( S_n \): Extracted ECG features at discrete time \( n \), representing the ECG segment surrounding a detected peak.
    \item \textbf{Action} \( A_n \): Possible operations such as adjusting detection thresholds and labeling the detected candidate as P, Q, R, S, or T.
    \item \textbf{Reward} \( R_n \): Scalar feedback based on detection accuracy, defined as:
\end{itemize}
\begin{equation}
R(S_n, A_n) =
\begin{cases}
+1, & \text{if correctly \textcolor{black}{detected}}, \\
-1, & \text{if incorrectly \textcolor{black}{detected}.}
\end{cases}
\end{equation}

\subsubsection{Q-Learning Algorithm}
The training process employs the Q-learning algorithm, a model-free reinforcement learning technique that iteratively updates the agent’s policy to maximize long-term reward.  
The Q-value update rule is defined as:

\begin{equation}
\begin{aligned}
Q(S_n, A_n) \leftarrow Q(S_n, A_n) + \alpha \bigl[ R_n + \gamma 
\max_{A'} Q(S_{n+1}, A') \\
-\, Q(S_n, A_n) \bigr]
\end{aligned}
\end{equation}
where:
\begin{itemize}
    \item \( \alpha \) is the learning rate,
    \item \( \gamma \) is the discount factor, and
    \item \( R_n \) is the reward associated with action \( A_n \).
\end{itemize}

Through repeated application of this rule, the RL agent autonomously adapts its decision thresholds and action-selection strategy, 
thereby improving PQRST detection performance under noisy and non-stationary ECG conditions.


\section{AI-Agent for PQRST \textcolor{black}{CNN--LSTM} Classification}

\subsection{Deep Learning CNN-LSTM Model for PQRST Classification}
To classify ECG segments into arrhythmia categories, a hybrid CNN--LSTM architecture is employed. 
The CNN extracts spatial (morphological) features from ECG signals, while the LSTM captures temporal dependencies across successive heartbeats. 
The integration of these modules with the reinforcement learning component is summarized in Fig.~\ref{fig:cnn}.

\subsubsection{Convolutional Neural Network (CNN) for ECG Signal Feature Extraction}
A one-dimensional (1D) CNN is used to extract spatial patterns from the ECG signal. 
The convolution operation in discrete time \( n \) is expressed as:

\begin{equation}
X^{(l)}[n] = f \left( \sum_{i=0}^{K-1} W_i^{(l)} X^{(l-1)}[n - i] + b^{(l)} \right)
\end{equation}

\noindent
where:
\begin{itemize}
    \item \( X^{(l)}[n] \) is the feature map at layer \( l \),
    \item \( W_i^{(l)} \) represents the convolution kernel (learnable weights),
    \item \( X^{(l-1)}[n] \) is the input from the previous layer,
    \item \( b^{(l)} \) is the bias term,
    \item \( f(\cdot) \) is the activation function — here, a ReLU function is used.
\end{itemize}

After convolution, a \emph{pooling layer} is applied to downsample the data and reduce dimensionality:
\begin{equation}
P^{(l)}[n] = \max_{0 \leq i < M} X^{(l)}[Mn + i]
\end{equation}

\noindent
where:
\begin{itemize}
    \item \( P^{(l)}[n] \) is the pooled feature at discrete time \( n \),
    \item \( M \) is the pooling window size.
\end{itemize}

\noindent
\textbf{Input:} Preprocessed ECG segment around the detected R-peak. 
\textbf{Model Architecture:} 1D CNN followed by LSTM layers for enhanced temporal representation. 
\textbf{Output:} Probability distribution across classes (\emph{P, Q, R, S, T}).

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig4.png}
  \caption{Reinforcement Learning--Enhanced CNN--LSTM Deep Learning Framework for Robust ECG PQRST Detection and Classification}
  \label{fig:cnn}
\end{figure}

\subsubsection{Long Short-Term Memory (LSTM) for Temporal Learning}
The LSTM--RNN component captures temporal dependencies within the PQRST features extracted by the CNN. 
Long Short-Term Memory (LSTM) networks are a specialized form of recurrent neural networks (RNNs) 
designed to retain long-term contextual information and mitigate vanishing gradient problems.

\noindent
Each LSTM unit contains three primary gates controlling information flow:

\begin{itemize}
    \item \textbf{Forget Gate:} Determines which information to discard from the cell state.
    \item \textbf{Input Gate:} Incorporates new information into the cell state.
    \item \textbf{Output Gate:} Regulates which part of the cell state is output as the next hidden state.
\end{itemize}

\noindent
The signal flow of the \textcolor{black}{LSTM--RNN} algorithm proceeds sequentially as follows:
\noindent
Input feature vector \(x_t \rightarrow\) Forget gate \(f_t \rightarrow\) Input gate \(i_t \rightarrow\)
Cell state update \(c_t \rightarrow\) Output gate \(o_t \rightarrow\) Hidden state \(h_t\).

\noindent
This gating mechanism allows the model to selectively remember relevant ECG features, 
capturing temporal correlations between consecutive cardiac cycles 
and enabling precise arrhythmia classification.

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig5.png}
  \caption{CNN--LSTM--RNN sub-system modeling of temporal dependencies in ECG feature sequences.}
  \label{fig:lstm}
\end{figure}

\subsubsection{Fully Connected (FC) Layer and Softmax for Classification}
The LSTM output is passed through a Fully Connected (FC) layer followed by a Softmax prediction module (SMP) for final classification. 
The overall signal flow is summarized as:

\noindent
\textbf{LSTM Output } \(h_n \rightarrow\) \textbf{Fully Connected Layer } \(z_k\)
\(\rightarrow\) \textbf{Softmax Function } \(P(y=c \mid X)\)
\(\rightarrow\) \textbf{Class Probabilities.}

\noindent
The FC layer computes:
\begin{equation}
z_k = W_k^{\top} h_n + b_k
\end{equation}
where \(z_k\) is the logit score for class \(k\), \(W_k\) is the learned weight matrix, 
\(h_n\) is the final LSTM hidden state, and \(b_k\) is the bias term.

\noindent
A classifier is trained to predict the correct ECG class. Given a feature vector \(X = [P, Q, R, S, T]\), the predicted class \(\hat{y}\) is obtained as:
\begin{equation}
\hat{y} = \arg\max_{c} P(y = c \mid X)
\end{equation}
where \(P(y=c \mid X)\) is computed via the Softmax activation:
\begin{equation}
y = \textcolor{black}{\operatorname{Softmax}}(W \cdot X + b)
\end{equation}
and explicitly defined as:
\begin{equation}
P(y = c \mid X) = \frac{e^{z_c}}{\sum_{k} e^{z_k}}
\end{equation}

\noindent
Here, \(W\) and \(b\) represent the learned weights and biases, respectively, and \(X\) denotes the ECG feature vector.

\noindent
This hierarchical structure ensures efficient and accurate classification of ECG PQRST peaks, 
with the Softmax function producing a normalized probability distribution over all possible classes, 
enhancing interpretability and diagnostic confidence.

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig6.png}
  \caption{Fully Connected and Softmax layers transforming LSTM outputs into ECG class probabilities.}
  \label{fig:flow}
\end{figure}

\subsection{Training Procedure}
The CNN--LSTM model is trained on ECG segments centered around detected R-peaks from the MIT-BIH Arrhythmia Database. 
Each segment undergoes preprocessing and normalization before being fed into the model. 
The architecture consists of three convolutional layers (16, 32, and 64 filters), each followed by max-pooling, 
and two stacked LSTM layers with 64 hidden units each. 
The final output layer performs classification across five arrhythmia categories (\emph{Normal}, \emph{PVC}, \emph{LBBB}, \emph{ST Elevation}, and \emph{AFIB}). 

Training employs the Adam optimizer with a learning rate of \(1 \times 10^{-3}\), 
a batch size of 64, and early stopping after 100 epochs based on validation loss to prevent overfitting.

\section{Results and Discussion}

The proposed AI-driven ECG signal processing framework was evaluated using the MIT-BIH Arrhythmia Database~\cite{Goldberger2000} to assess its accuracy, robustness, and generalization in PQRST detection and arrhythmia classification. 
The system integrates reinforcement learning (RL) for adaptive threshold tuning and a \textcolor{black}{CNN--LSTM} hybrid for spatiotemporal classification of ECG waveforms.

\subsection{Quantitative Evaluation and Comparative Performance}

The model achieved consistently high accuracy across all evaluated metrics, with a PQRST detection accuracy of 99.58\%, classification accuracy of 99.85\%, and anomaly detection precision of 99.85\%. 
These results highlight the synergy between the reinforcement learning agent and the CNN--LSTM architecture, combining adaptability with temporal--spatial feature extraction. 
Detailed quantitative results are presented in Table~\ref{tab:stats}.

\begin{table}[ht]
\centering
\caption{Evaluation of the proposed system on the MIT-BIH test set.}
\label{tab:stats}
\begin{tabular}{lc}
\toprule
\textbf{Metric} & \textbf{Value (\%)} \\
\midrule
Accuracy & 99.32 \\
Sensitivity (Recall) & 99.74 \\
Specificity & 99.59 \\
False Positive Rate & 0.26 \\
False Negative Rate & 0.68 \\
\bottomrule
\end{tabular}
\end{table}

As shown in Table~\ref{tab:stats}, the proposed approach maintains a near-perfect balance between sensitivity and specificity, confirming that it accurately identifies cardiac events while minimizing false detections. 
The extremely low false positive rate (0.26\%) demonstrates robustness and reliability, making it suitable for clinical or IoT-based continuous monitoring.

To contextualize these results, Table~\ref{tab:comparison} compares the proposed method with benchmark studies, including both classical and deep learning approaches. 
The reinforcement learning component significantly enhances adaptability to inter-patient variability, while the \textcolor{black}{CNN--LSTM} module effectively models long-term temporal dependencies, leading to state-of-the-art performance across all measured indicators.

\begin{table}[htbp]
\centering
\caption{Comparison of detection and classification accuracy with previous studies.}
\label{tab:comparison}
\resizebox{\columnwidth}{!}{
\begin{tabular}{l l c c c}
\toprule
\textbf{Study (Year)} & \textbf{Method} & \textbf{PQRST Detection (\%)} & \textbf{Classification (\%)} & \textbf{Anomaly Precision (\%)} \\
\midrule
This work (2025) & RL + CNN--LSTM hybrid & 99.58 & 99.85 & 99.85 \\
Christodoulou \emph{et al.} (2024) \cite{Christodoulou2024} & AI-IoT with ML & 98.7 & 98.5 & 98.3 \\
Pan and Tompkins (1985) \cite{Pan1985} & Traditional algorithm & 96.3 & 97.2 & --- \\
Goldberger \emph{et al.} (2000) \cite{Goldberger2000} & Clinical benchmark & 97.0 & 96.0 & 94.2 \\
ANSI/AAMI EC38 (1999) \cite{AAMI1999} & Standard ECG range & 98.0 & 97.6 & --- \\
Odugoudar and Walia (2024) \cite{Odugoudar2024} & CNN (arXiv) & 99.2 & 99.3 & 98.8 \\
Fatima \emph{et al.} (2024) \cite{Fatima2024} & Q-learning + CNN & 99.0 & 99.1 & 99.2 \\
\bottomrule
\end{tabular}}
\end{table}

The hybrid RL--CNN--LSTM framework surpasses both classical signal processing methods~\cite{Pan1985,Goldberger2000,AAMI1999} and modern deep learning models~\cite{Odugoudar2024,Fatima2024,Alamatsaz2022}. 
Unlike fixed-threshold algorithms, the RL agent dynamically adjusts detection parameters based on reward feedback, improving precision under noisy and non-stationary conditions.  
The CNN--LSTM component further enhances performance by capturing morphological and temporal correlations between beats. 
These mechanisms collectively explain the superior results observed across all key metrics.

\subsection{Qualitative Analysis and Visualization}

Figures~\ref{fig:example1}--\ref{fig:example3} illustrate the system’s ability to accurately identify and label PQRST complexes across both normal and pathological signals from the MIT-BIH dataset. 
Figure~\ref{fig:example1} presents a normal sinus rhythm trace with detected peaks and classification overlay, while \textcolor{black}{Fig.~\ref{fig:example2}} displays multiple signals with consistent detection accuracy. 
Figure~\ref{fig:viz} shows training waveform segments, and \textcolor{black}{Fig.~\ref{fig:example3}} demonstrates final PQRST detections with corresponding class annotations.

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig7.png}
  \caption{Binary-Tree Signal Processing Flow for AI Deep Learning \textcolor{black}{CNN--LSTM--RNN--FC--SMP} PQRST Detection and Classification}
  \label{fig:example1}
\end{figure}

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig8.png}
  \caption{Detected PQRST complexes across five ECG recordings from the MIT-BIH dataset (each row represents one signal).}
  \label{fig:example2}
\end{figure}

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig9.png}
  \caption{Visualization of training waveform segments showing highlighted PQRST intervals used for feature learning.}
  \label{fig:viz}
\end{figure}

\begin{figure}[ht]
  \centering
  \includegraphics[width=\columnwidth]{img/fig10.png}
  \caption{Example ECG showing detected PQRST points (colored markers) with associated CNN--LSTM classification results.}
  \label{fig:example3}
\end{figure}

The consistent identification of PQRST complexes across diverse morphologies--including left bundle branch block (LBBB), premature ventricular contractions (PVC), and atrial fibrillation (AFIB)--confirms the model’s high generalization capability. 
Moreover, the integration of reinforcement learning provides adaptive resilience, maintaining precision even under variable signal quality and noise levels.

\subsection{Integrated Discussion and Implications}

The combined quantitative and qualitative findings validate the effectiveness of reinforcement learning as an adaptive mechanism for ECG feature extraction, overcoming the limitations of static, rule-based methods. 
By coupling RL with CNN--LSTM temporal--spatial modeling, the proposed system achieves significant improvements in detection accuracy, interpretability, and robustness. 
This aligns with recent advances in intelligent ECG modeling~\cite{Ismail2023,OReilly2023,Abdurrahman2024} that emphasize self-optimizing architectures for healthcare monitoring.

Compared with earlier frameworks~\cite{Pan1985,Goldberger2000,Alamatsaz2022,Odugoudar2024,Fatima2024,Christodoulou2024}, the modular RL--CNN--LSTM design demonstrates higher resilience to inter-patient variability, waveform distortion, and baseline drift. 
The separation of preprocessing, feature extraction, RL optimization, and deep classification modules supports scalable deployment on IoT and wearable devices, paving the way for real-time and energy-efficient cardiac monitoring.

Nevertheless, the current model’s validation is limited to the MIT-BIH dataset. Future work could target optimization of the RL agent for low-power edge computing and integrate explainable AI (XAI) to enhance interpretability and transparency in automated diagnosis.

The experimental evaluation demonstrates the superior performance of the proposed hybrid model, achieving a PQRST Detection Accuracy of 99.58\%, a Classification Accuracy of 99.85\%, and an Anomaly Detection Precision of 99.85\% on validated ECG datasets. These results outperform traditional rule-based and single-model deep learning methods, confirming the robustness, generalizability, and clinical reliability of the proposed architecture.

This unique and innovative AI-driven system represents a significant advancement in the field of biomedical signal processing and intelligent cardiology. Its ability to capture both spatial and temporal characteristics of ECG signals--combined with real-time self-optimization through reinforcement learning--provides a powerful foundation for continuous monitoring, early diagnosis, and preventive cardiovascular care. The successful prototyping of this algorithm highlights its potential for integration into wearable medical devices, smart healthcare systems, and telemedicine platforms, enabling next-generation AI-powered cardiac diagnostics. Overall, the proposed RL--CNN--LSTM framework offers a robust, adaptive, and clinically relevant approach for next-generation ECG monitoring, combining real-time adaptability, high precision, and integration potential with intelligent IoT healthcare ecosystems.



\section{Conclusion}
This study introduced an AI-driven ECG analysis framework combining reinforcement learning with a hybrid CNN--LSTM architecture for adaptive PQRST detection and arrhythmia classification. The system demonstrated superior accuracy and robustness over traditional and deep learning approaches. The reinforcement learning agent optimized detection thresholds to adapt to signal variations, while the CNN--LSTM model captured spatial and temporal dependencies in cardiac cycles. With its modular design, the framework is suitable for real-time healthcare applications in IoT and wearable environments. Future work will explore cross-dataset validation, edge deployment, and explainable AI to enhance transparency and clinical trust.

\section{Acknowledgment}
The authors express their gratitude to BIOMED Medical Systems for providing research and technical support, to Neapolis University Cyprus for facilitating computational resources and project coordination, and to European University Cyprus for academic collaboration and institutional support. The authors also acknowledge the use of the PhysioNet repository~\cite{Goldberger2000} and thank the open-source ECG signal processing community for their valuable contributions that supported this research.

\section{Dedication}
This research work is lovingly dedicated to the cherished memory of Mr. Andreas Christodoulou, the beloved father of Lakis Christodoulou, whose life was tragically lost due to the absence of advanced AI and machine learning diagnostic technologies, and the lack of real-time, continuous monitoring of vital physiological signals. His loss serves as a powerful reminder of the urgent need for innovation in intelligent healthcare systems, technologies capable of early detection, timely intervention, and life-saving precision.

\bibliographystyle{IEEEtran}
\bibliography{references}
\end{document}
