SHARE
TWEET

Untitled

a guest Nov 19th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #lang racket
  2. (define (car-flot f) ;;TODO: USE OR REMOVE
  3. (car f))
  4. (define (cdr-flot f)
  5. (force (cdr f)))
  6. (define flot-null null)
  7. (define (flot-null? f)
  8. (null? f))
  9. (define-syntax consflot
  10. (syntax-rules ()
  11. ((consflot a b) (cons a (delay b)))))
  12.  
  13.  
  14.  
  15. (define (gen-signal a b dt c)
  16.   (gen-signal_inter a b dt c 0)
  17.   )
  18.  
  19. (define (gen-signal_inter a b dt c step)
  20.  (letrec (
  21.     [signal (lambda(x) (* a (sin (+ c (* b (* x dt))))))]
  22.     [flot (consflot (signal step) (gen-signal_inter a b dt c (+ step 1)))]
  23.     ) flot))
  24.  
  25.  
  26.  
  27. (define (flot->liste n flot)
  28.   (flot->liste_inter 0 n flot)
  29.   )
  30.  
  31. (define (flot->liste_inter i n flot)
  32.   (
  33.    if (= i n) '()
  34.        (cons (car-flot flot) (flot->liste_inter (+ i 1) n (cdr-flot flot)))
  35.    
  36.   ))
  37.  
  38.  
  39. (define (quantification flot ampl nbits)
  40.   ( ;must return cons car + promise
  41.    letrec(
  42.           [signalvalue (car-flot flot)]
  43.           [classnumber (expt 2 nbits)]
  44.           [currentvalue (- (exact-floor ( * ( + ampl signalvalue) (/ classnumber 2))) (/ classnumber 2))]
  45.           [res (consflot (/ currentvalue (/ classnumber 2)) (quantification (cdr-flot flot) ampl nbits))]
  46.    ) res
  47.   )
  48.  )
  49.  
  50. ;(- (floor (* (+ amplitude value) (/ quantification 2))) (/ quantification 2)) --> amounts of eights
  51.  
  52. (define flot1 (gen-signal 1 1 0.5 0))
  53. (define flot2 (quantification (gen-signal 1 1 0.5 0) 1 4))
  54. (flot->liste 10 (quantification (gen-signal 1 1 0.5 0) 1 4))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top