The tool we'll use today lives in Richard Waterman's collection of HTML programs and is called pstogif. To make life easier for more conversions, you might want to start by aliasing his tool. Then use it to convert the postscript file graph1.ps.
alias pstogif /users/waterman/LATEX2HTML/pstogif pstogif graph1.psAfter running this program to convert our previous MM graphic called to a gif file, we can add it to the page as follows. Use the "view source" browser option to see the HTML instructions.
(defun MOVING-AVERAGE (x width) "Smooths assuming input x is equally spaced." (unless (oddp width) (format t "Width needs to be odd integer.~%") (setf width (1+ (round width))) ) (let ((half (/ (1- width) 2)) ; invariants done once (n-1 (1- (length x))) (smth ()) ) (flet ((avg (i) (mean (select x (iseq (max 0 (- i half)) (min n-1 (+ i half))))) )) (dotimes (i (length x)) (push (avg i) smth)) (nreverse smth) ; native reverse is "safe" here )))This version does OK with n=1000 points, but starts to bog down when one think about "twicing", smoothing the smoother.
If you think the previous version was slow, this one absolutely drags with 1000 points in the display (only a subset are shown in the illustration). What to do? There are three choices, and the first one is always worth a try:
Writing the program in C only makes sense after you have spent time thinking about the second and will need the function repeatedly. For one or two times, why spend the hours that it takes to convert your program to C?
Our first program simply computes an average, and illustrates the passing of data from Lisp to C and back to Lisp.
Now for the real thing, the smoother. Since we're being so careful, might there be a better way to compute the smoother, such as by using St to compute St+1?