Exercise 3.75: Unfortunately, Alyssa’s
zero-crossing detector in Exercise 3.74 proves to be insufficient,
because the noisy signal from the sensor leads to spurious zero crossings. Lem
E. Tweakit, a hardware specialist, suggests that Alyssa smooth the signal to
filter out the noise before extracting the zero crossings. Alyssa takes his
advice and decides to extract the zero crossings from the signal constructed by
averaging each value of the sense data with the previous value. She explains
the problem to her assistant, Louis Reasoner, who attempts to implement the
idea, altering Alyssa’s program as follows:
(define (make-zero-crossings
input-stream last-value)
(let ((avpt
(/ (+ (stream-car input-stream)
last-value)
2)))
(cons-stream
(sign-change-detector avpt last-value)
(make-zero-crossings
(stream-cdr input-stream) avpt))))
This does not correctly implement Alyssa’s plan. Find the bug that Louis has
installed and fix it without changing the structure of the program. (Hint: You
will need to increase the number of arguments to make-zero-crossings.)
练习 3.75:遗憾的是,Alyssa 在练习 3.74 中设计的零交叉检测器被证明不够用,因为传感器发出的带噪声信号会导致虚假的零交叉。硬件专家 Lem E. Tweakit 建议 Alyssa 在提取零交叉点之前先对信号做平滑处理以滤除噪声。Alyssa 接受了他的建议,决定从由每个传感器数据值与前一个值的平均值构成的信号中提取零交叉点。她向助手 Louis Reasoner 解释了这个问题,Louis 尝试实现该思路,将 Alyssa 的程序修改如下:
(define (make-zero-crossings
input-stream last-value)
(let ((avpt
(/ (+ (stream-car input-stream)
last-value)
2)))
(cons-stream
(sign-change-detector avpt last-value)
(make-zero-crossings
(stream-cdr input-stream) avpt))))
这并没有正确实现 Alyssa 的方案。找出 Louis 引入的错误,并在不改变程序结构的前提下修复它。(提示:你需要增加 make-zero-crossings 的参数个数。)
(define (make-zero-crossings
input-stream last-value)
(let ((avpt
(/ (+ (stream-car input-stream)
last-value)
2)))
(cons-stream
(sign-change-detector avpt last-value)
(make-zero-crossings
(stream-cdr input-stream) avpt))))