SIMPARSE - parse simId string for needed signal information [id, f, tau, dur, alpha] = simparse(simId); simId string containing signal information N.B. Must be '~' or '_' delimited id string desribing type of signal f frequency of signal tau width of Gaussian dur signal duration in seconds alpha linear time dependence on the instantaneous chirplet frequency SEE ALSO: MAKEH
0001 function [id, f, tau, dur, alpha] = simparse(simId) 0002 0003 % SIMPARSE - parse simId string for needed signal information 0004 % 0005 % [id, f, tau, dur, alpha] = simparse(simId); 0006 % 0007 % simId string containing signal information 0008 % N.B. Must be '~' or '_' delimited 0009 % 0010 % id string desribing type of signal 0011 % f frequency of signal 0012 % tau width of Gaussian 0013 % dur signal duration in seconds 0014 % alpha linear time dependence on the instantaneous chirplet frequency 0015 % 0016 % SEE ALSO: MAKEH 0017 0018 % $Id: simparse.m,v 1.7 2005/04/28 19:55:32 stuver Exp $ 0019 0020 % FIND indicies of delimiters in simId 0021 % CHECK to make sure the correct number delimiters where found 0022 % ASSIGN variables by the location of the delimiter 0023 % CHECK variables for errors 0024 0025 [id, f, tau, dur, alpha] = deal([]); 0026 0027 I = find(simId == '~' | simId == '_'); 0028 0029 errorcheck(simId, I) 0030 0031 % The simulation type string is the information before the first 0032 % delimiter 0033 id = simId(1:I(1)-1); 0034 0035 % The frequency is the information between the first delimiter and the 0036 % second 0037 f = simId(I(1)+1:I(2)-1); % Frequency (string) 0038 f = str2num(f); % Convert string into number 0039 % Check for errors (f must be a positive finite number) 0040 if f < 0 | isinf(f) | isnan(f) | ~isreal(f) 0041 f 0042 error('simparse: f must be a real positive finite number') 0043 end 0044 0045 % The tau is the information between the second delimiter and the last 0046 tau = simId(I(2)+1:I(3)-1); % tau (string) 0047 tau = str2num(tau); % Convert string into number 0048 % Check for errors (tau must be a positive finite number) 0049 if tau < 0 | isinf(tau) | isnan(tau) | ~isreal(tau) 0050 tau 0051 error('simparse: tau must be a real positive finite number') 0052 end 0053 0054 if length(I) == 3 0055 % The duration is the information after the last delimiter 0056 dur = simId(I(3)+1:end); % Simulation duration (string) 0057 dur = str2num(dur); % Convert string into number 0058 % Check for errors (dur must be a positive finite number) 0059 if dur <= 0 | isinf(dur) | isnan(dur) | ~isreal(dur) 0060 dur 0061 error('simparse: dur must be a real finite number > 0') 0062 end 0063 elseif length(I) == 4 0064 % The duration is the information after the third delimiter 0065 dur = simId(I(3)+1:I(4)-1); % Simulation duration (string) 0066 dur = str2num(dur); % Convert string into number 0067 % Check for errors (dur must be a positive finite number) 0068 if dur <= 0 | isinf(dur) | isnan(dur) | ~isreal(dur) 0069 dur 0070 error('simparse: dur must be a real finite number > 0') 0071 end 0072 % alpha is the information after the last delimiter 0073 alpha = simId(I(4)+1:end); % Chirp parameter (string) 0074 alpha = str2num(alpha); % Convert string into number 0075 % Check for errors (alpha must be a finite number) 0076 if isinf(alpha) | isnan(alpha) | ~isreal(alpha) 0077 alpha 0078 error('simparse: alpha must be a real finite number') 0079 end 0080 end 0081 0082 return 0083 0084 % ~~~ END MAIN ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 0085 0086 function errorcheck(simId, I) 0087 0088 % ERRORCHECK - check simId for errors and errors out if one is found 0089 % 0090 % errorcheck(simId, I) 0091 % 0092 % simId string containing signal information 0093 % N.B. Must be '~' or '_' delimited 0094 % I locations of delimiters 0095 0096 % Check that delimiters where found 0097 if isempty(I) 0098 simId 0099 error('simparse: simId must be ~ delimited or _ delimited') 0100 elseif length(I) ~= 3 & length(I) ~= 4 0101 % There must be 3 or 4 delimiters 0102 simId 0103 error('simparse: There must be 3 or 4 delimiters in simId') 0104 end 0105 0106 spacing = diff(I); 0107 0108 % Delimiter 1 and 2 are consecutive 0109 if spacing(1) == 1 0110 simId 0111 error('simparse: Delimiter 1 and 2 are consecutive') 0112 elseif spacing(2) == 1 0113 % Delimiter 2 and 3 are consecutive 0114 simId 0115 error('simparse: Delimiter 2 and 3 are consecutive') 0116 end 0117 0118 if length(spacing) == 3 0119 % Delimiter 3 and 4 are consecutive 0120 if spacing(3) == 1 0121 simId 0122 error('simparse: Delimiter 3 and 4 are consecutive') 0123 end 0124 end 0125 0126 if I(1) == 1 0127 % There is a delimiter at the begining of simId 0128 simId 0129 error('simparse: There is a delimiter at the begining of simId') 0130 elseif I(end) == length(simId) 0131 % There is a delimiter at the end of simId 0132 simId 0133 error('simparse: There is a delimiter at the end of simId') 0134 end 0135 0136 return