some software algorithms for microprocessor ratemeters

6
Nuclear Instruments and Methods in Physics Research A301 (1991) 517-522 517 North-Holland Some software algorithms for microprocessor ratemeters Zoran Savic Military Technical Institute, Kataniceoa 15, 11000 Belgrade, Yugoslavia Received 22 February 1990 and m revised form 30 November 1990 After a review of the basic theoretical ratemeter problem and a general discussion of microprocessor ratemeters, a short insight into their hardware organization is given . Three software algorithms are described : the old ones, the quasi-exponential and floating mean algorithm, and a new weighted moving average algorithm . The equations for statistical characterization of the new algorithm are given and an intercomparison is made . It is concluded that the new algorithm has statistical advantages over the old ones . 1 . Introduction A classical problem in the field of nuclear science is the rate estimation of random pulse trains which may originate from various nuclear detectors . As is well known [1], this problem is especially hard when the rate is variable with time and is a consequence of random timing . In this case, a form of uncertainty principle exists, and an accurate time reference of the rate can only be obtained at the expense of the accuracy of the measurement and vice versa . Bearing this theoretical limit in mind, in practice it is only possible to find a certain optimization in accordance with the importance of the precise timing or accuracy of the rate measure- ment in a specific application . For the purpose of rate measurements different spe- cial instruments have been known for more than half a century [2], and the famous diode-pump circuit is a standard topic in every book on nuclear electronics . The development of these instruments closely followed the technological achievements of electronics and the most modern versions are those with microprocessors. Beside the relative simplicity and many other standard ad- vantages which microprocessor ratemeters offer, they have great flexibility in treating the optimization prob- lem in the rate measurement mentioned above . Although the characteristics of microprocessor ratemeters depend both on the hardware and the soft- ware organization of these instruments, possible optimi- zation of the rate measurement takes place mainly in the software. Software can implement different rate estimation algorithms . All of these algorithms are based on data pairs (N T,), where N, is the number of registered random pulses during the i th measuring period of time T but they can lead to quite different results according to how these elementary data are combined . In practice it is not easy to find the best 0168-9002/91/$03 .50 © 1991 - Elsevier Science Publishers B .V . (North-Holland) solution for a specific application and the most im- portant and delicate is the selection of criteria to which possible optimization must be directed. Sometimes this is a question of measure and taste [3,4] and it is not surprising that computer simulations and experimental tests are often conducted before the acceptance of a certain software organization. 2 . Hardware organization In principle, random pulses can be put directly into the interrupt facility of a computer [5], and a computer program can perform all necessary operations for the ratemeter function . Although such an oversimplified hardware solution of the microprocessor ratemeter is possible, it is not practical. A method like this may use too much processing time, leaving little for the other functions which a typical system with a ratemeter has . It is also possible that at very high rates with this method, the speed or capacity of the microcomputer would not be enough . So besides microcomputer hard- ware organization, some additional hardware is needed for an efficient microprocessor ratemeter . For the purpose of further discussion, in addition to customary microcomputer hardware which consists of [P, ROM, RAM and a number of I/O devices, it will be supposed that the microprocessor ratemeter has two programmable counters for the registration of random and time pulses . The time pulses come from a crystal- controlled oscillator and serve for the determination of the elapsed time T, of each measuring cycle . The cycle starts after initialization by the microprocessor com- mand that enables the counting of random and time pulses. When a predetermined number of either pulses is reached, an overflow signal generates an interrupt for

Upload: zoran-savic

Post on 21-Jun-2016

217 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Some software algorithms for microprocessor ratemeters

Nuclear Instruments and Methods in Physics Research A301 (1991) 517-522

517North-Holland

Some software algorithms for microprocessor ratemeters

Zoran SavicMilitary Technical Institute, Kataniceoa 15, 11000 Belgrade, Yugoslavia

Received 22 February 1990 and m revised form 30 November 1990

After a review of the basic theoretical ratemeter problem and a general discussion of microprocessor ratemeters, a short insightinto their hardware organization is given . Three software algorithms are described : the old ones, the quasi-exponential and floatingmean algorithm, and a new weighted moving average algorithm . The equations for statistical characterization of the new algorithmare given and an intercomparison is made . It is concluded that the new algorithm has statistical advantages over the old ones .

1 . Introduction

A classical problem in the field of nuclear science isthe rate estimation of random pulse trains which mayoriginate from various nuclear detectors . As is wellknown [1], this problem is especially hard when the rateis variable with time and is a consequence of randomtiming . In this case, a form of uncertainty principleexists, and an accurate time reference of the rate canonly be obtained at the expense of the accuracy of themeasurement and vice versa . Bearing this theoreticallimit in mind, in practice it is only possible to find acertain optimization in accordance with the importanceof the precise timing or accuracy of the rate measure-ment in a specific application .

For the purpose of rate measurements different spe-cial instruments have been known for more than half acentury [2], and the famous diode-pump circuit is astandard topic in every book on nuclear electronics . Thedevelopment of these instruments closely followed thetechnological achievements of electronics and the mostmodern versions are those with microprocessors. Besidethe relative simplicity and many other standard ad-vantages which microprocessor ratemeters offer, theyhave great flexibility in treating the optimization prob-lem in the rate measurement mentioned above .

Although the characteristics of microprocessorratemeters depend both on the hardware and the soft-ware organization of these instruments, possible optimi-zation of the rate measurement takes place mainly inthe software. Software can implement different rateestimation algorithms . All of these algorithms are basedon data pairs (N� T,), where N, is the number ofregistered random pulses during the i th measuringperiod of time T� but they can lead to quite differentresults according to how these elementary data arecombined . In practice it is not easy to find the best

0168-9002/91/$03.50 © 1991 - Elsevier Science Publishers B.V. (North-Holland)

solution for a specific application and the most im-portant and delicate is the selection of criteria to whichpossible optimization must be directed. Sometimes thisis a question of measure and taste [3,4] and it is notsurprising that computer simulations and experimentaltests are often conducted before the acceptance of acertain software organization.

2 . Hardware organization

In principle, random pulses can be put directly intothe interrupt facility of a computer [5], and a computerprogram can perform all necessary operations for theratemeter function . Although such an oversimplifiedhardware solution of the microprocessor ratemeter ispossible, it is not practical. A method like this may usetoo much processing time, leaving little for the otherfunctions which a typical system with a ratemeter has .It is also possible that at very high rates with thismethod, the speed or capacity of the microcomputerwould not be enough . So besides microcomputer hard-ware organization, some additional hardware is neededfor an efficient microprocessor ratemeter .

For the purpose of further discussion, in addition tocustomary microcomputer hardware which consists of[P, ROM, RAM and a number of I/O devices, it willbe supposed that the microprocessor ratemeter has twoprogrammable counters for the registration of randomand time pulses . The time pulses come from a crystal-controlled oscillator and serve for the determination ofthe elapsed time T, of each measuring cycle . The cyclestarts after initialization by the microprocessor com-mand that enables the counting of random and timepulses. When a predetermined number of either pulsesis reached, an overflow signal generates an interrupt for

Page 2: Some software algorithms for microprocessor ratemeters

51 8

the microprocessor which in turn identifies its origin(whether it is from random or time pulses), reads therelevant count, initializes a new cycle, performs the rateestimation algorithm and gives its value on a suitabledisplay.

The realization of a concrete microprocessor rateme-ter can be very different in practice and depends on anumber of factors such as the bit number and architec-ture of the particular microprocessor, the way of addre-ssing I/O devices, the way of handling an interruptprocedure, etc. It also depends on the overall range ofthe measuring rate, the range determining the way ofpresenting the results and the general purpose of theinstrument . Less obvious is that the hardware realiza-tion depends on the chosen software algorithm for rateestimation, especially on how much memory it requires.

3. Software algorithm

The interrupt signal mentioned above, can be gener-ated when the predetermined number of time or ran-dom pulses is reached and this defines two basic modesof gathering input data, with a predetermined time or apredetermined count . The number of the random pulsesin the predetermined time mode is governed by thePoisson distribution and the value of elapsed time forthe predetermined count mode is governed by the inter-val distribution . It follows that the rate estimation R, =N,/T, from elementary data N, and T, has a statisticaluncertainty which can be described by the fractionalstandard deviation (standard error) . For the prede-termined time mode this error is given as e = N,-1/2 andfor the predetermined count mode [6] as e = (N, -2)-1/, so for a relatively high number of randompulses, the statistical uncertainty of both methods is thesame . Therefore, further discussion is devoted only tothe predetermined time mode leaving aside the so-calledinverse-time-interval ratemeter organization .

It follows from the standard error that with constantrate p, the statistical accuracy is greater the longer thetime interval T, is and for a specific accuracy a specificdelay is required, which for low rates may be quite long .This problem becomes worse with variable rates and isvery marked in response to a step change . In this casebecause the step change and measuring cycle are notsynchronised, the first result after the step change isfaulty and delay can be anywhere between T, and 2T, .The response, of course, can be faster and the problemof nonsynchronism can be minimized if the time inter-val T, is shorter but that would lead to greater statisticalfluctuation. The solution can be found by combiningmore results of shorter duration and that is what thealgorithm has to do in rate estimation. Three suchalgorithms in which the predetermined time intervalsfrom cycle to cycle are the same (T, = T) will be furtheranalysed .

Z. Saotc / Software algorithms for microprocessor ratemeters

The first one, the quasi-exponential algorithm, wasused in many early digital ratemeters [8-10] and thesecond, the floating mean algorithm, has found applica-tion in some newly built microprocessor-controlledratemeters [4,11] . The third, the weighted moving aver-age algorithm, is a new one and it has a certain ad-vantage, as will be seen, compared to the old ones . Thederivations for the new algorithm which follow arecarried out in the Appendix and derivations for the oldones may be found elsewhere [3] .

3 .1. Quasi-exponential algorithm

The resulting estimated rate from n cycles of mea-surement R � in the so-called quasi-exponential al-gorithm is given as

R � = T y_ ( 1-a)

n- 'N,t=1

where a is a number between 0 and 1, T is the timeinterval of a single measurement and N, is the numberof pulses in the i th measurement . For a << 1 this al-gorithm closely resembles the behaviour of a classicalanalog ratemeter with an RC tank circuit . It is im-portant that relation (1) can be described by a recursiveformula,

which greatly facilitates the software algorithm.The response to a step function of the input rate p

with such an algorithm is given as :

R � =P [1-(1-a) "] ,

where R � is the mean value of the nth measurementresult. From this equation it is evident that there is atransition period to the final value R � = p which wouldbe reached after an infinite number of cycles . Forobservational time t >> T relation (3) can be written as :_

1 -rlTRn = P

L1_ (1_a

)

and further with a << 1 as :

Rn = p[1 - e-tl(Tla)1,

which shows a direct connection with the classicalratemeter and the equivalence of time constant RC andT/a . So, although theoretically the transient periodnever ends with this algorithm, in practice after severaltime constants it may be regarded as completed .

The statistical fluctuation of the current result R �expressed by the fractional standard deviation is givenby

R �

pT (2-a)[1 - (1-a)"~

Page 3: Some software algorithms for microprocessor ratemeters

and after several time constants it can be approximatedas

_ ae

(2-a)PT ,

which for a << 1 gives the classical result e =(2pT/a)-1/2 . From eq. (6) it follows that the standarderror of a single observation is constantly falling until itreaches its final value (7).

3 .2 . Floating mean algorithm

The estimated rate result from n cycles of measure-ment R" with the so-called floating mean algorithm isgiven as

1 nRn mT Nr,

r=1

and

Rn= m7.

Y_

N,, =n-m+1

where m is a positive integer, T is the time interval of asingle cycle and N, is the number of pulses in the ithmeasurement . The result Rn from this algorithm isformed on the basis of the last m measurements andwhen the new n th measurement is completed the n -mth measurement is discarded . This algorithm requiresFIFO (first-in-first-out) memory with m storage places .

The response to a step function of input rate p withthis algorithm is given by the relation

R n =P n,

n < mm

and

R"= p,

n>_m,

n<m

where R" is the mean value of the nth measurementresult . This algorithm has two clearly divided regimes, atransient period for n < m and a steady state for n >_ m .For observational time t >> T the transient period canbe expressed by the linear relation

PRn=mT1 (10)

and therefore this is sometimes called a linear al-gorithm . The transient period lasts precisely mT andafter that the final response R n = p is reached .

The statistical fluctuation of the current result R n

Table 1Relationship between algorithm parameters

m 6.353 7 .857 12 .364 24.369a 0.272 0.226 0.150 0.079k 8

10

16

32

Z Sav:c /Software algorithms for microprocessor ratemeters 519

expressed by the fractional standard deviation is givenby

and

1e=

n _ m,mpT

so the standard error is falling throughoutperiod and has a constant value after it .

3.3. Weighted moving average algorithm

The result of the estimated rate frommeasurement Rn with a weighted movinggorithm is given by the relations

R �

k(k+1)T r_ (k-n+i)N,,

andn

Rn k(k+1)T Y_ (k-n+i)N�r = n-k+1

2

R"=

k( kP+ 1) [(2k+1)n - n2j,n<k

the

n<k

37.871 48.372 75 .373 96 .3740.051 0 .041 0.026 0.02150 64 100 128

n>_k,

transient

n cycles ofaverage al-

(12)

where k is a positive integer, T is the time interval of asingle cycle and N, is the number of pulses in the ithmeasurement . The results R � from this algorithm areformed on the basis of the last k measurements, sowhen a new n th measurement is finished the n - k thmeasurement is discarded. The difference compared tothe floating mean algorithm is that there is a certainweight factor associated with each storage place of theFIFO memory . The factors are linearly related and thegreatest goes with the memory location where the lastmeasurement is stored . This algorithm, according to thetheory of analog linear ratemeters [7], resembles thebehaviour of an analog ratemeter with an optimumweight function which minimizes statistical fluctuationsand average delay.

The response to a step function of input rate p withthis algorithm is given by the relations

and

Rn = p,

n > k,

(13)

Page 4: Some software algorithms for microprocessor ratemeters

520

where R � is the mean value of the nth measurementresults . Again the algorithm has two clearly dividedregimes, a transient period for n <k and a steady statefor n >- k. For observational time t >> T the transientperiod has a quadratic form,

R � = p2 ~(2k+I)Tt-t2J,

(14)k(k + 1)T2

and has lasted exactly kT when the final response p isreached.

The statistical fluctuation of the current result R �expressed by the fractional standard deviation is givenby

3.4. Comparison of the algorithms

Z. Saoté /Software algorithmsfor microprocessor ratemeters

so the standard error is again falling during the tran-sient period and has a constant value after it .

As can be seen from eqs. (5), (9) and (13) all al-gorithms described give the same results for the steadystate and there are a number of ways to compare them.From the statistical point of view, these steady statescan be regarded as equivalent if their statistical fluctua-tions expressed as standard errors of the current read-ings of eqs. (7), (11) and (15) are equal. This conditiongives a correspondence between the parameters of thealgorithms (a, m and k) and mutual relations of thecharacteristics of the transient period (response time)from which the comparison may be made . On the otherhand, one can start the comparison from the transientperiod, taking the equivalence of its characteristics (re-

Fig. 1 . Step response for regularly spaced pulses. A - weightedaverage, B - floating mean, C - exponential .

.5

0

.5

K=16 K=32 K=64 K=128

0 20 40 60 80 100 :deviation

Fig. 2. Time relations for the same deviation . A - tf/t.� B -

sponse time for example), then calculating the parame-ters of the algorithms for such a case, and finally themutual relation of steady state characteristics .

With the described procedure for the statisticalequivalence of steady states, the correspondence be-tween algorithm parameters for some values of k isshown in table 1. Of course, the parameter m in prac-tice has to take the closest integer values from thequoted figures .

The response to the step function for regularly spacedpulses of the equivalent algorithms with k = 128, m = 96and a =0.021 is shown in fig. 1. From this figure, it isevident that the response of the new algorithm is fasterthan the response of the floating mean algorithm in thefirst three quarters of the transient period . It is alsofaster than the response of the exponential algorithm inthe last third of the transient period . This approximaterelation holds fairly well for different values of k, ascan be seen from fig . 2, where the quotients of the timesfor reaching the same deviation from the steady state ofthe floating mean and the new (t f /tw ) or the exponen-

50

100

150Ttime

Fig. 3 . Step response with ± standard deviation: weightedmoving average algorithm .

2 6k(k-n+1)+2n2 -3n+1E = 3pTn (2k - n + 1)2

n<k

and

2 2k+1E_

- ~ ' n' k, (15)3pTk k+1

Page 5: Some software algorithms for microprocessor ratemeters

INCOaN71i.5

50

106time

Fig. 4. Step response with ± standard deviation : floating meanalgorithm.

tial and the new (t./t,,) algorithm is shown. Thesequotients are derived from eqs. (5), (10) and (14) .

From the point of view of statistical fluctuations it isinteresting to note the responses to the step functiongiven in figs . 3, 4 and 5. These figures show the meanvalue of each result ± its standard deviation for thenew (k = 50) floating mean (m = 38) and exponential(a =0.051) algorithm. The figures are plotted for pT = 1and their shapes are similar for greater values of pTalthough the shaded areas are narrower. Supposing anapproximately normal distribution of the current resultR� , it could be said that in 68% of the cases theresponse to the step function will fall within the shadedareas of the figures . It can be seen from these figuresthat the new algorithm gives smaller fluctuations in thetransient period . It can also be seen that in the steadystate all algorithms give the same fluctuations which isas it should be for the chosen parameters .

The advantage of the weighted moving average al-gorithm is especially marked when dealing with impulserates as shown in fig . 6. There, a Poisson distributed

150 T

Fig . 5 . Step response with ± standard deviation : exponentialalgorithm.

Z. Saoeé /Software algorithms for microprocessor ratemeters

Fig. 6 . Response to impulse rate. A - weighted average, B -floating mean, C - exponential .

4. Conclusion

Acknowledgement

52 1

random pulse train of short duration (19T) and con-stant rate p= 5/T is treated with the new (k = 32),floating mean (m = 24) and exponential (a = 0.079) al-gorithm. From the figure it is evident that the responsewith the first is higher and faster at the top than withthe others .

The comparison of algorithms can also be madefrom the hardware-software point of view, where therequired operating memory and execution time are themost important parameters to form a judgement aboutthem . The required memory and execution time is thesmallest for the exponential and the largest for theweighted mean algorithm.

The new weighted moving average algorithm, whichis described in the paper, has better statistical character-istics in dealing with variable rates than the knownexponential and floating mean algorithms currentlybeing applied in microprocessor ratemeters. On theother hand, the new algorithm requires more memory(both RAM and ROM) and a longer execution timethan the old ones . This hardware limitation of theapplication of the new algorithm will probably havelesser importance with further improvements of micro-processor technology .

The author wishes to thank Mr. P. Behcev and Mr .B. Obradovi6 of this establishment for computer simula-tion concerning fig. 6 and their helpful comments on it .

Page 6: Some software algorithms for microprocessor ratemeters

522

Appendix

Response to the step function

If the step function commences at t = 0, the firstresult is at T and as N, = pT it follows from eq. (12)that

Rn

k(k+1)T Y_ (k - n +i ) N,

and

2p n

k(k+1) ry(k-n+i)

k(k+1)Lkn-n2 +_

n(n2

1) 1

k(k+1) [ (2k+1)n - n2 1,n<k

(16)

Rn k(k+1)T Y- (k-n+i)N,=n-k+I

2pk

= F(k

~Jk + 1) J=1

-

2p

k(k + 1) -p

n > k .

(17)k(k+1) 2

It follows from t >> T that n _-, t/T and, by substitu-

tion in eq . (16), eq. (14) is obtained .

Statistical fluctuation ofcurrent results

As the events are Poisson distributed, the variance ofN, is a,,2v = N, = pT, and as all

N,

are independent

statistic variables it follows from eq. (12) that

2 n

a2(Rn)=Lk(k+1)T,1: (k - n+i)ZN,'=1

k k

4__

P1 T F ~(k-n)2+2(k-n)i+i2 ]

2()

[(k_,

__ 4p n(k-n)2k2 (k + 1)2T

Z. Sanie / Software algorithmsfor microprocessor ratemeters

and

2 n

a2(Rn)=[k(k+l)T] Y- (k-n+t)ZN,t=n-k+1

By directly substituting the results of eqs. (18) and (16)or eqs. (19) and (17) in c =a(R,)/Rn the relation for

the fractional standard deviation (15) is obtained .

References

C.H . Vincent, Random Pulse Trains, their Measurementsand Statistical Properties (Peregrinus, London, 1973).

[2] N.S . Gringrich, R.D. Evans and H.S . Edgerton, Rev. Sci.Instr. 7 (1936) 450.A.M . Koturovi6, Proc. IMEKO Symp. on Measurementand Estimation, Bressanone (Brixen), Italy, 1984, p. 223.

[4] C.H. Staley, W.P . Unruh, W. Baird and M.G . Worth,IEEE Trans. Nucl . Sci. NS-34 (1) (1987) 619.J.S . Byrd, Nucl . Instr. and Meth. 121 (1974) 397.C.H . Vincent, Nucl . Instr. and Meth . 29 (1964) 337.C.H . Vincent, Nucl . Instr. and Meth . 23 (1963) 193.C.H . Vincent and J.B. Rowles, Nucl . Instr. and Meth . 22(1963) 201.

[9] M. Werner, Nucl. Instr . and Meth . 34 (1965) 103.[10] G. White, Nucl . Instr. and Meth. 125 (1975) 313.[11] D. Vankov, G.S . Ganev, R.M . Ivanov and M. Müller,

Nucl . Instr. and Meth . 214 (1983) 395.

[51[6]

[71[81

+2(k-n)n(n+1) +,n(n+1)(2n+1) 1

2

66

_ 2pn

3k2 (k + 1)2T

x[6k(k-n+1)+2n 2 -3n+11, n<k(18)

k= k2(k4p 1)2T 1:1j2

_ 4p k(k+1)(2k+1)

k2(k+1)2T 6

_ 2p 2k+13kT k + 1 ,