APPENDIX “C” - LINEARIZER PROGRAM
The following computer program, written in GWBASIC, calculates two
percentage tables required to linearize any non-linear relationship (eg. pH, flow,
etc.) at programmable, error levels. One set represents percent of full scale for the
input value and the other represents the corresponding percent of full scale for the
display value. These values are then used to compute the actual input and display
scaling points.
To use the program, copy it into any computer with GWBASIC installed. The
program uses the relationship between the measured parameter and the display
reading (subroutine 10000) for a square law device. Of course, ANY non-linear
relationship can be substituted into this subroutine to yield the % of full scale
input and % of full scale display. The program will prompt for (%) of full scale
error relative to display readings. Increasing the conformity error decreases the
number of linear slopes required to fit the function. The IMP can accommodate
up to nine linear segments and it is generally desired to use all of them to
minimize linearity error.
Note: Any non-linear function can be substituted for the equation at line 10010.
1 REM THIS PROGRAM WAS WRITTEN IN GWBASIC UNDER MS-DOS 3.3
2 REM THIS PROGRAM CALCULATES THE NUMBER OF LINEAR
SEGMENTS REQUIRED
3 REM TO CURVE-FIT A GIVEN FUNCTION, SEEN IN LINE NUMBER
10000.
6 REM THE PROGRAM COMPUTES THE RESULTS IN PER CENT(%) OF
FULL SCALE PROCESS
7 REM VALUE AND FULL SCALE DISPLAY VALUE. MULTIPLY THE PER
CENT VALUE TIMES
8 REM THE FULL SCALE PROCESS AND DISPLAY VALUES TO OBTAIN
EXACT SCALING
9 REM POINTS FOR THE IMP LINEARIZING FUNCTION.
10 CLS
15 PRINT “ CURVE FITTING PROGRAM”
16 PRINT “”
30 DIM PA(30)
40 DIM DA(30)
50 INPUT “ENTER CURVE FITTING ERROR (%) >”;E
60 P = 10000
70 GOSUB 10000
75 CR=D/P
80 ER=D*E*.01
110 CLS
111 SG=SG+1
112 PRINT “ CALCULATING LINEAR SEGMENT ”;SG
115 IF P2>=10000 THEN A=1:GOTO 1000
117 P2=P2+10
130 P=P1
140 GOSUB 10000
150 D1=D
170 P=P2
180 GOSUB 10000
190 D2=D
210 M=(D2-D1)/(P2-P1)
220 B=D1-(P1*M)
240 PT=P1
245 AD=(P2-P1)/6
250 PT=PT+AD
260 P=PT
270 GOSUB 10000
280 DT=D
290 DT1=(PT*M)+B
310 IF ABS(DT1-DT)>ER THEN 500
320 IF PT <P2 THEN GOTO 250
330 GOTO 115
500 P2=P2+10
510 D2=(P2*M)+B
515 P=P2
520 GOSUB 10000
550 IF ABS(D-D2)<ER THEN 500
1000 PA(SG)=P2/100
1020 DA(SG)=D2/CR/100
1200 P1=P2
1210 D1=D2
1216 IF A< >1 THEN GOTO 110
2000 CLS
2010 PRINT “NUMBER OF LINEAR SEGMENTS = ”;SG
2012 PRINT “CURVE FITTING ERROR (%) = ”;E
2015 PRINT “”
-45-