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 
00024 
00025 class FilterSpecification {
00026 public:
00027 
00028     friend class FIR;  
00029 
00030                     // Constructors
00031     FilterSpecification(unsigned numTaps = 0, unsigned numBands = 0, double *freqs = NULL, double *resps = NULL, double *weights = NULL);
00032     ~FilterSpecification();
00033     
00034                     // Accessors
00035     void setFrequencies(double *frequencies);
00036     void setResponses(double *responses);
00037     void setWeights(double *weights);
00038     void setNumTaps(unsigned numTaps);
00039     
00040     void planFilter();      // method to plan the filter (execute the search/iterate algorithm) 
00041     double *mTapData;       
00042 
00043 protected:
00044     unsigned mNumTaps;      
00045     unsigned mNumBands;     
00046     double *mFrequencies;   
00047     double *mResponses; 
00048     double *mWeights;       
00049 
00050 };
00051 
00052 /* Examples
00053     -- Simple LPF (2 bands) at 0.2 Fs with 0.05-width transition bands
00054     responses = {    1       x        0 };
00055     freqs =     { 0    0.2   0.25    0.5 };
00056     weights =   {   10               20 };
00057     
00058     -- basic BPF (3 bands) between 0.2 and 0.3 Fs with 0.05-width transition bands
00059     responses = {    0.5        x      1      x         0.8 };
00060     freqs =     { 0    0.15   0.2   0.3   0.35    0.5 };
00061     weights =   {   20               5                20 };
00062     
00063     -- Fancier dual-BPF
00064     responses = {    0        x      1       x         0        x      1        x       0 };
00065     freqs =     { 0   0.05   0.1   0.15   0.18   0.25   0.3   0.36   0.41   0.5 };
00066     weights =   {   10               1                  3                1                20 };
00067 */
00068 
00072 
00073 class FIR : public Effect {
00074 
00075 public:                     
00076 
00077     FIR (UnitGenerator & in, unsigned numTaps = 2,  float * tapDelay = NULL);
00078 //  FIR (char * file_name);                                 ///< read data from a file
00079     FIR (FilterSpecification & fs);                         
00080     FIR (UnitGenerator & in, char * fileName);
00081     FIR (UnitGenerator & in, FilterSpecification & fs);
00082     ~FIR ();
00083     
00084     void setTaps(unsigned numTaps,  float *tapDelays);
00085     void readTaps(char *fileName);
00086                     // The work method...
00087     void nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException);
00088 
00089 protected:
00090     FilterSpecification *mFilterSpec;
00091     unsigned mOffset;       // offset "pointer" for loop counting
00092                             // Here are the sample buffers (dynamically allocated)
00093     sample *mDLine;     // mNumTaps length delay line
00094     
00095     void resetDLine();      // zero-out mDline and reallocate memory if necessary;
00096     
00097                             // Parks-McClellan/Remez FIR filter design algorithm
00098     void remez(double h[], int numtaps, int numband, double bands[], double des[], double weight[], int type);
00099 
00100 };
00101 
00102 }
00103 
00104 #endif

Generated on Thu Sep 17 23:14:15 2009 for CSL by  doxygen 1.5.8