PICKSTIME - pick signal start time from range in samples startSamp = pickstime(startSamp1, startSamp2) Pick number of start times equal to the length of startSamp1 startSamp = pickstime(startSamp1, startSamp2, nstime) Pick nstime number of start times startSamp1 minimum start time in samples startSamp2 maximum start time in samples nstime (optional) number of start times to generate startSamp determined start time(s) in samples
0001 function startSamp = pickstime(startSamp1, startSamp2, varargin) 0002 0003 % PICKSTIME - pick signal start time from range in samples 0004 % 0005 % startSamp = pickstime(startSamp1, startSamp2) 0006 % Pick number of start times equal to the length of startSamp1 0007 % startSamp = pickstime(startSamp1, startSamp2, nstime) 0008 % Pick nstime number of start times 0009 % 0010 % startSamp1 minimum start time in samples 0011 % startSamp2 maximum start time in samples 0012 % nstime (optional) number of start times to generate 0013 % 0014 % startSamp determined start time(s) in samples 0015 0016 % $Id: pickstime.m,v 1.2 2004/05/10 20:26:13 stuver Exp $ 0017 0018 % DETERMINE number of start times to generate 0019 % DETERMINE interval of start times 0020 % SET start times 0021 0022 startSamp = []; 0023 0024 % Determine number of start times to generate 0025 if length(varargin) == 0 0026 % If nstime is not input, set it to the number of ranges input 0027 nstime = size(startSamp1, 1); 0028 elseif length(varargin) == 1 0029 % If nstime is input, assume that startSamp1 and startSamp2 are scalars 0030 % and generate a vector of minimum start times 0031 nstime = varargin{1}; 0032 startSamp1(1:nstime) = startSamp1; 0033 end 0034 0035 % Determine interval of start times 0036 interval = startSamp2-startSamp1; 0037 % Check interval for error 0038 if interval < 0 0039 error('makelist -> pickstime: startSamp1 must be < startSamp2') 0040 end 0041 0042 % Set start times 0043 for k=1:nstime 0044 % Pick a random number in the interval 0045 samp = rand(1)*interval; % This includes intersample start 0046 % Add randomly picked sample to startSamp1 0047 startSamp(k) = startSamp1(k)+samp(k); 0048 end 0049 0050 return