Advertisement
jlafreniere96

Untitled

Nov 20th, 2019
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.02 KB | None | 0 0
  1. #lang racket
  2.  
  3. (provide flot->liste)
  4. (provide gen-signal)
  5. (provide quantification)
  6. (provide passage-par-zero)
  7.  
  8. ; ***************** IFT359 / TP4 Groupe 2
  9. ; ***************** Lafreniere, Jonathan 17084316
  10. ; ***************** Pelletier, Robin 17056187
  11.  
  12. (define (car-flot f)
  13. (car f))
  14. (define (cdr-flot f)
  15. (force (cdr f)))
  16. (define flot-null null)
  17. (define (flot-null? f)
  18. (null? f))
  19. (define-syntax consflot
  20. (syntax-rules ()
  21. ((consflot a b) (cons a (delay b)))))
  22.  
  23.  
  24.  
  25. (define (gen-signal a b dt c)
  26.   (gen-signal_inter a b dt c 0)
  27.   )
  28.  
  29. (define (gen-signal_inter a b dt c step)
  30.  (let* (
  31.     [signal (lambda(x) (* a (sin (+ c (* b (* x dt))))))]
  32.     [flot (consflot (signal step) (gen-signal_inter a b dt c (+ step 1)))]
  33.     ) flot))
  34.  
  35.  
  36.  
  37. (define (flot->liste n flot)
  38.   (flot->liste_inter 0 n flot)
  39.   )
  40.  
  41. (define (flot->liste_inter i n flot)
  42.   (
  43.    if (= i n) '()
  44.        (cons (car-flot flot) (flot->liste_inter (+ i 1) n (cdr-flot flot)))
  45.    
  46.   ))
  47.  
  48.  
  49. (define (quantification flot amplitude nbits)
  50.   (consflot (trouverInterval(car-flot flot) amplitude nbits)
  51.              (quantification (cdr-flot flot) amplitude nbits)
  52.  ))
  53.  
  54. (define (trouverInterval f amp nbits [debut (* amp -1)])
  55.   (if (= debut amp) (- amp (/ amp (/ (expt 2 nbits) 2)))
  56.       (cond[(= f (* amp -1)) (* amp -1)]
  57.            [(<= f (+ debut (/ amp (/ (expt 2 nbits) 2 )))) debut]
  58.            [else (trouverInterval f amp nbits (+ debut(/ amp (/ (expt 2 nbits) 2))))]))
  59.   )
  60.  
  61.  
  62. (define (passage-par-zero flot)
  63.   (passage-par-zero_inter (cdr-flot flot) (car-flot flot))
  64.  )
  65.  
  66. (define (passage-par-zero_inter flot prev_value)
  67.   (let*(
  68.         [current_value (car-flot flot)]
  69.         [flot_value (if (and ( < prev_value 0) (>= current_value 0)) 1
  70.                         (if(and (>= prev_value 0) (< current_value 0)) -1 0)  
  71.                        
  72.                         )
  73.                                    
  74.             ]
  75.         [res (consflot flot_value (passage-par-zero_inter (cdr-flot flot) current_value))]
  76.      
  77.         ) res
  78.     )
  79.   )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement