Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (provide flot->liste)
- (provide gen-signal)
- (provide quantification)
- (provide passage-par-zero)
- ; ***************** IFT359 / TP4 Groupe 2
- ; ***************** Lafreniere, Jonathan 17084316
- ; ***************** Pelletier, Robin 17056187
- (define (car-flot f)
- (car f))
- (define (cdr-flot f)
- (force (cdr f)))
- (define flot-null null)
- (define (flot-null? f)
- (null? f))
- (define-syntax consflot
- (syntax-rules ()
- ((consflot a b) (cons a (delay b)))))
- (define (gen-signal a b dt c)
- (gen-signal_inter a b dt c 0)
- )
- (define (gen-signal_inter a b dt c step)
- (let* (
- [signal (lambda(x) (* a (sin (+ c (* b (* x dt))))))]
- [flot (consflot (signal step) (gen-signal_inter a b dt c (+ step 1)))]
- ) flot))
- (define (flot->liste n flot)
- (flot->liste_inter 0 n flot)
- )
- (define (flot->liste_inter i n flot)
- (
- if (= i n) '()
- (cons (car-flot flot) (flot->liste_inter (+ i 1) n (cdr-flot flot)))
- ))
- (define (quantification flot amplitude nbits)
- (consflot (trouverInterval(car-flot flot) amplitude nbits)
- (quantification (cdr-flot flot) amplitude nbits)
- ))
- (define (trouverInterval f amp nbits [debut (* amp -1)])
- (if (= debut amp) (- amp (/ amp (/ (expt 2 nbits) 2)))
- (cond[(= f (* amp -1)) (* amp -1)]
- [(<= f (+ debut (/ amp (/ (expt 2 nbits) 2 )))) debut]
- [else (trouverInterval f amp nbits (+ debut(/ amp (/ (expt 2 nbits) 2))))]))
- )
- (define (passage-par-zero flot)
- (passage-par-zero_inter (cdr-flot flot) (car-flot flot))
- )
- (define (passage-par-zero_inter flot prev_value)
- (let*(
- [current_value (car-flot flot)]
- [flot_value (if (and ( < prev_value 0) (>= current_value 0)) 1
- (if(and (>= prev_value 0) (< current_value 0)) -1 0)
- )
- ]
- [res (consflot flot_value (passage-par-zero_inter (cdr-flot flot) current_value))]
- ) res
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement