How can I read local ecg file using wfdb app?

I only have a .dat file (no .hea file) which contains all 12 ecg leads.
I download and configure the wfdb app for matlab.
Then I run the following code,
[signal, fs, tm] = rdsamp('ecgfile.dat');
And then I got the error below,
This is my matlab directory, my .dat file is located in F:\Open ECG file data.
Could anyone help me solve this problem?
regards.

4 Comments

Julia Liu
Julia Liu on 27 Jul 2022
Edited: Julia Liu on 27 Jul 2022
Same problem faced.
Addng the following line in line 91 in rdsamp.m solved my problem, hope it helps yours too.
config.WFDB_PATH = 'C:\yourfolder\mcode\';
'yourfolder' is the folder storing your .dat file.
Only works if data were put directly under the 'mcode' folder created by WFDB.
Pretty messy to store data here though, need better solution...
Thanks for sharing your experience. I'm facing the same issue.
As you suggrested, I have add the following line in line 91 in rdsamp.m file, i.e.,
config.WFDB_PATH = 'C:\User\Desktop\test\mcode\';
All the .dat files are stored in a folder called "test" with the path "C:\User\Desktop\test". In the test folder, I have two more folders called "mcode" and "database" which are generated by wfdb toolbox.
However, I get the following error
Could not find record: test.dat. Search path is set to: 'C:\User\Desktop\test\mcode\'
Any idea how to solve this issue?
Thanks in advance!
In my case,
My .dat file is saved under D:\zMATLAB\WFDB\mcode\
The following test1.m is also saved and ran under D:\zMATLAB\WFDB\mcode\
In rdsamp.m, from line 86 - 94,
persistent javaWfdbExec config
if(isempty(javaWfdbExec))
[javaWfdbExec,config]=getWfdbClass('rdsamp');
end
config.WFDB_PATH = 'D:\zMATLAB\WFDB\mcode\'; %%%%%%% added line
%Set default pararamter values
inputs={'recordName','signalList','N','N0','rawUnits','highResolution'};
outputs={'signal','Fs','tm'};
@Julia Liu Thanks for your through explanation. I made sure the .dat file and test1.m are saved under 'C:\User\Desktop\test\mcode\', However, I still get the same error:
any idea?
Error using rdsamp (line 204)
Could not find record: SE8ECG4E. Search path is set to: 'C:\User\Desktop\test\mcode\'

Sign in to comment.

Answers (2)

Use the fullfile function to generate the file name with the correct path, then use that result as the argument for ‘rdsamp’.
Then save the three outputs to a ‘.mat’ file so you can load them quickly and conveniently when you need them later.

7 Comments

Thank you for your reply.
I ran the code below but I still got the same error.
path = fullfile('F:\','Open ECG file data','ecgfile.dat');
[signal, fs, tm] = rdsamp(path);
I am attaching the .dat file as well.
Thanks and best regards.
I can’t get that Physionet ‘rdsamp’ file to run — I get some sort of Java error — so I abandoned the attempt and deleted the entire directory contiaining it and whatever else it depends on. The documentation is almost completely lacking in any sort of useful information.
Physionet used to provide MATLAB ‘.mat’ files that could be imported using load. I have no idea whatever became of that capability, since I can’t find it on the Physionet site (that used to be called ‘Physionet ATM’). I haven’t used Physionet in a few years because of those changes, although I still have several ‘.mat’ files that I use occasionally to test code.
I cannot help you with this, so I will delete my Answer in a few mninutes. I have no idea how to get that file to work. I suggest you ask Physionet about this. Please post whatever solution they offer back here so others can benefit.
EDIT — (31 Dec 2020 at 20:32)
A few minutes ago, I received an e-mail from Tom Pollard at PhysioNet, and am posting the the relevant excerpt of it:
—————
It sounds like you are interested in the Matlab software, which is primarily maintained by Ikaro Silva and Benjamin Moody (https://github.com/ikarosilva/wfdb-app-toolbox). If you have issues with this software, then a good approach would be to raise an issue on the GitHub repository (https://github.com/ikarosilva/wfdb-app-toolbox).
From the error message that you've shown, it looks like there are a couple of things happening:
(1) In your command ([signal, fs, tm] = rdsamp('ecgfile.dat');) the package appears to default to searching online for a file called `ecgfile.dat`, instead of searching locally.
(2) The package is using the incorrect URL (http://physionet.org/physiobank/database) for its online search.
The fixes are:
(1) In your specific case, as the files are local, you could try specifying the file path to your rdsamp argument. e.g. `rdsamp('path/to/file/ecgfile.dat')`. I would suggest avoiding spaces in directory names (e.g. "open_ecg_data" instead of "Open ECG file data") because the spaces can be tricky to work with at the command line.
(2) The Matlab software maintainers should update the hardcoded search URL in the package itself.
The screenshot you have shown mentions the ATM, a web tool that can be used to extract records. This tool is available at: https://archive.physionet.org/cgi-bin/atm/. I'm not sure that the ATM it is really needed in your case. Using the WFDB software should be a more efficient way of parsing .dat files and converting them to .mat format if necessary.
If you are familiar with Python, then you might also consider using the Python WFDB software for working with the dat files. There is an example notebook at: https://github.com/MIT-LCP/wfdb-python/blob/master/demo.ipynb that may be helpful in getting started with this.
Best wishes,
Tom
---
Tom Pollard
MIT Laboratory for Computational Physiology,
Institute for Medical Engineering and Science,
E25-505, 45 Carleton St, Cambridge, MA 02142
—————
Thanks for your reply.
A few days ago I sent Physionet an e-mail and yesterday I received the same e-mail as you mentioned above. They also sent me some solutions and I am trying to sort it out.
My pleasure!
I forwarded the full email I received on 31 Dec 2020 to MathWorks (what I posted here is a relevant excerpt) and suggested that since so many people use PhysioNet with MATLAB that it would be worth considering some sort of collaboration to make the tools more user-friendly.
I have not yet visited the GitHub section. That might provide more information, since File Exchange and GitHub are in some ways linked.
@Kevin T Could you please share with us how you solved the issue?
@Star Strider I am getting the same error as Kevin got. As you suggested, I did ''Use the fullfile function to generate the file name with the correct path, then use that result as the argument for ‘rdsamp’." However still getting the same error. it seems the package defaults to searching online for my .dat file instead of searching locally even though I set the path . Any suggestions? thanks in advance!
See: PhysioBank ATM to get the .mat file versions of the records.

Sign in to comment.

There should be at least the following three issues taken care of:
  1. The ".dat" file should always have its ".hea" file with it. The header (.hea) file contains plain text and can be easily deduced from the other ".hea" files of similar records.
  2. You should not pass the full path of the record file to the function "rdsamp".
  • For example, let's say your matlab and record files have the following paths:
  • F:\Open ECG file data\reader.m
  • F:\Open ECG file data\records\rec001.dat
  • F:\Open ECG file data\records\rec001.hea
  • Then you should call "rdsamp" in the reader.m file as follows:
  • [signal, fs, tm] = rdsamp('\records\rec001');
3. The full path of the records should not exceed 256 characters.

Asked:

on 30 Dec 2020

Commented:

on 5 Feb 2024

Community Treasure Hunt

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

Start Hunting!