|
|
Introduction
The firfilter
package is a set of C++ classes which provide commonly used building
blocks for constructing a FIR filter
system.
The current set of building blocks are:
In addition to these building blocks, there are also several functions
for stimulating and measuring the system response:
-
runFilters - unit
impulse, single
frequency, frequency sweep or N-equally spaced (i.e., xn
of DFT)
-
spectralAnalysis
- DFT
analysis
An example
A 10-band
equalizer system was constructed and analyzed using the firfilter
package and documented here.
Running the equalizer example
- Download
the firfilter files.
- unzip
and untar (where x.y is the
version):
> tar zxf firfilter-x.y.tar.gz
- cd
to the filter/examples/equalizer
directory and make a non-debug
executable:
> cd
/.../firfilter-x.y/filter/examples/equalizer
> make ndebug
- If
successful, you should see similar (value of linux_xxx depends on uname -ps) to:
> ls linux*/ndebug/*exe
linux_x86_64/ndebug/equalizer.exe
- Run
the equalizer without any arguments:
> linux*/ndebug/equalizer.exe
creates
the filters and system described here.
This run also outputs several text files which can be viewed using graph.
The files are prefixed with lpf, bpf
and hpf
for the
lowpass, bandpass and highpass filters, respectively. The cutoff
frequencies are also specified in the basename, too. For example,
during design/generation, DFTs of the (windowed) filters are created:
lpf_fc45.dft.txt
|
DFT
of
lowpass filter
with (design constraint) cutoff of 45 Hz.
|
bpf_fl45_fh75.dft.txt
|
DFT
of
bandpass filter
with (design constraint) cutoffs of (lower-band) 45 Hz and (upper band)
75 Hz.
|
hpf_fc10665.dft.txt
|
DFT
of
highpass filter
with (design constraint) cutoff of 10.665 kHz.
|
After the filters are generated, spectral analysis
(DFT) of the entire system is done creating a series of spectralMagDb
files. Each of these files corresponds to an endpoint in the
system. These endpoints are annotated on the original schematic and shown here as Ei
labels (where i is [0-13]).
spectralMagDb_10g.txt
|
DFT
of
summation point
of the lowest 5 equalizer bands with fc [30,60,120,250,500]
Hz.
|
spectralMagDb_11g.txt
|
DFT
of
summation point
of the middle 2 equalizer bands with fc [1, 2] kHz. |
spectralMagDb_12g.txt
|
DFT
of
summation point
of the upper 3 equalizer bands with fc [4, 8, 16] kHz. |
These DFTs can be viewed using the viewSpectral.rb script:
>
./viewSpectral.rb
That script
requires Ruby and graph. You can
also view the results at these links:
- Next,
we'll run some single and frequency sweep runs, using a (Ruby) script runFilters.rb:
>
./runFilters.rb |& tee
runFilters.log
First, the single
frequency
sweeps are done starting with an impulse response. The sweep
results are dumped into the N64
subdirectory (N64
indicates filter order 64). The single frequency results are
named fsweep_fx_y.txt,
where x
is the single frequency. The value y can be
one of:
- xn, which
is the x[n]
input stimulus to the filter system
- yig, where i is a
value 1...13 which indicates the endpoint in the system. For now,
we'll just focus on 10...13, where 10...12 are the summation points shown here and 13 is the filter output y[n].
The yig
indicates gold reference, which is the double precision
result. (The yir
refer
to the revised results, which are fixed precision. More on these
later!)
The
impulse
response results can be viewed as:
> graph -T X -C -x 0 500
N64/fsweep_f0_y{10,11,12,13}g.txt
and vary the -x
arguments, etc. for more/less detail.
There are 4 single sweeps at frequencies: 0 (impulse), 120, 1500,
8000. The latter 3 correspond to middle points of each of the 3
banks. Thus, as you view the different outputs note the
attenuation at all but the output (y13) and the appropriate bank output: y10, 11 or
12.
For example, view the f=120 response:
> foreach i (10 11 12 13)
graph -T X -C -x 1000 2000 -L "i=${i}" N64/fsweep_f120_{xn,y${i}g}.txt
end
Then, repeat for the other frequencies:
> foreach i ( 10 11 12 13 )
graph -T X -C -x 1000 1100 -L "i=${i}" N64/fsweep_f1500_{xn,y${i}g}.txt
end
> foreach i ( 10 11 12 13 )
graph -T X -C -x 1000 1050 -L "i=${i}" N64/fsweep_f8000_{xn,y${i}g}.txt
end
You
should verify
that the expected attenuations occur at the expected endpoints (of the
corresponding graph results)!
- Notice that a
series of N64/*r.txt files were also created during these runs.
These *r files are the revised results, and the *g files are the golden
results. The revised are simulation using fixed point arithmatic
and the golden are simulations using (full) double precision.
The (current) revised precision is 18-bit: using 14 fraction and 4
integer (2's complement) bits.
The bit-accurate (revised) simulation capability will be utilized here
to co-simulate/verify a synthesizable Verilog HDL model of the 10-band
graphic equalizer.
|