声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3952|回复: 3

[综合讨论] 用matlab读取edf格式的脑电时,其数值是脑电的幅值吗?

[复制链接]
发表于 2010-7-2 16:52 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
用matlab读取edf格式的脑电时,matlab上的读数是脑电的幅值吗?
回复
分享到:

使用道具 举报

发表于 2010-7-2 21:08 | 显示全部楼层
个人水平专业有限, 不知edf格式是什么? :@L
发表于 2012-4-15 22:36 | 显示全部楼层
冒昧问你一下你是怎么用matlab读取edf文件的?
发表于 2012-4-16 00:23 | 显示全部楼层
其实只要知道资料档案的格式, 使用fread就一定可以读!
帮搜索下, 不过个人没edf的资料, 没试过
试过的人再说说是否可用
From http://www.mathworks.com/matlabcentral/fileexchange/31900-edfread
  1. function [hdr, record] = edfRead(fname, varargin)
  2. % Read European Data Format file into MATLAB
  3. %
  4. % [hdr, record] = edfRead(fname)
  5. %         Reads data from ALL RECORDS of file fname ('*.edf'). Header
  6. %         information is returned in structure hdr, and the signals
  7. %         (waveforms) are returned in structure record, with waveforms
  8. %         associated with the records returned as fields titled 'data' of
  9. %         structure record.
  10. %
  11. % [...] = edfRead(fname, 'assignToVariables', assignToVariables)
  12. %         Triggers writing of individual output variables, as defined by
  13. %         field 'labels', into the caller workspace.
  14. %
  15. % FORMAT SPEC: Source: http://www.edfplus.info/specs/edf.html SEE ALSO:
  16. % http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/eeg/edf_spec.htm
  17. %
  18. % The first 256 bytes of the header record specify the version number of
  19. % this format, local patient and recording identification, time information
  20. % about the recording, the number of data records and finally the number of
  21. % signals (ns) in each data record. Then for each signal another 256 bytes
  22. % follow in the header record, each specifying the type of signal (e.g.
  23. % EEG, body temperature, etc.), amplitude calibration and the number of
  24. % samples in each data record (from which the sampling frequency can be
  25. % derived since the duration of a data record is also known). In this way,
  26. % the format allows for different gains and sampling frequencies for each
  27. % signal. The header record contains 256 + (ns * 256) bytes.
  28. %
  29. % Following the header record, each of the subsequent data records contains
  30. % 'duration' seconds of 'ns' signals, with each signal being represented by
  31. % the specified (in the header) number of samples. In order to reduce data
  32. % size and adapt to commonly used software for acquisition, processing and
  33. % graphical display of polygraphic signals, each sample value is
  34. % represented as a 2-byte integer in 2's complement format. Figure 1 shows
  35. % the detailed format of each data record.
  36. %
  37. % DATA SOURCE: Signals of various types (including the sample signal used
  38. % below) are available from PHYSIONET: http://www.physionet.org/
  39. %
  40. %
  41. % % EXAMPLE 1:
  42. % % Read all waveforms/data associated with file 'ecgca998.edf':
  43. %
  44. % [header, recorddata] = edfRead('ecgca998.edf');
  45. %
  46. % % EXAMPLE 2:
  47. % % Read records 3 and 5, associated with file 'ecgca998.edf':
  48. %
  49. % header = edfRead('ecgca998.edf','AssignToVariables',true);
  50. % % Header file specifies data labels 'label_1'...'label_n'; these are
  51. % % created as variables in the caller workspace.
  52. %
  53. % Coded 8/27/09 by Brett Shoelson, PhD
  54. % brett.shoelson@mathworks.com
  55. % Copyright 2009 - 2012 MathWorks, Inc.

  56. % HEADER RECORD
  57. % 8 ascii : version of this data format (0)
  58. % 80 ascii : local patient identification
  59. % 80 ascii : local recording identification
  60. % 8 ascii : startdate of recording (dd.mm.yy)
  61. % 8 ascii : starttime of recording (hh.mm.ss)
  62. % 8 ascii : number of bytes in header record
  63. % 44 ascii : reserved
  64. % 8 ascii : number of data records (-1 if unknown)
  65. % 8 ascii : duration of a data record, in seconds
  66. % 4 ascii : number of signals (ns) in data record
  67. % ns * 16 ascii : ns * label (e.g. EEG FpzCz or Body temp)
  68. % ns * 80 ascii : ns * transducer type (e.g. AgAgCl electrode)
  69. % ns * 8 ascii : ns * physical dimension (e.g. uV or degreeC)
  70. % ns * 8 ascii : ns * physical minimum (e.g. -500 or 34)
  71. % ns * 8 ascii : ns * physical maximum (e.g. 500 or 40)
  72. % ns * 8 ascii : ns * digital minimum (e.g. -2048)
  73. % ns * 8 ascii : ns * digital maximum (e.g. 2047)
  74. % ns * 80 ascii : ns * prefiltering (e.g. HP:0.1Hz LP:75Hz)
  75. % ns * 8 ascii : ns * nr of samples in each data record
  76. % ns * 32 ascii : ns * reserved

  77. % DATA RECORD
  78. % nr of samples[1] * integer : first signal in the data record
  79. % nr of samples[2] * integer : second signal
  80. % ..
  81. % ..
  82. % nr of samples[ns] * integer : last signal

  83. if nargin > 3
  84.     error('EDFREAD: Too many input arguments.');
  85. end

  86. if ~nargin
  87.     error('EDFREAD: Requires at least one input argument (filename to read).');
  88. end

  89. if nargin == 1
  90.     assignToVariables = false;
  91. end

  92. [fid,msg] = fopen(fname,'r');
  93. if fid == -1
  94.     error(msg)
  95. end

  96. assignToVariables = false; %Default
  97. for ii = 1:2:numel(varargin)
  98.     switch lower(varargin{ii})
  99.         case 'assigntovariables'
  100.             assignToVariables = varargin{ii+1};
  101.     end
  102. end

  103. % HEADER
  104. hdr.ver        = str2double(char(fread(fid,8)'));
  105. hdr.patientID  = fread(fid,80,'*char')';
  106. hdr.recordID   = fread(fid,80,'*char')';
  107. hdr.startdate  = fread(fid,8,'*char')';% (dd.mm.yy)
  108. % hdr.startdate  = datestr(datenum(fread(fid,8,'*char')','dd.mm.yy'), 29); %'yyyy-mm-dd' (ISO 8601)
  109. hdr.starttime  = fread(fid,8,'*char')';% (hh.mm.ss)
  110. % hdr.starttime  = datestr(datenum(fread(fid,8,'*char')','hh.mm.ss'), 13); %'HH:MM:SS' (ISO 8601)
  111. hdr.bytes      = str2double(fread(fid,8,'*char')');
  112. reserved       = fread(fid,44);
  113. hdr.records    = str2double(fread(fid,8,'*char')');
  114. hdr.duration   = str2double(fread(fid,8,'*char')');
  115. % Number of signals
  116. hdr.ns    = str2double(fread(fid,4,'*char')');
  117. for ii = 1:hdr.ns
  118.     hdr.label{ii} = fread(fid,16,'*char')';
  119. end
  120. for ii = 1:hdr.ns
  121.     hdr.transducer{ii} = fread(fid,80,'*char')';
  122. end
  123. % Physical dimension
  124. for ii = 1:hdr.ns
  125.     hdr.units{ii} = fread(fid,8,'*char')';
  126. end
  127. % Physical minimum
  128. for ii = 1:hdr.ns
  129.     hdr.physicalMin(ii) = str2double(fread(fid,8,'*char')');
  130. end
  131. % Physical maximum
  132. for ii = 1:hdr.ns
  133.     hdr.physicalMax(ii) = str2double(fread(fid,8,'*char')');
  134. end
  135. % Digital minimum
  136. for ii = 1:hdr.ns
  137.     hdr.digitalMin(ii) = str2double(fread(fid,8,'*char')');
  138. end
  139. % Digital maximum
  140. for ii = 1:hdr.ns
  141.     hdr.digitalMax(ii) = str2double(fread(fid,8,'*char')');
  142. end
  143. for ii = 1:hdr.ns
  144.     hdr.prefilter{ii} = fread(fid,80,'*char')';
  145. end
  146. for ii = 1:hdr.ns
  147.     hdr.samples(ii) = str2double(fread(fid,8,'*char')');
  148. end
  149. for ii = 1:hdr.ns
  150.     reserved    = fread(fid,32,'*char')';
  151. end
  152. hdr.label = deblank(hdr.label);
  153. hdr.units = deblank(hdr.units);


  154. if nargout > 1 || assignToVariables
  155.     % Scale data (linear scaling)
  156.     scalefac = (hdr.physicalMax - hdr.physicalMin)./(hdr.digitalMax - hdr.digitalMin);
  157.     dc = hdr.physicalMax - scalefac .* hdr.digitalMax;
  158.    
  159.     % RECORD DATA REQUESTED
  160.     tmpdata = struct;
  161.     for recnum = 1:hdr.records
  162.         for ii = 1:hdr.ns
  163.             % Use a cell array for DATA because number of samples may vary
  164.             % from sample to sample
  165.             tmpdata(recnum).data{ii} = fread(fid,hdr.samples(ii),'int16') * scalefac(ii) + dc(ii);
  166.         end
  167.     end
  168.     record = zeros(hdr.ns, hdr.samples(1)*hdr.records);
  169.    
  170.     for ii = 1:numel(hdr.label)
  171.         ctr = 1;
  172.         for jj = 1:hdr.records
  173.             try
  174.                 record(ii, ctr : ctr + hdr.samples - 1) = tmpdata(jj).data{ii};
  175.             end
  176.             ctr = ctr + hdr.samples;
  177.         end
  178.     end
  179.    
  180.     if assignToVariables
  181.         for ii = 1:numel(hdr.label)
  182.             try
  183.                 eval(['assignin(''caller'',''',hdr.label{ii},''',record(ii,:))'])
  184.             end
  185.         end
  186.     end
  187. end
  188. fclose(fid);
复制代码
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-16 02:44 , Processed in 0.064708 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表