-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathspMS2Sample.m
55 lines (48 loc) · 1.32 KB
/
spMS2Sample.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Samples = spMS2Sample(MS, Hertz, varargin)
% Samples = spMS2Sample(MS, Hertz, OptioanlArgs)
%
% Given a time in MS and a sample rate in Hertz, determine
% the number of samples corresponding to the time.
%
% OptionalArgs:
%
% 'Rounding', String
% Where String is:
% 'round' - round towards nearest integer
% 'floor' - round towards negative infinity (default)
% 'ceil' - round towards positive infinity
% 'none' - no rounding
%
% This code is copyrighted 2002 by Marie Roch.
% e-mail: [email protected]
%
% Permission is granted to use this code for non-commercial research
% purposes. Use of this code, or programs derived from this code for
% commercial purposes without the consent of the author is strictly
% prohibited.
Samples = (MS / 1000) * Hertz;
n=1;
Rounded = 0;
while n <= length(varargin)
switch varargin{n}
case 'Rounding'
switch varargin{n+1}
case 'round'
Rounded = 1; Samples = round(Samples);
case 'floor'
Rounded = 1; Samples = floor(Samples);
case 'ceil'
Rounded = 1; Samples = ceil(Samples);
case 'none'
Rounded = 1;
otherwise
error(sprintf('Bad Rouning method %s', varargin{n+1}));
end
n=n+2;
otherwise
error(sprintf('Bad optional argument: "%s"', varargin{n}));
end
end
if ~ Rounded
Samples = floor(Samples);
end