Home > mml > monrate.m

monrate

PURPOSE ^

MONRATE - Calculates the control system data rate of a noisy channel

SYNOPSIS ^

function [AvgRate, N] = monrate(family, DeviceList, T);

DESCRIPTION ^

MONRATE - Calculates the control system data rate of a noisy channel
  [AvgRate, N] = monrate(Family, DeviceList, T)

  INPUTS
  1. Family - Family name ('BPMx', 'HCM', etc.) 
  2. DeviceList - Device list or element list [column vector] {Default: entire family}
  3. T - Time interval to check sampling rate [seconds]  {Default: 2 seconds}

  OUTPUTS
  1. AvgRate - Average sample rate over T seconds periods
  2. N - Number of observed transitions

  NOTES
  1. This method only works on noisy channels!

  Written by Greg Portmann

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [AvgRate, N] = monrate(family, DeviceList, T);
0002 %MONRATE - Calculates the control system data rate of a noisy channel
0003 %  [AvgRate, N] = monrate(Family, DeviceList, T)
0004 %
0005 %  INPUTS
0006 %  1. Family - Family name ('BPMx', 'HCM', etc.)
0007 %  2. DeviceList - Device list or element list [column vector] {Default: entire family}
0008 %  3. T - Time interval to check sampling rate [seconds]  {Default: 2 seconds}
0009 %
0010 %  OUTPUTS
0011 %  1. AvgRate - Average sample rate over T seconds periods
0012 %  2. N - Number of observed transitions
0013 %
0014 %  NOTES
0015 %  1. This method only works on noisy channels!
0016 %
0017 %  Written by Greg Portmann
0018 
0019 DisplayFlag = 0;
0020 OneAtATimeFlag = 0;
0021 
0022 if nargin == 0,
0023     error('Need atleast one input: family');
0024 end 
0025 
0026 if nargin < 2
0027     DeviceList = [];
0028 end
0029 if isempty(DeviceList)
0030     DeviceList = getlist(family);
0031 end
0032 
0033 if (size(DeviceList,2) == 1) 
0034     DeviceList = elem2dev(family, DeviceList);
0035 end                  
0036 
0037 if nargin <= 2
0038     T = 2;
0039 end
0040 
0041 if OneAtATimeFlag
0042     DelT = .005;
0043 else
0044     if size(DeviceList,1) > 50
0045         DelT = .03;
0046     else
0047         DelT = .02;
0048     end
0049 end
0050 if length(T) == 1
0051     tin = 0:DelT:T;
0052 else
0053     tin = T;
0054 end
0055 
0056 
0057 disp(['   Checking the data rate for channel or family: ', family]); 
0058 disp(['   Collection data for ',num2str(tin(end)),' seconds at a sample rate of ',num2str(1/mean(diff(tin))),' Hertz.']); 
0059 pause(0);
0060 disp(['   Channels must be noisy for this method to work.']);
0061 if OneAtATimeFlag
0062     
0063     for i = 1:size(DeviceList,1)
0064         % Collect data
0065         [a, t] = getam(family, DeviceList(i,:), tin);
0066         
0067         adiff = abs(diff(a));
0068         I = find(adiff > 0);
0069         
0070         if size(I,2) < 3
0071             disp(' '); 
0072             disp('   WARNING: Less than 3 update.  Increase time span or channel not noisy enough.'); 
0073             disp(' ');
0074         end
0075         
0076         if isempty(I)
0077             N(i,1) = 0;
0078             AvgRate(i,1) = 0;
0079         else
0080             t = t(I);
0081             tdiff = diff(t);
0082             
0083             N(i,1) = size(I,2)-1;
0084             AvgRate(i,1) = 1/mean(tdiff);
0085         end
0086         
0087         Dev=elem2dev(family,elem(i));
0088         fprintf('   %s(%2d,%2d), Sample Rate=%5.2f Hz,  Number of Samples=%d, Number of New Data Points=%d\n', family, Dev(1), Dev(2), AvgRate(i,1), length(t),N(i,1));
0089     end
0090 else
0091     % Collect data using EPICs
0092     getam(family, DeviceList);  % just to connect to channels
0093     [a, t, DataTime] = getam(family, DeviceList, tin);
0094     
0095     for i = 1:size(DeviceList,1)
0096         adiff = abs(diff(a(i,:)));
0097         I = find(adiff>0);
0098         
0099         if size(I,2) < 3
0100             fprintf('\n    WARNING: %s(%d,%d) updated %d times in %.2f seconds.  Increase time span or channel is not noisy enough.\n\n', family, DeviceList(i,:), size(I,2), tin(end)); 
0101         end
0102         
0103         if isempty(I)
0104             N(i,1) = 0;
0105             AvgRate(i,1) = 0;
0106         else
0107             t1 = t(I);
0108             tdiff = diff(t1);
0109             
0110             N(i,1) = size(I,2)-1;
0111             AvgRate(i,1) = 1/mean(tdiff);
0112         end
0113         
0114         Dev = DeviceList(i,:);
0115         if DisplayFlag
0116             fprintf('   %s(%2d,%2d), Sample Rate=%5.2f Hz,  Number of Samples=%d, Number of New Data Points=%d\n', family, Dev, AvgRate(i,1), length(t), N(i,1));
0117         end
0118     end
0119 end

Generated on Mon 21-May-2007 15:29:18 by m2html © 2003