gb_cutting_sweeps.m 1011 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. function [sweep_cut, sweep_time,sweep_points] = gb_cutting_sweeps(cfg, data)
  2. sweep_start = round(cfg.start_time*cfg.SR);
  3. sweep_end = round(cfg.end_time*cfg.SR);
  4. for x = 1:length(cfg.sp_trigger)
  5. sweep_points{x} = sweep_start+cfg.sp_trigger(x):cfg.sp_trigger(x)+sweep_end;
  6. sweep_cut{x} = data(sweep_points{x});
  7. if isfield(cfg, 'baseline_rectify')
  8. % rectify epoch
  9. sweep_cut{x} = abs(sweep_cut{x});
  10. bs_start = round(cfg.baseline_rectify(1)*cfg.SR);
  11. bs_end = round(cfg.baseline_rectify(2)*cfg.SR);
  12. bs_points{x} = bs_start+cfg.sp_trigger(x):cfg.sp_trigger(x)+bs_end;
  13. bs_cut{x} = abs(data(bs_points{x}));
  14. % identify mean of the baselined period
  15. baselined_chunk = mean(bs_cut{x},2);
  16. % subtract the mean from the baselined period from the rectified epoch
  17. sweep_cut{x} = sweep_cut{x} - baselined_chunk;
  18. end
  19. end
  20. sweep_time = linspace(cfg.start_time,cfg.end_time, length(sweep_points{1})) ;