Hi Sebastian and everyone,
Since there appears to be a problem with opening the old zip file, and
since I'm unable to transfer any file from my HCUGE PC to this group,
I will simply paste a few of the scripts below. I include the
following:
- openeph.m
- opensef.m
- computeavgref.m
- computedataagainstref.m
- computegfp.m
- computedissandsc.m
- saveeph.m
- savesef.m
All these scripts have a header with a short description of the
variable names and formats used.
All the caveats in my original posting remain! (
http://www.google.com/
url?sa=D&q=
http://groups.google.com/group/cartool/browse_thread/thread/
162d69ff4e5b8ae8/4973bf8165ff4e62%3Flnk%3Dgst%26q%3Ddissimilarity
%234973bf8165ff4e62&usg=AFQjCNHMeIfzTzPT33feWVpQbhfYne4r4A)
Please signal here any problem with these scripts.
Pierre (PS the e-mail address mentioned in the scripts does no longer
exist: please use
pierre....@gmail.com)
function
[numchannels,numtimeframes,samplingrate,thedata]=openeph(openfilename)
% openeph: opens a Cartool evoked potential data file (.ep(h))
%
% inputs: full path and name of the file to open
%
% outputs: number of channels, number of timeframes (and sampling rate
for
% .eph files) as 1-D numeric arrays; data as a 2-D numeric array where
% dimension 1 contains the timeframes, dimension 2 contains the
channels
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
% open filename for reading in text mode
fid=fopen(openfilename,'rt');
% for .eph files
if strcmp(openfilename(end-3:end),'.eph')==1
% read header
eph=textscan(fid,'%s','delimiter','/n');
eph=eph{1};
numchannels=sscanf(eph{1},'%f',1);
numtimeframes=sscanf(eph{1},'%*f %f',1);
samplingrate=sscanf(eph{1},'%*f %*f %f',1);
% prepare for reading data
formatstring='%f';
if numchannels>1
for i=1:numchannels-1
formatstring=[formatstring ' %f'];
end
end
% read data
thedata=zeros(numtimeframes,numchannels);
for i=1:numtimeframes
thedata(i,:)=sscanf(eph{i+1},formatstring);
end
% for .ep files
elseif strcmp(openfilename(end-2:end),'.ep')==1
thedata='';
while ~feof(fid)
thedataline=fgetl(fid);
thedata=strvcat(thedata,thedataline);
end
thedata=str2num(thedata);
numtimeframes=size(thedata,1);
numchannels=size(thedata,2);
samplingrate=0;
else
error('incorrect file type');
end
% close file
fclose(fid);
function
[numchannels,numtimeframes,samplingrate,thedata]=opensef(openfilename)
% opensef: opens a Cartool simple EEG data file (.sef)
%
% inputs: full path and name of the file to open
%
% outputs: number of channels, number of timeframes and sampling rate
as
% 1-D numeric arrays; data as a 2-D numeric array where dimension 1
% contains the timeframes, dimension 2 contains the channels
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
% open filename for reading
fid=fopen(openfilename,'r');
% read fixed part of header
version=strcat(fread(fid,4,'int8=>char')');
numchannels=fread(fid,1,'int32');
numauxchannels=fread(fid,1,'int32');
numtimeframes=fread(fid,1,'int32');
samplingrate=fread(fid,1,'float32');
year=fread(fid,1,'int16');
month=fread(fid,1,'int16');
day=fread(fid,1,'int16');
hour=fread(fid,1,'int16');
minute=fread(fid,1,'int16');
second=fread(fid,1,'int16');
millisecond=fread(fid,1,'int16');
% read variable part of header
channels=strcat(fread(fid,[8,numchannels],'int8=>char')');
% read data
thedata=fread(fid,[numchannels,numtimeframes],'float32')';
% close file
fclose(fid);
function avgref=computeavgref(thedata)
% computeavgref: computes the average reference of a data set
%
% inputs: data as a 2-D numeric array where dimension 1 contains the
% timeframes, dimension 2 contains the channels
%
% outputs: average reference as a 1-D numeric array that contains the
% average reference at each timeframe
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
% define number of channels and time frames
numtimeframes=size(thedata,1);
numchannels=size(thedata,2);
% compute average reference
avgref=zeros(numtimeframes,1);
for i=1:numtimeframes
avgref(i)=sum(thedata(i,:))/numchannels;
end
function thedata=computedataagainstref(thedata,ref)
% computedataagainstref: changes the reference of a data set
%
% inputs: data as a 2-D numeric array where dimension 1 contains the
% timeframes, dimension 2 contains the channels; ref as either a
number
% (1-D numeric array) or the 'avgref' string for average reference
%
% outputs: data as a 2-D numeric array where dimension 1 contains the
% timeframes, dimension 2 contains the channels
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
% define number of channels and time frames
numtimeframes=size(thedata,1);
numchannels=size(thedata,2);
% compute data against selected reference
if ischar(ref)==1&strcmp(ref,'avgref')==1
avgref=computeavgref(thedata);
for i=1:numtimeframes
thedata(i,:)=thedata(i,:)-avgref(i);
end
elseif ischar(ref)==1&strcmp(ref,'avgref')==0
error('Unknown code for reference');
elseif isnumeric(ref)==1&ref>=1&ref<=numchannels
for i=1:numtimeframes
thedata(i,:)=thedata(i,:)-thedata(i,ref);
end
elseif isnumeric(ref)==1&(ref<1|ref>numchannels);
error('Reference specified does not exist');
end
function gfp=computegfp(thedata)
% computegfp: calculates the global field power of a data set
%
% inputs: data as a 2-D numeric array where dimension 1 contains the
% timeframes, dimension 2 contains the channels
%
% outputs: global field power as a 1-D numeric array that contains the
% global field power at each timeframe
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
% define number of channels and time frames
numtimeframes=size(thedata,1);
numchannels=size(thedata,2);
% compute global field power
gfp=zeros(numtimeframes,1);
avgref=computeavgref(thedata);
for i=1:numtimeframes
gfp(i)=sqrt(sum((thedata(i,:)-avgref(i)).^2)/numchannels);
end
function [diss,sc]=computedissandsc(thedata1,thedata2)
% computediss: computes dissimilarity and spatial correlation between
2
% data sets
%
% inputs: data as 2-D numeric arrays where dimension 1 contains the
% timeframes, dimension 2 contains the channels
%
% outputs: diss and sc as 1-D numeric arrays that contain the
% dissimilarity and spatial correlation at each timeframe
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
% verify equal number of channels and time frames
if size(thedata1,1)~=size(thedata2,1)
error('Number of timeframes is different');
elseif size(thedata1,2)~=size(thedata2,2)
error('Number of channels is different');
end
% compute dissimilarity
diss=zeros(size(thedata1,1),1);
for i=1:size(thedata1,1)
diss(i)=sqrt(sum((thedata1(i,:)-thedata2(i,:)).^2)/
size(thedata1,2));
end
% compute spatial correlation
sc=zeros(size(diss,1),1);
for i=1:size(diss,1)
sc(i)=(2-diss(i)^2)/2;
end
function saveeph(savefilename,thedata,varargin)
% saveeph: saves data as a Cartool evoked potential data file (.ep(h/
sd/se))
%
% inputs: full path and name of the file to save, data as a 2-D
numeric
% array where dimension 1 contains the timeframes, dimension 2
contains the
% channels, (optional) samplingrate as 1-D numeric array passed as
% 3rd argument
%
% outputs: .ep(h/sd/se) file
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
if strcmp(savefilename(end-3:end),'.eph')==1
numtimeframes=size(thedata,1);
numchannels=size(thedata,2);
samplingrate=varargin{1};
theheader=[numchannels numtimeframes samplingrate];
dlmwrite(savefilename,theheader,'\t');
dlmwrite(savefilename,thedata,'delimiter','\t','-append');
elseif strcmp(savefilename(end-2:end),'.ep')==1
dlmwrite(savefilename,thedata,'delimiter','\t','-append');
elseif strcmp(savefilename(end-4:end),'.epsd')==1|
strcmp(savefilename(end-4:end),'.epse')==1
if nargin==2
dlmwrite(savefilename,thedata,'delimiter','\t','-append');
elseif nargin==3
numtimeframes=size(thedata,1);
numchannels=size(thedata,2);
samplingrate=varargin{1};
theheader=[numchannels numtimeframes samplingrate];
dlmwrite(savefilename,theheader,'\t');
dlmwrite(savefilename,thedata,'delimiter','\t','-append');
end
end
function savesef(savefilename,thedata,samplingrate)
% savesef: saves data as a Cartool simple EEG data file (.sef)
%
% inputs: full path and name of the file to save, data as a 2-D
numeric
% array where dimension 1 contains the timeframes, dimension 2
contains the
% channels, samplingrate as 1-D numeric array
%
% outputs: .sef file
%
% Cartool:
http://brainmapping.unige.ch/Cartool.htm
%
% author of this script:
pierre....@medecine.unige.ch
% define fixed part of header
version='SE01';
numchannels=size(thedata,2);
numauxchannels=0;
numtimeframes=size(thedata,1);
year=0;
month=0;
day=0;
hour=0;
minute=0;
second=0;
millisecond=0;
% open savefilename for writing
fid=fopen(savefilename,'w');
%write fixed part of header
fwrite(fid,version,'int8');
fwrite(fid,numchannels,'int32');
fwrite(fid,numauxchannels,'int32');
fwrite(fid,numtimeframes,'int32');
fwrite(fid,samplingrate,'float32');
fwrite(fid,year,'int16');
fwrite(fid,month,'int16');
fwrite(fid,day,'int16');
fwrite(fid,hour,'int16');
fwrite(fid,minute,'int16');
fwrite(fid,second,'int16');
fwrite(fid,millisecond,'int16');
% define and write variable part of header
for i=1:numchannels
fwrite(fid,101,'int8');
currentchannel=uint8(num2str(i));
for j=1:size(currentchannel,2)
fwrite(fid,currentchannel(j),'int8');
end
for k=j+2:8
fwrite(fid,0,'int8');
end
end
% write data
count=fwrite(fid,thedata','float32');
% close file
fclose(fid);
> > does not lead to a page. Thanks Google Group... :-(- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -