H5_ISI.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. % The script calculates the Inter Spike Intervals (ISIs) and plots the
  2. % results in a histogram. The proportion of ISIs violating a threshold
  3. % is also calculated and indicated in the histogram.
  4. % authors: Francesco E. Vaccari
  5. % date: 10/2022
  6. clear all; clc; close all;
  7. addpath('supportFunctions')
  8. currentFolder = pwd;
  9. parentFolder = fileparts(fileparts(currentFolder));
  10. [filename,path_folder_data] = uigetfile('*.h5','Select a h5 dataset',[parentFolder '\data']);
  11. str = '/DATA'; %it can be either unit_XXX, unit_XXX/condition_YY or unit_XXX/condition_YY/trial_ZZ
  12. threshold = 1; %threshold for violations in ms
  13. [data, all_strings] = get_all_data_from_level_h5_rec([path_folder_data filename],str, {}, {}); %extract data
  14. spikes = data(:,2);
  15. ISIs = cellfun(@diff, spikes, 'UniformOutput', false);
  16. ISIs = cell2mat(ISIs');
  17. violations = length(find(ISIs<threshold)) / numel(ISIs) * 100; %percentage over the total number of ISIs
  18. figure
  19. time = 0:0.5:100;
  20. histogram(ISIs,time);
  21. hold on
  22. xline(threshold,'--')
  23. xLimits = get(gca,'XLim');
  24. yLimits = get(gca,'YLim');
  25. text(xLimits(2)/4, yLimits(2)*2/3, ['Violations (ISI below ' num2str(threshold) 'ms threshold) = ' num2str(violations) '%'])
  26. xlabel('ISI duration (ms)')
  27. ylabel('events num.')
  28. title('ISI')