get_snr.m 1.1 KB

12345678910111213141516171819202122232425262728
  1. function [SNR, SNRconservative] = get_snr(data,goodtrials,t,baselinewin)
  2. % this function calculates two different estimates of SNR, a normal one
  3. % and a conservative one.
  4. % input:
  5. % - data (has to be NORMALIZED so the peak response is 1)
  6. % - boolean array of good trials, only good trials are included in std
  7. % calculation
  8. % - time axis in same unit as baseline window
  9. % - [start end] baseline window
  10. %
  11. % Rob Teeuwen 20190815
  12. % first average the baseline window for each trial to get a single
  13. % baseline value per trial. then calculate the standard deviation
  14. % of all baseline values. divide 1 by this std (because we
  15. % normalized, so 1 is the peak response).
  16. bl = find(t>baselinewin(1) & t<baselinewin(2));
  17. baselines = nanmean(data(bl,goodtrials==1),1); % baselines is 1xtrls array
  18. SNR = 1/(std(baselines));
  19. % calculate a conservative SNR as well, first calculate the std for
  20. % each trial, then average the stds.
  21. baselinedev = std(data(bl,goodtrials==1));
  22. SNRconservative = 1/(mean(baselinedev));
  23. end