SETAMPL - set the signal amplitude for makelist ampl = setampl(preAmpl, nSim) preAmpl intermediate amplitude information from makelist nSim number of amplitudes to determine and return ampl determined amplitudes
0001 function ampl = setampl(preAmpl, nSim) 0002 0003 % SETAMPL - set the signal amplitude for makelist 0004 % 0005 % ampl = setampl(preAmpl, nSim) 0006 % 0007 % preAmpl intermediate amplitude information from makelist 0008 % nSim number of amplitudes to determine and return 0009 % 0010 % ampl determined amplitudes 0011 0012 % $Id: setampl.m,v 1.2 2004/05/10 20:26:14 stuver Exp $ 0013 0014 % DETERMINE mode of preAmpl from input length 0015 % IF amplitude if fixed 0016 % COPY preAmpl nSim times into ampl 0017 % ELSEIF amplitude drawn from logarithmic distribution 0018 % DETERMINE range of distribution from preAmpl values 0019 % SET ampl to value from log distribution 0020 % ELSEIF amplitude drawn from discrete linear distribution 0021 % GENERATE linear distibution from values in preAmpl 0022 % SET ampl to value in linear distribution 0023 % ENDIF 0024 0025 ampl = []; 0026 0027 % Find length of preAmpl to determine mode 0028 amplMode = length(preAmpl); 0029 0030 % Set ampl based on preAmpl length 0031 switch amplMode 0032 case 1 % The amplitude is fixed 0033 % can leave preAmpl alone 0034 ampl(1:nSim) = preAmpl; 0035 case 2 % logarithmic distributed inside range 0036 % Determine range 0037 lower = log10(preAmpl(1)); 0038 upper = log10(preAmpl(2)); 0039 % Check range for error 0040 if upper < lower 0041 error('makelist -> setampl: ampl(1) must be < ampl(2)') 0042 end 0043 range = upper-lower; 0044 % Set ampl to value from log distribution 0045 logampl = (rand(nSim,1)*range)+lower; 0046 ampl = 10.^logampl; 0047 case 3 % Pick ampl randomly from uniformly distributed values 0048 % Determine range 0049 lower = preAmpl(1); 0050 interval = preAmpl(2); 0051 upper = preAmpl(3); 0052 % Check range for error 0053 if upper < lower 0054 error('makelist -> setampl: ampl(1) must be < ampl(2)') 0055 end 0056 if interval <= 0 0057 error(['makelist -> setampl: The interval, ampl(2), ' ... 0058 'must be > 0']) 0059 end 0060 % Generate discrete linear distribution 0061 temp = lower:interval:upper; 0062 tempLength = length(temp); 0063 % Set ampl to value from distribution 0064 for g = 1:nSim 0065 ampl(g) = temp(fix(rand(1)*tempLength)); 0066 end 0067 otherwise 0068 error(['makelist -> setampl: ampl must be a vector of length '... 0069 '1, 2 or 3']) 0070 end 0071 0072 return