indfrequency.m 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. function res = indfrequency(this, f)
  2. % Method for getting the index closest to given frequency
  3. % FORMAT res = indfrequency(this, f)
  4. % this - MEEG object
  5. % f - vector of frequencies (in Hz)
  6. %
  7. % res - vector of sample indices matching indices
  8. %__________________________________________________________________________
  9. % Copyright (C) 2008-2012 Wellcome Trust Centre for Neuroimaging
  10. % Stefan Kiebel
  11. % $Id: indfrequency.m 5212 2013-01-26 13:16:36Z vladimir $
  12. if ~strncmpi(transformtype(this), 'TF',2)
  13. error('Only TF datasets are supported');
  14. end
  15. res = NaN(1,length(f));
  16. fdiff = mean(diff(frequencies(this)));
  17. if nsamples(this) > 0
  18. F = frequencies(this);
  19. for i = 1:length(f)
  20. if f(i) == -Inf
  21. res(i) = 1;
  22. elseif f(i) == Inf
  23. res(i) = length(F);
  24. else
  25. [m, res(i)] = min(abs(F-f(i)));
  26. if m > fdiff
  27. warning('Could not find an index matching the requested frequency %d Hz', f(i));
  28. res(i) = NaN;
  29. end
  30. end
  31. end
  32. end