const std::vector<float> &taps,
float oversample_rate)
{
- return gr_pfb_channelizer_ccf_sptr (new gr_pfb_channelizer_ccf (numchans, taps,
+ return gnuradio::get_initial_sptr(new gr_pfb_channelizer_ccf (numchans, taps,
oversample_rate));
}
gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans,
const std::vector<float> &taps,
float oversample_rate)
- : gr_sync_interpolator ("pfb_channelizer_ccf",
- gr_make_io_signature (numchans, numchans, sizeof(gr_complex)),
- gr_make_io_signature (1, 1, numchans*sizeof(gr_complex)),
- oversample_rate),
- d_updated (false), d_oversample_rate(oversample_rate)
+ : gr_block ("pfb_channelizer_ccf",
+ gr_make_io_signature (numchans, numchans, sizeof(gr_complex)),
+ gr_make_io_signature (1, 1, numchans*sizeof(gr_complex))),
+ d_updated (false), d_numchans(numchans), d_oversample_rate(oversample_rate)
{
- d_numchans = numchans;
+ // 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 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]");
+
+ set_relative_rate(1.0/intp);
+
d_filters = std::vector<gr_fir_ccf*>(d_numchans);
// Create an FIR filter for each channel and zero out the taps
// Create the FFT to handle the output de-spinning of the channels
d_fft = new gri_fft_complex (d_numchans, false);
+
+ // Although the filters change, we use this look up table
+ // to set the index of the FFT input buffer, which equivalently
+ // 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(unsigned int i = 0; i < d_numchans; i++) {
+ d_idxlut[i] = d_numchans - ((i + d_rate_ratio) % d_numchans) - 1;
+ }
+
+ // Calculate the number of filtering rounds to do to evenly
+ // align the input vectors with the output channels
+ d_output_multiple = 1;
+ while((d_output_multiple * d_rate_ratio) % d_numchans != 0)
+ d_output_multiple++;
+ set_output_multiple(d_output_multiple);
}
gr_pfb_channelizer_ccf::~gr_pfb_channelizer_ccf ()
{
+ delete [] d_idxlut;
+
for(unsigned int i = 0; i < d_numchans; i++) {
delete d_filters[i];
}
}
// Set the history to ensure enough input items for each filter
- set_history (d_taps_per_filter);
+ set_history (d_taps_per_filter+1);
d_updated = true;
}
int
-gr_pfb_channelizer_ccf::work (int noutput_items,
- gr_vector_const_void_star &input_items,
- gr_vector_void_star &output_items)
+gr_pfb_channelizer_ccf::general_work (int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
{
gr_complex *in = (gr_complex *) input_items[0];
gr_complex *out = (gr_complex *) output_items[0];
return 0; // history requirements may have changed.
}
-#if 0
- int M = d_numchans;
- int N = d_oversample_rate;
- int lastidx = 0, i = 1, k = 0, m = 0, n = 0;
-
- int *idx = new int[M];
- for(k = 0; k < M; k++)
- idx[k] = 0;
-
- while(i <= noutput_items/N) {
- unsigned int x = 0;
- unsigned int y = 0;
- for(n = N-1; n >= 0; n--) {
- for(k = 0; k < M/N; k++)
- idx[(lastidx + k) % M]++;
- lastidx = (lastidx + M/N) % M;
-
- x += M/N;
- y = M/N;
- for(m = 0; m < M; m++) {
- in = (gr_complex*)input_items[m];
-
- x = (M + x - 1) % M;
- y = (M + y - 1) % M;
-
- d_fft->get_inbuf()[y] = d_filters[x]->filter(&in[idx[m]]);
- }
-
- d_fft->execute();
- memcpy(out, d_fft->get_outbuf(), d_numchans*sizeof(gr_complex));
- out += d_numchans;
- }
- i++;
- }
-
-#else
-
- int M = d_oversample_rate;
- int N = d_numchans;
- int r = N / M;
-
int n=1, i=-1, j=0, last;
- //int state = 0;
-
- // Although the filters change, we use this look up table
- // to set the index of the FFT input buffer, which equivalently
- // performs the FFT shift operation on every other turn.
- int *idxlut = new int[N];
- for(int ii = 0; ii < N; ii++) {
- idxlut[ii] = N - ((ii + r) % N) - 1;
- }
-
- while(n <= noutput_items/M) {
+ int toconsume = (int)rintf(noutput_items/d_oversample_rate);
+ while(n <= toconsume) {
j = 0;
- i = (i + r) % N;
+ i = (i + d_rate_ratio) % d_numchans;
last = i;
while(i >= 0) {
in = (gr_complex*)input_items[j];
- //d_fft->get_inbuf()[(i + state*r) % N] = d_filters[i]->filter(&in[n]);
- d_fft->get_inbuf()[idxlut[j]] = d_filters[i]->filter(&in[n]);
+ d_fft->get_inbuf()[d_idxlut[j]] = d_filters[i]->filter(&in[n]);
j++;
i--;
}
- i = N-1;
+ i = d_numchans-1;
while(i > last) {
in = (gr_complex*)input_items[j];
- //d_fft->get_inbuf()[(i + state*r) % N] = d_filters[i]->filter(&in[n-1]);
- d_fft->get_inbuf()[idxlut[j]] = d_filters[i]->filter(&in[n-1]);
+ d_fft->get_inbuf()[d_idxlut[j]] = d_filters[i]->filter(&in[n-1]);
j++;
i--;
}
- n += (i+r) >= N;
- //state ^= 1;
+ n += (i+d_rate_ratio) >= (int)d_numchans;
// despin through FFT
d_fft->execute();
memcpy(out, d_fft->get_outbuf(), d_numchans*sizeof(gr_complex));
out += d_numchans;
}
-
- delete [] idxlut;
-#endif
-
+ consume_each(toconsume);
return noutput_items;
}