0001 function status = lap_ns_data(rawfname,Max_microv,Min_Chan);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 if nargin < 1
0012 [fid, fname, pathname] = get_fid('rb','*.*');
0013 rawfname = [fname];
0014 else
0015 fid = fopen(rawfname,'rb');
0016 end;
0017
0018 if rawfname == []
0019 [fid, fname, pathname] = get_fid('rb','*.*');
0020 end
0021 if nargin < 2
0022 Max_microv = 100;
0023 Min_Chan = 100;
0024 end;
0025
0026 [header_array, EventCodes,Samp_Rate, NChan, scale, NSamp, NEvent] = rd_fragger_hdr(fid);
0027 [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mask] = ns_artifact_edit(fid,Samp_Rate,NChan, NSamp, NEvent,scale,1,Max_microv,Min_Chan);
0028 frewind(fid);
0029 [header_array, EventCodes,Samp_Rate, NChan, scale, NSamp, NEvent] = rd_fragger_hdr(fid);
0030 header_array(13) = header_array(13)/100;
0031 header_array(10) = NChan + 1;
0032 header_array(14) = Samp_Rate*NEpoch;
0033 [xelec,yelec,zelec] = electrodes(NChan+1);
0034 lap_filename = [rawfname '_lap'];
0035 lapfid = fopen(lap_filename,'wb');
0036
0037 wt_fragger_hdr(lapfid,header_array,EventCodes);
0038 for i = 1:NEpoch
0039 if sum(mask(i,:)) > 1
0040 trialdata = zeros(NChan+NEvent,Samp_Rate);
0041 trialdata = fread(fid,[NChan+NEvent,Samp_Rate],'int16');
0042 trialdata = trialdata';
0043 trialdata2 = zeros(Samp_Rate,NChan+1);
0044 trialdata2(:,1:NChan) = trialdata(:,1:NChan);
0045 good_chan = find(mask(i,:));
0046 lap_trialdata2 = laplacian_trial(trialdata2,good_chan,xelec,yelec,zelec);
0047 plot(lap_trialdata2(:,73));
0048 lap_trialdata2 = 100*lap_trialdata2';
0049 lap_trialdata = zeros(NChan+1+NEvent,Samp_Rate);
0050 lap_trialdata(NChan+2:NChan+1+NEvent,:) = trialdata(NChan+1:NChan+NEvent,:);
0051 lap_trialdata(1:NChan+1,:) = lap_trialdata2;
0052 figure
0053 plot(lap_trialdata(73,:));
0054 else
0055 lap_trialdata = zeros(NChan+1+NEvent,Samp_Rate);
0056 end
0057 fwrite(lapfid,lap_trialdata,'int16');
0058 end;
0059 fclose(fid);
0060 fclose(lapfid);
0061