int_spikes.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function [spikes1] = int_spikes(spikes,handles);
  2. %Interpolates with cubic splines to improve alignment.
  3. w_pre=handles.w_pre;
  4. w_post=handles.w_post;
  5. ls = w_pre + w_post;
  6. detect = handles.detection;
  7. int_factor = handles.int_factor;
  8. nspk=size(spikes,1);
  9. s=1:size(spikes,2);
  10. ints=1/int_factor:1/int_factor:size(spikes,2);
  11. intspikes=zeros(1,length(ints));
  12. spikes1=zeros(nspk,ls);
  13. switch detect
  14. case 'pos'
  15. for i=1:nspk
  16. intspikes(:) = spline(s,spikes(i,:),ints);
  17. [maxi, iaux]=max((intspikes(w_pre*int_factor:w_pre*int_factor+8)));
  18. iaux = iaux + w_pre*int_factor -1;
  19. spikes1(i,w_pre:-1:1) = intspikes(iaux:-int_factor:iaux-w_pre*int_factor+int_factor);
  20. spikes1(i,w_pre+1:ls) = intspikes(iaux+int_factor:int_factor:iaux+w_post*int_factor);
  21. end
  22. case 'neg'
  23. for i=1:nspk
  24. intspikes(:) = spline(s,spikes(i,:),ints);
  25. [maxi, iaux]=min((intspikes(w_pre*int_factor:w_pre*int_factor+8)));
  26. iaux = iaux + w_pre*int_factor -1;
  27. spikes1(i,w_pre:-1:1) = intspikes(iaux:-int_factor:iaux-w_pre*int_factor+int_factor);
  28. spikes1(i,w_pre+1:ls) = intspikes(iaux+int_factor:int_factor:iaux+w_post*int_factor);
  29. end
  30. case 'both'
  31. for i=1:nspk
  32. intspikes(:) = spline(s,spikes(i,:),ints);
  33. [maxi, iaux]=max(abs(intspikes(w_pre*int_factor:w_pre*int_factor+8)));
  34. iaux = iaux + w_pre*int_factor -1;
  35. spikes1(i,w_pre:-1:1) = intspikes(iaux:-int_factor:iaux-w_pre*int_factor+int_factor);
  36. spikes1(i,w_pre+1:ls) = intspikes(iaux+int_factor:int_factor:iaux+w_post*int_factor);
  37. end
  38. end