FIR.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 // It is provided under GPL by Jake Janovetz (janovetz@uiuc.edu)
00010 
00011 #ifndef CSL_FIR_H
00012 #define CSL_FIR_H
00013 
00014 #include "CSL_Core.h"
00015 
00016 namespace csl {
00017 
00018 
00019 class FIR;  
00020 
00021 // FilterSpecification class for designing multi-band-pass FIR filter impulse responses
00022 
00023 class FilterSpecification {
00024 public:
00025 
00026     friend class FIR;  
00027 
00028                     // Constructors
00029     FilterSpecification(unsigned numTaps = 0, unsigned numBands = 0, double *freqs = NULL, double *resps = NULL, double *weights = NULL);
00030     ~FilterSpecification();
00031     
00032                     // Accessors
00033     void setFrequencies(double *frequencies);
00034     void setResponses(double *responses);
00035     void setWeights(double *weights);
00036     void setNumTaps(unsigned numTaps);
00037     
00038     void planFilter();      // method to plan the filter (execute the search/iterate algorithm) 
00039 
00040 protected:
00041     unsigned mNumTaps;      
00042     unsigned mNumBands;     
00043     double *mFrequencies;   
00044     double *mResponses; 
00045     double *mWeights;       
00046     double *mTapData;       
00047 
00048 };
00049 
00050 /* Examples
00051     -- Simple LPF (2 bands) at 0.2 Fs with 0.05-width transition bands
00052     responses = {    1       x        0 };
00053     freqs =     { 0    0.2   0.25    0.5 };
00054     weights =   {   10               20 };
00055     
00056     -- basic BPF (3 bands) between 0.2 and 0.3 Fs with 0.05-width transition bands
00057     responses = {    0.5        x      1      x         0.8 };
00058     freqs =     { 0    0.15   0.2   0.3   0.35    0.5 };
00059     weights =   {   20               5                20 };
00060     
00061     -- Fancier dual-BPF
00062     responses = {    0        x      1       x         0        x      1        x       0 };
00063     freqs =     { 0   0.05   0.1   0.15   0.18   0.25   0.3   0.36   0.41   0.5 };
00064     weights =   {   10               1                  3                1                20 };
00065 */
00066 
00067 // FIR Filter class
00068 
00069 class FIR : public Effect {
00070 
00071 public:                     
00072 
00073     FIR (UnitGenerator & in, unsigned numTaps = 2,  float * tapDelay = NULL);
00074 //  FIR (char * file_name);                                 ///< read data from a file
00075     FIR (FilterSpecification & fs);                         
00076     FIR (UnitGenerator & in, char * fileName);
00077     FIR (UnitGenerator & in, FilterSpecification & fs);
00078     ~FIR ();
00079     
00080     void setTaps(unsigned numTaps,  float *tapDelays);
00081     void readTaps(char *fileName);
00082                     // The work method...
00083     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00084 
00085 protected:
00086     FilterSpecification *mFilterSpec;
00087     unsigned mOffset;       // offset "pointer" for loop counting
00088                             // Here are the sample buffers (dynamically allocated)
00089     sample *mDLine;     // mNumTaps length delay line
00090     
00091     void resetDLine();      // zero-out mDline and reallocate memory if necessary;
00092     
00093                             // Parks-McClellan/Remez FIR filter design algorithm
00094     void remez(double h[], int numtaps, int numband, double bands[], double des[], double weight[], int type);
00095 
00096 };
00097 
00098 }
00099 
00100 #endif

Generated on Fri Apr 6 20:18:13 2007 for CSL by  doxygen 1.4.5-20051010