rem Data Bounding, Smoothing, and Differentiation [loop] cls print print "Data Bounding, Smoothing, and Differentiation" print dim y(100) dim x(100) rem data entry input "Number of points to input? ";n [gleap] input "Use keyboard (k) or read from data (d)? ";c$ if c$="k" then for i=1 to n print "x(";i;")= "; input " ";x1 x(i)=x1 next i end if if c$="d" then rem 105 data points are used in convolution data rem we want to skip past them and restore pointers for i=1 to 105 read x1 next i for i=1 to n read x1 x(i)=x1 next i restore end if if c$<>"d" and c$<>"k" then [gleap] [again] print rem choose process print "Chose process:" print " 1. Data Bounding " print " 2. Data Smoothing " print " 3. First Derivative" print " 4. Second Derivative" print " 5. Quit" print input "(1,2,3,4,5) ";q2 q=0 q1=0 if q2=1 then q=-1 gosub [bound] end if if q2=2 then q=0 gosub [smooth] end if if q2=3 then q=1 q1=3 gosub [smooth] end if if q2=4 then q=2 q1=4 gosub [smooth] end if if q2=5 then end gosub [again] rem bounding routine [bound] print print "data bounding" a$="Data bounded" input "How many standard deviations? ";s y(1)=x(1) for k=2 to n-1 a=(x(k-1)+x(k+1))/2 d=x(k)-a m=s*(x(k))^.5 if abs(d)0 then [bleap] y(k)=x(k)+m goto [cleap] [bleap] y(k)=x(k)-m goto [cleap] [aleap] y(k)=x(k) [cleap] next k y(n)=x(n) gosub [prin] return [smooth] rem least squares smoothing and derivative routines print [fleap] input "Degree of smoothing desired (2-4, 1 return to main menu): ";s if s=1 then [eleap] if s<2 then [fleap] if s>4 then [fleap] restore t=36*q+(s-2)*(s+3) for k=1 to t+1 read b next k m=2*s+1 for k=1 to m read c1 c(k)=c1 next k m1=m rem smooth each data point var2=n-1*s for k=s+1 to n-s d=0 l=m1 rem compute convolution for j=1 to m d=d+x(l)*c(j) l=l-1 next j y(k)=d/8 m1=m1+1 next k rem convolution array coefficients rem compute end points and 2nd derivative for k=1 to s y(k)=y(s+1) next k var1=n-s+1 for k=var1 to n y(k)=y(n-s) next k a$= "2nd derivative" if q1=4 then [dleap] rem first derivative t=35-2*s rem read new set of coefficients for k=1 to t read b next k for k=1 to m read c1 c(k)=c1 next k d=0 l=n r=m e=0 rem compute convolution for j=1 to m e=e+x(l)*c(j) d=d+x(r)*c(j) r=r-1 l=l-1 next j d=d/b e=e/b l=n-s+1 for k=1 to s y(k)=y(k)+d*(k-1*s-1) y(l)=y(l)+e*k l=l+1 next k a$="1st derivative " if q1=3 then [dleap] rem smoothed values rem read new coeffcients for k=1 to t read b next k for k=1 to m read c1 c(k)=c1 next k d=0 e=0 r=m l=n rem compute convolution for j=1 to m d=d+x(r)*c(j) e=e+x(l)*c(j) r=r-1 l=l-1 next j d=d/b e=e/b l=n-s+1 for k=1 to s y(k)=y(k)+d*(k-1*s-1)*(k-1*s-1)/2 y(l)=y(l)+e*k*k/2 l=l+1 next k a$="smoothed data" [dleap] gosub [prin] [eleap] return rem ****************** convolution array data **************** rem ****************** do not change **************** data 35,-3,12,17,12,-3 data 21,-2,3,6,7,6,3,-2 data 231,-21,14,39,54,59,54,39,14,-21 data 429,-36,9,44,69,84,89,84,69,44,9,-36 data 10,2,1,0,-1,-2 data 28,3,2,1,0,-1,-2,-3 data 60,4,3,2,1,0,-1,-2,-3,-4 data 110,5,4,3,2,1,0,-1,-2,-3,-4,-5 data 7,2,-1,-2,-1,2 data 42,5,0,-3,-4,-3,0,5 data 462,28,7,-8,-17,-8,7,28 data 429,15,6,-1,-9,-10,-9,-6,-1,6,15 [prin] print print "Result: ";a$ print for k=1 to n print "X(";k;")= ";x(k) print "Y(";k;")= ";y(k) print next k return rem ****************** insert your data below **************** rem ****************** if you are using this **************** rem ****************** input method **************** data 84,85,83,105,108,123,107,96,102,92 data 111,93,102,76,78,64,64,61,54,51 end