The oversampling rate can be only a few values as defined by the number of channels...
authorTom Rondeau <trondeau@vt.edu>
Tue, 13 Apr 2010 01:22:20 +0000 (21:22 -0400)
committerTom Rondeau <trondeau@vt.edu>
Tue, 13 Apr 2010 01:22:20 +0000 (21:22 -0400)
This now checks to make sure the user-specified rate is valid.
Also added some documentation to describe the oversample rate parameter.

gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc
gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.h

index e13a933ea7b4d4711fc91aa65f618fb00a324e65..824a78dd97d82376c604e8f8dd95724c4f003e0a 100644 (file)
@@ -49,6 +49,17 @@ gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans,
              gr_make_io_signature (1, 1, numchans*sizeof(gr_complex))),
     d_updated (false), d_numchans(numchans), d_oversample_rate(oversample_rate)
 {
+  // The over sampling rate must be rationally related to the number of channels
+  // in that it must be N/i for i in [1,N], which gives an outputsample rate 
+  // of [fs/N, fs] where fs is the input sample rate.
+  // This tests the specified input sample rate to see if it conforms to this
+  // requirement within a few significant figures.
+  double intp = 0;
+  double x = (10000.0*rint(numchans / oversample_rate)) / 10000.0;
+  double fltp = modf(numchans / oversample_rate, &intp);
+  if(fltp != 0.0)
+    throw std::invalid_argument("gr_pfb_channelizer: oversample rate must be N/i for i in [1, N]"); 
+
   d_filters = std::vector<gr_fir_ccf*>(d_numchans);
 
   // Create an FIR filter for each channel and zero out the taps
@@ -68,7 +79,7 @@ gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans,
   // performs the FFT shift operation on every other turn.
   d_rate_ratio = (int)rintf(d_numchans / d_oversample_rate);
   d_idxlut = new int[d_numchans];
-  for(int i = 0; i < d_numchans; i++) {
+  for(unsigned int i = 0; i < d_numchans; i++) {
     d_idxlut[i] = d_numchans - ((i + d_rate_ratio) % d_numchans) - 1;
   }
 
@@ -175,7 +186,7 @@ gr_pfb_channelizer_ccf::general_work (int noutput_items,
       i--;
     }
 
-    n += (i+d_rate_ratio) >= d_numchans;
+    n += (i+d_rate_ratio) >= (int)d_numchans;
 
     // despin through FFT
     d_fft->execute();
index e33e1938e36d10ae3b23469f633d72a4aec67466..d56ccdbc6c3fca32b6cb86539b18cd82bb4f60fc 100644 (file)
@@ -89,6 +89,19 @@ class gri_fft_complex;
  *      <B><EM>self._taps = gr.firdes.low_pass_2(1, fs, BW, TB, 
  *           attenuation_dB=ATT, window=gr.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
  *
+ * The filter output can also be overs ampled. The over sampling rate 
+ * is the ratio of the the actual output sampling rate to the normal 
+ * output sampling rate. It must be rationally related to the number 
+ * of channels as N/i for i in [1,N], which gives an outputsample rate
+ * of [fs/N, fs] where fs is the input sample rate and N is the number
+ * of channels.
+ *
+ * For example, for 6 channels with fs = 6000 Hz, the normal rate is 
+ * 6000/6 = 1000 Hz. Allowable oversampling rates are 6/6, 6/5, 6/4, 
+ * 6/3, 6/2, and 6/1 where the output sample rate of a 6/1 oversample
+ * ratio is 6000 Hz, or 6 times the normal 1000 Hz. A rate of 6/5 = 1.2,
+ * so the output rate would be 1200 Hz.
+ *
  * The theory behind this block can be found in Chapter 6 of 
  * the following book.
  *
@@ -104,6 +117,18 @@ class gr_pfb_channelizer_ccf : public gr_block
    * Build the polyphase filterbank decimator.
    * \param numchans (unsigned integer) Specifies the number of channels <EM>M</EM>
    * \param taps    (vector/list of floats) The prototype filter to populate the filterbank.
+   * \param oversample_rate (float)   The over sampling rate is the ratio of the the actual
+   *                                  output sampling rate to the normal output sampling rate.
+   *                                   It must be rationally related to the number of channels
+   *                                 as N/i for i in [1,N], which gives an outputsample rate 
+   *                                 of [fs/N, fs] where fs is the input sample rate and N is
+   *                                 the number of channels.
+   *                                 
+   *                                 For example, for 6 channels with fs = 6000 Hz, the normal
+   *                                 rate is 6000/6 = 1000 Hz. Allowable oversampling rates
+   *                                 are 6/6, 6/5, 6/4, 6/3, 6/2, and 6/1 where the output
+   *                                 sample rate of a 6/1 oversample ratio is 6000 Hz, or
+   *                                 6 times the normal 1000 Hz.
    */
   friend gr_pfb_channelizer_ccf_sptr gr_make_pfb_channelizer_ccf (unsigned int numchans,
                                                                  const std::vector<float> &taps,