loadEEG.m
上传用户:xhrjvip
上传日期:2020-11-07
资源大小:2k
文件大小:1k
- function [EEGmatrix,tsample]=loadEEG(filenm, numdl, smpf)
- %%%%%%%%%%%%%%
- % input:
- % filenm: file name Exp: filenm = '008.eeg';
- % numdl: the numbers of daolian, Exp: numdl = 33;
- % smpf : sample frequency, Exp: smpf = 210; Hz
- % output:
- % EEGmatrix: 输出的EEG矩阵,行为采样的数,列为channel, units: uv
- % tsample: 采样点对应的时间, units: s
- numd1=33;
- n = nargin;
- if n < 2
- disp('Insuficient arguments');
- disp('Please input filename or num of dl');
- end
- if n < 3
- smpf = 512; % Hz sample frequency
- end
- fid = fopen(filenm,'rb'); % 二进制打开文件
- if (fid <=0)
- error([ 'Error opening file "' filenm '"' ]);
- end
- EEGdata=fread(fid, 'short')-2047;
- %EEGdata=fread(fid, 'short');
- % 16位 short
- %EEGdata(find(EEGdata<0)) = 0; % if <0 =0
- fclose(fid);
- nsample = size(EEGdata, 1) / numdl; % size(EEGdata, 1) denotes EEGdata numbers of rows; get numbers of sample
- EEGmatrix = reshape(EEGdata, [numdl, nsample]); % reshape the matrix into nsample * channel
- tsample = (1:nsample)/smpf; % translate nsample to time
- clear EEGdata;
- EEGmatrix = EEGmatrix * 500.0 / 2048; % translate binary into value