Code covered by the BSD License  

Highlights from
Minimal Stimulation analysis for pClamp

from Minimal Stimulation analysis for pClamp by Chessa Scullin
paired pulse traces from a abf file and make comparisons to an average trace

import_abfminstimfiltered(file, en, dt)
function [data] = import_abfminstimfiltered(file, en, dt)

%     This script partly incorporated the matlab script getpc6header.m,
%     originally conceived and written by Carsten Hohnke
%     (http://www.ai.mit.edu/people/ch/).
%      taken from the matlab website then adapted to use with abf files 
%       pClamp 10 of specific length by Chessa Scullin
    
% Let's check the number and the type of input arguments.
if nargin < 2
  error('Function requires two input argument (the ABF filename and the en)');
elseif ~isstr(file)
  error('Input must be a string representing an ABF filename');
end % if

fid = fopen(file);              % Open the file.  If this returns a -1, we did not open the file successfully.
if fid==-1
 error(sprintf('File %s has not been found or permission denied',file));
 return;
end % if


fseek(fid,12,'bof');
h.lActualEpisodes=fread(fid,1,'int');
h.size=5120;
s.size=0;
fseek(fid,100,'bof');
h.nADCNumChannels=fread(fid,1,'short');

fseek(fid,244,'bof');
h.lActualAcqLength=fread(fid,1,'int');
fseek(fid,12,'bof');
h.lActualEpisodes=fread(fid,1,'int');

h.fHeaderVersionNumber=2;

fseek(fid,30,'bof');
h.nDataFormat=fread(fid,1,'short');

fseek(fid,622,'bof');
h.fADCRange=fread(fid,1,'float');
fseek(fid,630,'bof');
h.lADCResolution=fread(fid,1,'int');

fseek(fid,1064,'bof');%1064,1192
h.fInstrumentScaleFactor(1)=fread(fid,1,'float');
fseek(fid,1192,'bof');%1064,1192
h.fInstrumentScaleFactor(2)=fread(fid,1,'float');

h.x_fAutosampleAdditGain=1;

fseek(fid,1052,'bof');%1052,1180
h.fADCProgrammableGain(1)=fread(fid,1,'float');
if (h.nADCNumChannels==2);
fseek(fid,1180,'bof');%1052,1180
h.fADCProgrammableGain(2)=fread(fid,1,'float');
end;

fseek(fid,1072,'bof');%1072,1200
h.fSignalGain(1)=fread(fid,1,'float');
if (h.nADCNumChannels==2);
fseek(fid,1200,'bof');%1072,1200
h.fSignalGain(2)=fread(fid,1,'float');
end;
fseek(fid,1076,'bof');%1076,1204
h.fSignalOffset(1)=fread(fid,1,'float');
if (h.nADCNumChannels==2);
fseek(fid,1204,'bof');%1076,1204
h.fSignalOffset(2)=fread(fid,1,'float');
end;

ne = h.lActualEpisodes;      % Get the number of episodes contained in the data file...
if en < 1 | en > ne,         % and check for valid value of the user request.
   error('Invalid episode number.');
end

Nchan = h.nADCNumChannels;
ns    = h.lActualAcqLength / h.lActualEpisodes;
%ns=24000;
if (h.fHeaderVersionNumber >= 1.6)
 fseek(fid, (h.size+s.size) + (en-1)*2*ns, 'bof');
else
 fseek(fid, (2048+s.size)+370 + (en-1) * 2 * ns, 'bof'); % UNTESTED!
end 

if (h.nDataFormat == 0) % Data representation. 0 = 2-byte integer; 1 = IEEE 4 byte float.
 xdata = fread(fid, ns, 'short');
else
 xdata = fread(fid, ns, 'float');
end 

 eval('xdata = reshape(xdata, Nchan, length(xdata)/Nchan)'';', '');
 data      = [];
 data      = zeros(size(xdata,1),Nchan+1);
 data(:,1) = dt*(0:size(xdata,1)-1)';
 
  for chan=1:Nchan,
  gain(chan)   = h.fADCRange / h.lADCResolution / (h.fInstrumentScaleFactor(chan) * h.x_fAutosampleAdditGain * h.fADCProgrammableGain(chan) * h.fSignalGain(chan));
  offset(chan) = h.fSignalOffset(chan);
  data(:,chan+1) = xdata(:,chan) * gain(chan) + offset(chan);  
 end 
 fclose(fid);

Contact us at files@mathworks.com