Home > bioelectromagnetism > convert_erps2brainstorm.m

convert_erps2brainstorm

PURPOSE ^

convert_erps2brainstorm - script to convert ascii to brainstorm ERP data

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 convert_erps2brainstorm - script to convert ascii to brainstorm ERP data

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 % convert_erps2brainstorm - script to convert ascii to brainstorm ERP data
0003 
0004 
0005 %clear all
0006 
0007 
0008 data = 'd:\matlab\brainstorm_v1\studies\';
0009 
0010 cd(data);
0011 
0012 datapath = pwd;
0013 
0014 % Load the averaged data
0015 sample_rate = 2.5;
0016 epoch_start = -200;
0017 epoch_end = 1500;
0018 points = 681;
0019 
0020 % --- Setup data structures for timing array
0021 
0022 timeArray = meshgrid(epoch_start:sample_rate:epoch_end,1)';
0023 timeNonZero = find(timeArray);
0024 timeZero = find(timeArray == 0);
0025 
0026 % Load data
0027 for g = {'c','p'},
0028     
0029     if strcmp(g,'c'),
0030         
0031         for s = 1:10,
0032             
0033             sdir = sprintf('%s%02d',char(g),s);
0034             cd(sdir)
0035             
0036             for c = {'o','oac','oat','ouc','out','t','tac','tad','tat','tuc','tud','tut'},
0037                 
0038                 file = sprintf('%s%02d%s.dat',char(g),s,char(c));
0039                 volt = sprintf('%s%02d%s',    char(g),s,char(c));
0040                 
0041                 channelfile = sprintf('%s%02d_channel.mat',char(g),s)
0042                 if exist(channelfile) == 2,
0043                     load(channelfile,'Channel')
0044                     channelfile = sprintf('%s%02d_%s_volts_channel.mat',char(g),s,char(c))
0045                     save(channelfile,'Channel')
0046                     clear Channel
0047                 end
0048                 
0049                 if ~exist(volt,'var')
0050                     
0051                     fprintf('loading ascii %s\n',file);
0052                     load(file);
0053                     
0054                     % Interpolate the Zero value
0055                     V = eval(volt)';
0056                     InterpZero = interp1( timeArray(timeNonZero), V, 0, 'cubic' );
0057                     V = [V(1:timeZero-1,:); InterpZero; V(timeZero:end,:)];
0058                     eval(strcat(volt,' = V'';'));
0059                     
0060                     % Convert and save into brainstorm file
0061                     
0062                     data.Time = timeArray' ./ 1000; % in seconds
0063                     data.F    = eval(volt) ./ 10^6; % in Volts
0064                     
0065                     %data.F(125,:) = zeros(1,size(data.F,2)); % create zero ref data
0066                     %data.F(125,:) = mean(data.F(1:124,:));   % create avg  ref data??
0067                     
0068                     fileprefix = sprintf('%s%02d_%s_volts',char(g),s,char(c));
0069                     eeg_write_brainstorm(fileprefix,data);
0070                     
0071                 else
0072                     fprintf('Already loaded %s\n',file);
0073                 end
0074                 
0075                 
0076             end
0077             cd ..
0078         end
0079         
0080     else
0081         
0082         for s = [2 4:9],
0083             
0084             sdir = sprintf('%s%02d',char(g),s);
0085             cd(sdir)
0086             
0087             for c = {'o','oac','oat','ouc','out','t','tac','tad','tat','tuc','tud','tut'},
0088                 
0089                 file = sprintf('%s%02d%s.dat',char(g),s,char(c));
0090                 volt = sprintf('%s%02d%s',    char(g),s,char(c));
0091                 
0092                 channelfile = sprintf('%s%02d_channel.mat',char(g),s)
0093                 if exist(channelfile) == 2,
0094                     load(channelfile,'Channel')
0095                     channelfile = sprintf('%s%02d_%s_volts_channel.mat',char(g),s,char(c))
0096                     save(channelfile,'Channel')
0097                     clear Channel
0098                 end
0099                 
0100                 if ~exist(volt,'var')
0101                     fprintf('loading ascii %s\n',file);
0102                     load(file);
0103                     
0104                     % Interpolate the Zero value
0105                     V = eval(volt)';
0106                     InterpZero = interp1( timeArray(timeNonZero), V, 0, 'cubic' );
0107                     V = [V(1:timeZero-1,:); InterpZero; V(timeZero:end,:)];
0108                     eval(strcat(volt,' = V'';'));
0109                     
0110                     % Convert and save into brainstorm file
0111                     
0112                     data.Time = timeArray' ./ 1000; % in seconds
0113                     data.F    = eval(volt) ./ 10^6; % in Volts
0114                     
0115                     %data.F(125,:) = zeros(1,size(data.F,2)); % create zero ref data
0116                     %data.F(125,:) = mean(data.F(1:124,:));   % create avg  ref data??
0117                     
0118                     fileprefix = sprintf('%s%02d_%s_volts',char(g),s,char(c));
0119                     eeg_write_brainstorm(fileprefix,data);
0120                     
0121                 else
0122                     fprintf('Already loaded %s\n',file);
0123                 end
0124                 
0125             end
0126             cd ..
0127         end
0128     end
0129 end
0130 clear timeZero timeNonZero g c file volt V InterpZero

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003