Improve the importing method used for blackrock data

Hi,
Within the current version BS, you use the following code to import data for blackrock (.NSx)

rec = openNSx('read', sFile.filename, 'channels', iChannels , 'sample', strSamples, strPrecision, 'uV');

But, the 'uV' format will introduce some lose of accuracy caused by dataformat transforming. It can be solved with a very simple way that used by fieldtrip (modified version. Fieldtrip has a bug to handle data transforming, I have send issue to them, Should I divide the blackrock data with 4? · Issue #2102 · fieldtrip/fieldtrip · GitHub):

orig = openNSx(filename, 'channels',find(chan_sel),...
      'duration', [(begsample-1)*hdr.orig.skipfactor+1, endsample*hdr.orig.skipfactor],...
      'skipfactor', hdr.orig.skipfactor);
    
d_min=double([orig.ElectrodesInfo.MinDigiValue]);
d_max=double([orig.ElectrodesInfo.MaxDigiValue]);
v_min=double([orig.ElectrodesInfo.MinAnalogValue]);
v_max=double([orig.ElectrodesInfo.MaxAnalogValue]);
 
%calculating slope (a) and ordinate (b) of the calibration
b=double(v_min .* d_max - v_max .* d_min) ./ double(d_max - d_min);
a=double(v_max-v_min)./double(d_max-d_min);
    
%apply v = a*d + b to each row of the matrix
dat=bsxfun(@plus,bsxfun(@times, double(orig.Data), a'),b');

Isn't this something you should submit to the NPMK library instead?
https://github.com/BlackrockNeurotech/NPMK

1 Like

Yes. Thank you for your suggestion.