The purpose of this example is to teach you the basic usage of
gmeteor
. We start with a simple design, a low-pass filter of
length 10. The sampling frequency is 60Hz, the passband is
[0..10], and the stopband is [20..30]. The desired
frequency response is 1 in the passband, and 0 in the
stopband. (The frequency response in the transition band
[10..20] is not specified.) This is an instance of the
approximation design style: we specify the ideal response, and
let gmeteor
approximate it.
In order to design the filter, you must create a file called ‘example-1.scm’ with the following contents.
; A simple filter (title "A simple filter") (verbose #t) (cosine-symmetry) (filter-length 10) (sampling-frequency 60) (limit-= (band 0 10) 1) (limit-= (band 20 30) 0) (output-file "example-1.coef") (plot-file "example-1.plot") (go)
Then, you must invoke gmeteor
as follows.
gmeteor example-1.scm
You can plot the file ‘example-1.plot’, obtaining a graph of the frequency response like the following.
As mentioned in Introduction, the specification file
‘example-1.scm’ is a program written in the Scheme programming
language, but do not worry if you do not know Scheme. All you need to
know is that the file consists of a sequence of commands, and that each
command is enclosed within a pair of parenteses, as in
(filter-length 10)
. Do not forget these parentheses, because
Scheme requires them. In the rest of this section, we discuss the
meaning of each command individually.
The first line
; A simple filter
is a comment. Comments are introduced by a single semicolon and last until the end of the line. You can add comments anywhere you wish.
The expression (title "A simple filter")
specifies an optional
title for the filter. The title does not affect the computation in any
way, and it is used for documentation purposes. The title appears in
the output file when gmeteor
runs in verbose mode.
The command (verbose #t)
tells gmeteor
to run in verbose
mode. In Scheme, the expression #t
denotes the boolean true
value, while #f
denotes the false value. In non-verbose mode,
gmeteor
outputs the filter coefficients (and nothing else) to the
output file. In verbose mode, gmeteor
prints additional
information such as the title, the sampling frequency, and so on.
The command (cosine-symmetry)
specifies that the frequency
response H(f) is an even function. In linear-phase FIR
filters—the only kind gmeteor
knows about—H(f) is either
an even or an odd function of f. A function H(f) is
even whenever H(f) = H(-f), and odd whenever
H(f) = -H(-f). To obtain an odd frequency response, use the
command (sine-symmetry)
. If neither symmetry is specified,
(cosine-symmetry)
is the default.
The command (filter-length 10)
specifies the length of the
filter. In this case, the designed filter has 10 coefficients.
The command (sampling-frequency 60)
sets the sampling frequency
to 60Hz.
The command (limit-= (band 0 10) 1)
specifies the passband
constraint: the frequency response is 1 for frequencies in the
band [0..10]. The expression (band A B)
creates a
band, i.e., the interval of frequencies from A
to B
.
The expression (limit-=
band value)
specifies that
the frequency response should be equal to value in the band
band. (gmeteor
provides additional constructs
(limit-<=
band value)
and (limit->=
band
value)
to set upper and lower bounds to the frequency response,
respectively. See Example 6.)
In a similar fashion, the command (limit-= (band 20 30) 0)
specifies the stopband constraint, namely, the frequency response should
be 0 in the stopband [20..30].
The command (output-file "example-1.coef")
sets the name of the
output file, which contains the filter coefficients. In verbose mode,
the output file also contains additional information. If the output
file is not specified, gmeteor
prints to standard output. If the
output file is ‘#f’, gmeteor
prints nothing.
The command (plot-file "example-1.plot")
sets the name of the
plot file, which contains a sequence of (x, y) pairs, where
y=H(x) and H is the frequency response. You can use
‘gnuplot’ or ‘graph’ to view the plot file. (see graph.) If the plot file is not specified, gmeteor
does not
produce a plot.
Finally, the command (go)
tells gmeteor
to compute the
filter and produce the desired output files. Do not omit this line,
otherwise gmeteor
will exit silently without doing anything.