[CM] Learn Scheme For Max with S7 e-book up

bil at ccrma.Stanford.EDU bil at ccrma.Stanford.EDU
Wed Mar 24 13:47:03 PDT 2021


Here's an example of "do" for your book:

;; 2D dft, real data, spot-checked against fftw
(define (dft2 in)
   (let* ((dims (vector-dimensions in))
          (h (car dims))
          (w (cadr dims))
	 (ih (/ 1.0 h))
	 (iw (/ 1.0 w))
          (rl (make-float-vector (list h w) 0.0))
          (im (make-float-vector (list h w) 0.0))
	 (out (make-float-vector (list h w))))
     (do ((yout 0 (+ yout 1)))
         ((= yout h)
	 (do ((i 0 (+ i 1)))
	     ((= i h) out)
	   (do ((j 0 (+ j 1)))
	       ((= j w))
	     (set! (out i j) (+ (* (rl i j) (rl i j)) (* (im i j) (im i 
j)))))))
       (do ((xout 0 (+ xout 1)))
           ((= xout w))
         (do ((yin 0 (+ yin 1)))
             ((= yin h))
           (do ((xin 0 (+ xin 1)))
               ((= xin w))
             (set! (rl yout xout) (+ (rl yout xout)
				    (* (in yin xin)
				       (cos (* 2 pi (+ (* xout xin iw)
						       (* yout yin ih)))))))
             (set! (im yout xout) (+ (im yout xout)
				    (* (in yin xin)
				       (sin (* 2 pi (+ (* xout xin iw)
						       (* yout yin ih)))))))))))))

(I was trying to find a good "do" timing test, so I wrote this
yesterday).



More information about the Cmdist mailing list