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