Note: I know absolutely nothing about zero crossings nor signal processing in general. However, I am doing programming exercises that require them. I've searched around but I cannot understand most of the information I'm getting. Hopefully I get clarification here. Feel free to close if it is off topic.
Here are two exercises from a computer science book (Structure and Interpretation of Computer Programs - Section 3.5.3 Exploiting the Stream Paradigm). I'll only include the relevant details.
Exercise 3.74: Alyssa P. Hacker is designing a system to process signals coming from physical sensors. One important feature she wishes to produce is a signal that describes the zero crossings of the input signal. That is, the resulting signal should be 1 whenever the input signal changes from negative to positive, -1 whenever the input signal changes from positive to negative, and 0 otherwise. (Assume that the sign of a 0 input is positive.) For example, a typical input signal with its associated zero-crossing signal would be
… 1 2 1.5 1 0.5 -0.1 -2 -3 -2 -0.5 0.2 3 4 …
… 0 0 0 0 0 -1 0 0 0 0 1 0 0 …
The associated second exercise is:
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.)
note: sense-data is the input signal
My questions are:
- What is Exercise 3.75 referring to? Is it the large amounts of 0s?
- Suppose we filter out the noise from the signals in "… 0 0 0 0 0 -1 0 0 0 0 1 0 0 …", should the resulting filtered signal be "… 0 -1 0 1 0 …" or "… -1 1 …"?
- In this exercise, smoothing is done by averaging each value of the input signal with the previous value, for the life of me, I don't understand what that should do and why we do it?