Preprocessing PTB-XL dataset in MATLAB

Hello! How can I open specific records from PTB-XL dataset and process them in MATLAB? What I want to do is to first load the ECG leads loaded in .dat file one by one so that I can preprocess them, such as applying digital filters, prior to the creation of composite lead (mixture of 12-lead ECG in one waveform). I have WFDB tool from Physionet. However, it is not working on the dataset. I have the dataset downloaded in my laptop. Thank you!

3 个评论

Aside from .dat file, it also contains its corresponding .hea file
I have WFDB tool from Physionet. However, it is not working on the dataset.
Could we get some more information as to how it is failing?
Basically, when I try to follow the documentation in the tool, it keeps throwing an error that the file is nowhere to be found. It turns out that the tool is set to read files available in the PhysioBank ATM. PTB-XL is not available to that site.

请先登录,再进行评论。

 采纳的回答

Hi Ralph,
I can certainly help you with that. So, basically your objective is to open specific records from the PTB-XL dataset and process them in MATLAB which involves loading ECG leads from .dat files, preprocessing them by applying digital filters, and creating a composite lead. Since the WFDB tool from Physionet is not working for this dataset, you are looking alternative method to achieve this using MATLAB. You already know load the .dat file and its corresponding .hea file, since the WFDB tool is not working, you can directly read the .dat file using MATLAB's `fread` function, and parse the header information from the .hea file using standard file input/output functions. For more information on this function, please refer to,
Next step involves preprocessing the ECG leads, so once you have loaded the ECG leads, apply digital filters for preprocessing by installing DSP System Toolbox. For more information regarding DSP System Toolbox, please refer to
Finally, create a composite lead by simply combining the preprocessed ECG signals using MATLAB's array manipulation functions like `vertcat` or `horzcat`. For more information on these functions, please refer to
Here's a sample MATLAB script to illustrate the above steps:
% Step 1: Load the .dat file and its corresponding .hea file
fid = fopen('your_ecg_record.dat', 'r'); data = fread(fid, 'int16'); fclose(fid);
headerInfo = importdata('your_ecg_record.hea');
% Step 2: Preprocess the ECG leads
fs = headerInfo.SamplingFrequency; [b, a] = butter(4, [0.5 40]/(fs/2), 'bandpass'); filteredData = filter(b, a, data);
% Step 3: Create a composite lead
compositeLead = [filteredData1, filteredData2, ...]; % Combine all filtered ECG signals
% Additional considerations: You can further analyze and visualize the composite lead using MATLAB's plotting functions such as `plot` or `plotyy`. Additionally, consider saving the preprocessed data using MATLAB's `save` function for future use.
I hope this helps! Let me know if you need further assistance.

5 个评论

I'll try this one out. I haven't checked it yet.
The code results in 4 files. One of this is data, which contains 60000x1 double value. I tried to analyze this data, however, it didn't produce 12 lead. It seems that the signals were all mixed up.
Hi Ralph,
Have you figured out to resolve the issue, please let us know if you need any further assistance.
Yes, thank you for your help guys!
No problem, glad to know your issues have been resolved. If you still need any further assistance or help, please let us know. Good luck with your future endeavors.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by