{"id":10217,"date":"2018-10-12T09:00:46","date_gmt":"2018-10-12T13:00:46","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=10217"},"modified":"2018-10-11T16:36:40","modified_gmt":"2018-10-11T20:36:40","slug":"edf-read","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2018\/10\/12\/edf-read\/","title":{"rendered":"EDF Read"},"content":{"rendered":"<div xmlns:mwsh=\"http:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\n   <introduction><\/p>\n<p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>&#8216;s pick this week is <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/31900\"><tt>edfRead<\/tt><\/a> by <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/845693\">Brett Shoelson<\/a>.\n      <\/p>\n<p>   <\/introduction><\/p>\n<h3>EDF Read<a name=\"1\"><\/a><\/h3>\n<p>A MATLAB user asked me yesterday if we have support for the binary file format <a href=\"https:\/\/en.wikipedia.org\/wiki\/European_Data_Format\">EDF<\/a>, short for &#8220;European Data Format&#8221;.  I&#8217;d never heard of it.  However, apparently my colleague, Brett, had already written a reader for it.\n   <\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[hdr, record] = edfread(<span style=\"color: #A020F0\">'ecgca998.edf'<\/span>);<\/pre>\n<pre style=\"font-style:oblique\">Step 1 of 2: Reading requested records. (This may take a few minutes.)...\r\nStep 2 of 2: Parsing data...\r\n<\/pre>\n<p>The function returns the header information and a matrix where each row is the data for that variable.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">disp(hdr)<\/pre>\n<pre style=\"font-style:oblique\">            ver: 0\r\n      patientID: 'X F X Gestation_32+3                                                            '\r\n       recordID: 'Startdate 29-JAN-2004 X X X                                                     '\r\n      startdate: '29.01.04'\r\n      starttime: '23.38.00'\r\n          bytes: 2048\r\n        records: 45\r\n       duration: 5\r\n             ns: 7\r\n          label: {1&times;7 cell}\r\n     transducer: {1&times;7 cell}\r\n          units: {'mV'  'mV'  'uV'  'uV'  'uV'  'uV'  ''}\r\n    physicalMin: [-5 -5 -500 -500 -500 -500 -1]\r\n    physicalMax: [5 5 500 500 500 500 1]\r\n     digitalMin: [-32768 -32768 -32768 -32768 -32768 -32768 -32768]\r\n     digitalMax: [32767 32767 32767 32767 32767 32767 32767]\r\n      prefilter: {1&times;7 cell}\r\n        samples: [5000 5000 5000 5000 5000 5000 500]\r\n      frequency: [1000 1000 1000 1000 1000 1000 100]\r\n<\/pre>\n<p>Today, it might be easier to store some of this as a table.<\/p>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">T = array2table(record',<span style=\"color: #A020F0\">'VariableNames'<\/span>, hdr.label);\r\nT.Properties.VariableUnits = hdr.units;\r\nT.Properties.VariableDescriptions = hdr.transducer;<\/pre>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">head(T)<\/pre>\n<pre style=\"font-style:oblique\">ans =\r\n  8&times;7 table\r\n    Thorax_1    Thorax_2    Abdomen_1    Abdomen_2    Abdomen_3    Abdomen_4    EDFAnnotations\r\n    ________    ________    _________    _________    _________    _________    ______________\r\n     -1.0331    -0.22179     -22.133       -22.21      -22.118      -22.194        0.37633    \r\n       -1.04     -0.5642     -50.866       -28.13      -66.934      -20.958        0.15688    \r\n     -1.0117    -0.54879     -50.942      -26.009      -65.759      -23.262        0.33596    \r\n    -0.98688    -0.53689     -51.553      -27.901      -67.681      -25.368        0.36086    \r\n    -0.99832    -0.53887     -52.346      -28.832      -66.781      -25.841         0.4078    \r\n     -1.0159    -0.54238     -48.867      -28.527      -65.621      -24.559        0.15792    \r\n     -1.0304    -0.54986     -47.585       -31.67      -67.407      -24.331        0.64312    \r\n     -1.0468    -0.56466     -48.409      -34.203      -70.184      -25.444         0.1588    \r\n<\/pre>\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">summary(T)<\/pre>\n<pre style=\"font-style:oblique\">Variables:\r\n    Thorax_1: 225000&times;1 double\r\n        Properties:\r\n            Units:  mV\r\n            Description:  AgAgCl electrodes\r\n        Values:\r\n            Min              -5 \r\n            Median     -0.33333 \r\n            Max               5 \r\n    Thorax_2: 225000&times;1 double\r\n        Properties:\r\n            Units:  mV\r\n            Description:  AgAgCl electrodes\r\n        Values:\r\n            Min              -5 \r\n            Median     -0.18532 \r\n            Max               5 \r\n    Abdomen_1: 225000&times;1 double\r\n        Properties:\r\n            Units:  uV\r\n            Description:  AgAgCl electrodes\r\n        Values:\r\n            Min            -500  \r\n            Median      -13.603  \r\n            Max             500  \r\n    Abdomen_2: 225000&times;1 double\r\n        Properties:\r\n            Units:  uV\r\n            Description:  AgAgCl electrodes\r\n        Values:\r\n            Min            -500  \r\n            Median      -4.2649  \r\n            Max             500  \r\n    Abdomen_3: 225000&times;1 double\r\n        Properties:\r\n            Units:  uV\r\n            Description:  AgAgCl electrodes\r\n        Values:\r\n            Min            -500  \r\n            Median      -7.7745  \r\n            Max             500  \r\n    Abdomen_4: 225000&times;1 double\r\n        Properties:\r\n            Units:  uV\r\n            Description:  AgAgCl electrodes\r\n        Values:\r\n            Min            -500  \r\n            Median      -2.2354  \r\n            Max             500  \r\n    EDFAnnotations: 225000&times;1 double\r\n        Values:\r\n            Min                 0     \r\n            Median              0     \r\n            Max           0.65097     \r\n<\/pre>\n<h3>Comments<a name=\"6\"><\/a><\/h3>\n<p>Give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=10217#respond\">here<\/a> or leave a <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/31900#comments\">comment<\/a> for Brett.\n   <\/p>\n<p><script language=\"JavaScript\">\n<!--\n\n    function grabCode_e66971b4f98d484f893c4171465e8c0b() {\n        \/\/ Remember the title so we can use it in the new page\n        title = document.title;\n\n        \/\/ Break up these strings so that their presence\n        \/\/ in the Javascript doesn't mess up the search for\n        \/\/ the MATLAB code.\n        t1='e66971b4f98d484f893c4171465e8c0b ' + '##### ' + 'SOURCE BEGIN' + ' #####';\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e66971b4f98d484f893c4171465e8c0b';\n    \n        b=document.getElementsByTagName('body')[0];\n        i1=b.innerHTML.indexOf(t1)+t1.length;\n        i2=b.innerHTML.indexOf(t2);\n \n        code_string = b.innerHTML.substring(i1, i2);\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\n\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \n        \/\/ in the XML parser.\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\n        \/\/ doesn't go ahead and substitute the less-than character. \n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\n\n        author = 'Sean de Wolski';\n        copyright = 'Copyright 2018 The MathWorks, Inc.';\n\n        w = window.open();\n        d = w.document;\n        d.write('\n\n<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\n\n\\n');\n      \n      d.title = title + ' (MATLAB code)';\n      d.close();\n      }   \n      \n-->\n<\/script><\/p>\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><a href=\"javascript:grabCode_e66971b4f98d484f893c4171465e8c0b()\"><span style=\"font-size: x-small;        font-style: italic;\">Get<br \/>\n            the MATLAB code<br \/>\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\n<p>      Published with MATLAB&reg; R2018b<\/p>\n<\/div>\n<p><!--\ne66971b4f98d484f893c4171465e8c0b ##### SOURCE BEGIN #####\n%% EDF Read\n%\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/31900 |edfRead|> by \n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/845693 Brett Shoelson>.\n% \n\n%% EDF Read\n%\n% A MATLAB user asked me yesterday if we have support for the binary file\n% format <https:\/\/en.wikipedia.org\/wiki\/European_Data_Format EDF>, short\n% for \"European Data Format\".  I'd never heard of it.  However, apparently\n% my colleague, Brett, had already written a reader for it.\n\n[hdr, record] = edfread('ecgca998.edf');\n\n%%\n% The function returns the header information and a matrix where each row\n% is the data for that variable.\n\ndisp(hdr)\n\n%%\n% Today, it might be easier to store some of this as a table.\n\nT = array2table(record','VariableNames', hdr.label);\nT.Properties.VariableUnits = hdr.units;\nT.Properties.VariableDescriptions = hdr.transducer;\n%%\nhead(T)\n%%\nsummary(T)\n\n%% Comments\n% \n% Give it a try and let us know what you think\n% <http:\/\/blogs.mathworks.com\/pick\/?p=10217#respond here> or leave a\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/31900#comments\n% comment> for Brett.\n%\n \n\n##### SOURCE END ##### e66971b4f98d484f893c4171465e8c0b\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sean&#8216;s pick this week is edfRead by Brett Shoelson.<\/p>\n<p>EDF Read<br \/>\nA MATLAB user asked me yesterday if we have support for the binary file format EDF, short for &#8220;European Data&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2018\/10\/12\/edf-read\/\">read more >><\/a><\/p>\n","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10217"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=10217"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10217\/revisions"}],"predecessor-version":[{"id":10221,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/10217\/revisions\/10221"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=10217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=10217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=10217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}