CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

FIR.h
Go to the documentation of this file.
1 ///
2 /// FIR.h -- CSL filter specification and FIR filter classes
3 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 ///
5 /// The FilterSpecification uses the Parks-McClellan/Remez iterative algorithm
6 // It is provided under GPL by Jake Janovetz (janovetz@uiuc.edu)
7 ///
8 /// The FIR implementation is based on a minimal version written for the MAT 240B course;
9 /// it does not use the CSL RingBuffer helper class.
10
11 #ifndef CSL_FIR_H
12 #define CSL_FIR_H
13
14 #include "CSL_Core.h"
15
16 namespace csl {
17
18
19 class FIR; ///< forward declaration
20
21 ///
22 /// FilterSpecification class for designing multi-band-pass FIR filter impulse responses
23 ///
24
25 class FilterSpecification {
26 public:
27
28 friend class FIR; ///< Allow the FIR to access private members of this class.
29
30 // Constructors
31 FilterSpecification(unsigned numTaps = 0, unsigned numBands = 0, double *freqs = NULL, double *resps = NULL, double *weights = NULL);
32 ~FilterSpecification();
33
34 // Accessors
35 void setFrequencies(double *frequencies);
36 void setResponses(double *responses);
37 void setWeights(double *weights);
38 void setNumTaps(unsigned numTaps);
39
40 void planFilter(); // method to plan the filter (execute the search/iterate algorithm)
41 double *mTapData; ///< the FIR tap weights (created by the planFilter method)
42
43 protected:
44 unsigned mNumTaps; ///< number of taps desired
45 unsigned mNumBands; ///< length of specification
46 double *mFrequencies; ///< band edge frequencies (2 * mNumBands)
47 double *mResponses; ///< band responses (mNumBands)
48 double *mWeights; ///< band error weights (mNumBands)
49
50 };
51
52 /* Examples
53 -- Simple LPF (2 bands) at 0.2 Fs with 0.05-width transition bands
54 responses = { 1 x 0 };
55 freqs = { 0 0.2 0.25 0.5 };
56 weights = { 10 20 };
57
58 -- basic BPF (3 bands) between 0.2 and 0.3 Fs with 0.05-width transition bands
59 responses = { 0.5 x 1 x 0.8 };
60 freqs = { 0 0.15 0.2 0.3 0.35 0.5 };
61 weights = { 20 5 20 };
62
63 -- Fancier dual-BPF
64 responses = { 0 x 1 x 0 x 1 x 0 };
65 freqs = { 0 0.05 0.1 0.15 0.18 0.25 0.3 0.36 0.41 0.5 };
66 weights = { 10 1 3 1 20 };
67 */
68
69 ///
70 /// FIR Filter class
71 ///
72
73 class FIR : public Effect {
74
75 public: /// Various constructors
76 /// Takes a UGen, and optionally the number of taps and the tap IR array.
77 FIR (UnitGenerator & in, unsigned numTaps = 2, float * tapDelay = NULL);
78 // FIR (char * file_name); ///< read data from a file
79 FIR (FilterSpecification & fs); ///< give it a filter specification object
80 FIR (UnitGenerator & in, char * fileName);
81 FIR (UnitGenerator & in, FilterSpecification & fs);
82 ~FIR ();
83
84 void setTaps(unsigned numTaps, float *tapDelays);
85 void readTaps(char *fileName);
86 // The work method...
87 void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
88
89 protected:
90 FilterSpecification *mFilterSpec;
91 unsigned mOffset; // offset "pointer" for loop counting
92 // Here are the sample buffers (dynamically allocated)
93 sample *mDLine; // mNumTaps length delay line
94
95 void resetDLine(); // zero-out mDline and reallocate memory if necessary;
96
97 // Parks-McClellan/Remez FIR filter design algorithm
98 void remez(double h[], int numtaps, int numband, double bands[], double des[], double weight[], int type);
99
100 };
101
102 }
103
104 #endif