Hi Sanjay,
The Pan-Tompkins algorithm is mainly used for QRS detection, and while it doesn’t inherently convert 1D signals to 2D, it can be part of a pre-processing step before conversion. To convert 1D signal to 2D, you can get 2 spectral pictures of time or frequency. Therefore, the ‘reshape’ function can be used to convert from a vector to a matrix and the Pan-Tompkins algorithm can just be used for preprocessing.
To implement the Pan-Tompkins algorithm, refer the following steps:
- Remove the baseline wander and high-frequency noise of the signal by bandpass filtering
- Differentiate the signal to emphasize slopes of the QRS complex
- Square the signal to enhance the QRS peaks
- Smoothen the signal to obtain a waveform suitable for thresholding
- Detect QRS complexes by thresholding.
- After detecting QRS complexes, you can convert the signal to a 2D format. One common approach is using a spectrogram or reshaping the signal into a matrix.
A sample MATLAB code to perform the above steps is as following assuming a sample random ECG signal.
ecg_signal = 0.5 * sin(2 * pi * 1 * t) + 0.1 * randn(size(t));
[b, a] = butter(1, [5 15] / (fs / 2), 'bandpass');
ecg_filtered = filtfilt(b, a, ecg_signal);
ecg_diff = diff(ecg_filtered);
ecg_squared = ecg_diff .^ 2;
window_size = round(0.15 * fs);
ecg_integrated = movmean(ecg_squared, window_size);
threshold = max(ecg_integrated) * 0.6;
qrs_peaks = ecg_integrated > threshold;
spectrogram(ecg_signal, 128, 120, 128, fs, 'yaxis');
title('ECG Spectrogram');
num_segments = floor(length(ecg_signal) / segment_length);
ecg_2d = reshape(ecg_signal(1:num_segments*segment_length), segment_length, num_segments);
The above code outputs the following:
This approach uses QRS detection with a method to visualize the ECG in 2D, which can be useful for pattern recognition or feature extraction tasks. However, the Pan-Thompkins algorithm is just used here for pre-processing and not for converting the ECG signal into 2D explicitly. You can further adjust the corresponding parameters for specific ECG data. For more information on the algorithm and functions used, refer the following resources:
Hope this helps!