diff --git a/klusta/nlx2DAT.m b/klusta/nlx2DAT.m index 3997b25..d244569 100644 --- a/klusta/nlx2DAT.m +++ b/klusta/nlx2DAT.m @@ -1,4 +1,4 @@ -function nlx2DAT(animal, experiments, channels, folder2save) +function nlx2DAT(animal, experiments, channels, broken_channels, folder2save, common_average_reference) % by Mattia 8.11.18 based on https://github.com/kwikteam/klusta/issues/48 @@ -33,23 +33,18 @@ function nlx2DAT(animal, experiments, channels, folder2save) % nints = round((memsize.MaxPossibleArrayBytes / 6) * 0.95); % find all the experiments for the animal that you want to spike sort -experiments_animal = structfind(experiments, 'animal_ID', animal); +experiments_animal = structfind(experiments, 'animal_ID', animal); % loop over the experiments for experiment = experiments(experiments_animal) -% disp(strcat('writing_experiment_', experiment.name)) + % disp(strcat('writing_experiment_', experiment.name)) % load first file just to calculate the number of block in which you want % to partition your recording ExtractMode = 1; file_to_load = strcat(experiment.path, experiment.name, filesep, 'CSC', num2str(channels(1)), '.ncs'); [~, temp, ~] = load_nlx_Modes(file_to_load, ExtractMode, []); clength = length(temp); -% nintsdata = 2 * clength * numel(channels); -% -% % Partition size of data -% nBlocks = ceil(nintsdata / nints); -% blocksize = round(nints / numel(channels)); % Create output file fname = experiment.name; @@ -59,30 +54,20 @@ function nlx2DAT(animal, experiments, channels, folder2save) %% write data -% fprintf('Saving block 000/000 -ch00') -% for blockNR = 1 : nBlocks - - % Index for chunk -% IDX(1) = (blockNR - 1) * blocksize + 1; -% IDX(2) = blockNR * blocksize; - -% if IDX(2) > clength && blockNR == 1 -% IDX(2) = clength; -% end - -% samples = zeros(length(channels), IDX(2) - IDX(1) + 1, 'int16'); - samples = zeros(length(channels), clength, 'int16'); -% fprintf('\t-ch01'); - for channel_idx = 1 : length(channels) -% fprintf('\b\b%2d', channel_idx); + samples = zeros(length(channels), clength, 'int16'); + for channel_idx = 1 : length(channels) + if ~ ismember(channels(channel_idx), broken_channels) file_to_load = strcat(experiment.path, experiment.name, filesep, 'CSC', ... num2str(channels(channel_idx)), '.ncs'); [~, samples(channel_idx, :), ~] = load_nlx_Modes(file_to_load, ExtractMode, []); end - - fwrite(fidout, samples, 'int16'); - -% end + end + if common_average_reference == 1 + samples(~ ismember(channels, broken_channels), :) = ... + samples(~ ismember(channels, broken_channels), :) - ... + int16(mean(samples(~ ismember(channels, broken_channels), :))); % common average reference + end + fwrite(fidout, samples, 'int16'); fclose(fidout); end end