esc_measure.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function escval = esc_measure(ph_sig, amp_sig, avg)
  2. % function escval = esc_measure(ph_sig, amp_sig, avg)
  3. %
  4. % Returns a value (or vector of values) for the ESC measure calculated
  5. % between two signals. Signals may contain one of more trials. Multiple
  6. % trials may be averaged so as to return one ESC value or a vector of
  7. % ESC values calculated for each trial may be returned, depending on the
  8. % 'avg' argument. Signals should be passed as column vectors, multiple
  9. % trials stored as multiple columns.
  10. %
  11. % INPUTS:
  12. % ph_sig - signal filtered for a lower, modulating frequency (e.g. theta
  13. % band oscillations)
  14. %
  15. % amp_sig - signal filtered for a higher, modulated frequency (e.g. gamma
  16. % band oscillations)
  17. %
  18. % avg - string, either 'y' or 'n', determines whether ESC values are
  19. % averaged over trials or returned as a vector
  20. %
  21. % Author: Angela Onslow, May 2010
  22. escsum = 0;
  23. if size(ph_sig, 2) ~= size(amp_sig, 2)
  24. sprintf('Error - Signals must have the same number of trials')
  25. return
  26. end
  27. num_trials = size(ph_sig, 2);
  28. if strcmp(avg, 'y')
  29. %Average over trials using the Fisher transform
  30. for c = 1:num_trials
  31. r = corrcoef(ph_sig(:,c), amp_sig(:,c));
  32. escsum = escsum + atanh(r(1,2));
  33. end
  34. escsum = escsum/num_trials;
  35. escval = tanh(escsum);
  36. else
  37. escval = zeros(num_trials,1);
  38. for i = 1:num_trials
  39. r = corrcoef(ph_sig(:,i), amp_sig(:,i));
  40. escval(i,1) = r(1,2);
  41. end
  42. end