In this example, we design the zero-order-hold compensator example from Oppenheim and Schafer, Discrete-Time Signal Processing, 1st ed., Section 7.7.2.
The specifications are as follows. The sampling frequency is 2 PI, the passband is [0..0.4 PI], the stopband is [0.6 PI..PI]. The frequency response is not flat in the passband, but it has the form H(f) = (f / 2) / (sin (f / 2)). (See Oppenheim and Schafer for why you may want such a filter.) The stopband error is 1/10 of the passband error. The specification file follows.
(title "Compensation for Zero-Order Hold") (cosine-symmetry) (filter-length 29) (define pi (* 4 (atan 1))) ; pi = 3.14... (define 2pi (* 2 pi)) ; 2pi = 2 * pi (define (*2pi x) (* 2pi x)) ; a function that multiplies x by 2pi (sampling-frequency (*2pi 1)) (define passband (band 0 (*2pi 0.2))) (define stopband (band (*2pi 0.3) (*2pi 0.5))) (limit-= passband (lambda (f) (if (= f 0) 1 (/ (/ f 2) (sin (/ f 2)))))) (limit-= stopband 0 .1) (output-file "example-7.coef") (plot-file "example-7.plot") (go)
A graph of the frequency response follows.
This example does not really introduce any new
but it shows some more useful Scheme constructs.
(define var value
) defines a new
variable var with value value. The similar expression
(define (var arg
) defines a function, and
it is equivalent to
A variable can contain an arbitrary object. In particular, the expression
(define passband (band 0 (*2pi 0.2)))
defines the variable
passband and sets it value to the
(band 0 (*2pi 0.2)). This construct is useful if the
passband is used in many places.
(if test if-expr else-expr
denotes a conditional expression. In our example, we use it to avoid
division by 0.