source: MML/trunk/mml/monrate.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 11 years ago

Initial import--MML version from SOLEIL@2013

File size: 3.2 KB
Line 
1function [AvgRate, N] = monrate(family, DeviceList, T);
2%MONRATE - Calculates the control system data rate of a noisy channel
3%  [AvgRate, N] = monrate(Family, DeviceList, T)
4%
5%  INPUTS
6%  1. Family - Family name ('BPMx', 'HCM', etc.)
7%  2. DeviceList - Device list or element list [column vector] {Default: entire family}
8%  3. T - Time interval to check sampling rate [seconds]  {Default: 2 seconds}
9%
10%  OUTPUTS
11%  1. AvgRate - Average sample rate over T seconds periods
12%  2. N - Number of observed transitions
13%
14%  NOTES
15%  1. This method only works on noisy channels!
16%
17%  Written by Greg Portmann
18
19DisplayFlag = 0;
20OneAtATimeFlag = 0;
21
22if nargin == 0,
23    error('Need atleast one input: family');
24end
25
26if nargin < 2
27    DeviceList = [];
28end
29if isempty(DeviceList)
30    DeviceList = getlist(family);
31end
32
33if (size(DeviceList,2) == 1)
34    DeviceList = elem2dev(family, DeviceList);
35end                 
36
37if nargin <= 2
38    T = 2;
39end
40
41if OneAtATimeFlag
42    DelT = .005;
43else
44    if size(DeviceList,1) > 50
45        DelT = .03;
46    else
47        DelT = .02;
48    end
49end
50if length(T) == 1
51    tin = 0:DelT:T;
52else
53    tin = T;
54end
55
56
57disp(['   Checking the data rate for channel or family: ', family]);
58disp(['   Collection data for ',num2str(tin(end)),' seconds at a sample rate of ',num2str(1/mean(diff(tin))),' Hertz.']);
59pause(0);
60disp(['   Channels must be noisy for this method to work.']);
61if OneAtATimeFlag
62   
63    for i = 1:size(DeviceList,1)
64        % Collect data
65        [a, t] = getam(family, DeviceList(i,:), tin);
66       
67        adiff = abs(diff(a));
68        I = find(adiff > 0);
69       
70        if size(I,2) < 3
71            disp(' ');
72            disp('   WARNING: Less than 3 update.  Increase time span or channel not noisy enough.');
73            disp(' ');
74        end
75       
76        if isempty(I)
77            N(i,1) = 0;
78            AvgRate(i,1) = 0;
79        else
80            t = t(I);
81            tdiff = diff(t);
82           
83            N(i,1) = size(I,2)-1;
84            AvgRate(i,1) = 1/mean(tdiff);
85        end
86       
87        Dev=elem2dev(family,elem(i));
88        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));
89    end
90else
91    % Collect data using EPICs
92    getam(family, DeviceList);  % just to connect to channels
93    [a, t, DataTime] = getam(family, DeviceList, tin);
94   
95    for i = 1:size(DeviceList,1)
96        adiff = abs(diff(a(i,:)));
97        I = find(adiff>0);
98       
99        if size(I,2) < 3
100            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));
101        end
102       
103        if isempty(I)
104            N(i,1) = 0;
105            AvgRate(i,1) = 0;
106        else
107            t1 = t(I);
108            tdiff = diff(t1);
109           
110            N(i,1) = size(I,2)-1;
111            AvgRate(i,1) = 1/mean(tdiff);
112        end
113       
114        Dev = DeviceList(i,:);
115        if DisplayFlag
116            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));
117        end
118    end
119end
Note: See TracBrowser for help on using the repository browser.