--- /dev/null
+#lang racket
+
+(define (RC R C dt)
+ (define (RC1 i initial-vc)
+ (add-streams (integral (scale-stream i (/ 1.0 C)) initial-vc dt)
+ (scale-stream i R)))
+ RC1)
+
+(define RC1 (RC 5 1 0.5))
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(define (make-zero-crossings input-stream last-value)
+ (cons-stream
+ (sign-change-detector (stream-car input-stream) last-value)
+ (make-zero-crossings (stream-cdr input-stream)
+ (stream-car input-stream))))
+
+(define (sign-change-detector current-value previous-value)
+ (cond [(and (positive? previous-value)
+ (positive? current-value)) 0]
+ [(and (positive? previous-value)
+ (negative? current-value)) -1]
+ [(and (negative? previous-value?)
+ (positive? current-value)) +1]
+ [else 0]))
+
+(define zero-crossings (make-zero-crossings sense-data 0))
+
+;; eva's implementation
+(define zc (stream-map sign-change-detector sense-data (cons-stream 0 sense-data)))
--- /dev/null
+#lang racket
+
+#|
+
+The procedure find average of the current sensor value with the last average value. This
+is wrong. the symbol 'last-value' is used differently in different places. In the average
+calculation, this should be the last sensor value. In the sign-change-detector this should
+be last average value.
+
+Solution is for the make-zero-crossing to accept the last-average-value as another parameter.
+
+|#
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(define (smooth stream)
+ (cons-stream (/ (+ (stream-car stream)
+ (stream-car (stream-cdr stream)))
+ 2.0)
+ (smooth (stream-cdr stream))))
+
+(define (make-zero-crossings input-stream last-value)
+ (cons-stream
+ (sign-change-detector (stream-car input-stream) last-value)
+ (make-zero-crossings (stream-cdr input-stream)
+ (stream-car input-stream))))
+
+(define zero-crossings (make-zero-crossings (smooth sense-data) 0))
+
+
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(define (integral integrand delayed-initial-value dt)
+ (cons-stream initial-value
+ (let ((integrand (force delayed-initial-value)))
+ (if (stream-null? integrand)
+ the-empty-stream
+ (integral (stream-cdr integrand)
+ (+ (* dt (stream-car integrand))
+ initial-value)
+ dt)))))
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(define (solve-2nd a b y0 dy0 dt)
+ (define y (integral (delay dy) y0 dt))
+ (define dy (integral (delay ddy) dy0 dt))
+ (define ddy (add-streams (scale-stream dy a)
+ (scale-stream y b)))
+ y)
+
--- /dev/null
+#lang racket
+
+(define (solve-2nd f y0 dy0 dt)
+ (define y (integral (delay dy) y0 dt))
+ (define dy (integral (delay ddy) dy0 dt))
+ (define ddy (stream-map f dy y))
+ y)
\ No newline at end of file
--- /dev/null
+#lang racket
+
+(define (RLC R L C dt)
+ (define (rlc1 vc0 il0)
+ (define vc (integral (delay dvc) vc0 dt))
+ (define dvc0 (scale-stream il (/ -1 C)))
+ (define il (integral (delay dil) il0 dt))
+ (define dil (add-streams (scale-stream vc (/ 1 L))
+ (scale-stream il (/ -R L))))
+ (stream-map (lambda (x y) (cons x y)) vc il)))
+
+
--- /dev/null
+#lang racket
+
+(define (rand-seq init req-stream)
+ (let ((req (stream-car req-stream)))
+ (cond ((eq? req 'reset)
+ (let ((new-init (stream-car (stream-cdr req-stream))))
+ (let ((new-rand-val (rand-update new-init)))
+ (cons-stream
+ new-rand-val
+ (rand-seq new-rand-val
+ (stream-cdr (stream-cdr req-stream)))))))
+ ((eq? req 'generate)
+ (let ((new-val (rand-update init)))
+ (cons-stream
+ new-val
+ (rand-seq new-val (stream-cdr req-stream))))))))
+
\ No newline at end of file