GNU Radio v3.6.2-149-ga6d285d9 C++ API
pfb_channelizer_ccf.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2009,2010,2012 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 
00024 #ifndef INCLUDED_FILTER_PFB_CHANNELIZER_CCF_H
00025 #define INCLUDED_FILTER_PFB_CHANNELIZER_CCF_H
00026 
00027 #include <filter/api.h>
00028 #include <gr_block.h>
00029 
00030 namespace gr {
00031   namespace filter {
00032 
00033     /*!
00034      * \class pfb_channelizer_ccf
00035      *
00036      * \brief Polyphase filterbank channelizer with
00037      *        gr_complex input, gr_complex output and float taps
00038      *
00039      * \ingroup filter_blk
00040      * \ingroup pfb_blk
00041      *
00042      * This block takes in complex inputs and channelizes it to <EM>M</EM>
00043      * channels of equal bandwidth. Each of the resulting channels is
00044      * decimated to the new rate that is the input sampling rate
00045      * <EM>fs</EM> divided by the number of channels, <EM>M</EM>.
00046      *
00047      * The PFB channelizer code takes the taps generated above and builds
00048      * a set of filters. The set contains <EM>M</EM> number of filters
00049      * and each filter contains ceil(taps.size()/decim) number of taps.
00050      * Each tap from the filter prototype is sequentially inserted into
00051      * the next filter. When all of the input taps are used, the remaining
00052      * filters in the filterbank are filled out with 0's to make sure each
00053      * filter has the same number of taps.
00054      *
00055      * Each filter operates using the gr_fir filter classs of GNU Radio,
00056      * which takes the input stream at <EM>i</EM> and performs the inner
00057      * product calculation to <EM>i+(n-1)</EM> where <EM>n</EM> is the
00058      * number of filter taps. To efficiently handle this in the GNU Radio
00059      * structure, each filter input must come from its own input
00060      * stream. So the channelizer must be provided with <EM>M</EM> streams
00061      * where the input stream has been deinterleaved. This is most easily
00062      * done using the gr_stream_to_streams block.
00063      *
00064      * The output is then produced as a vector, where index <EM>i</EM> in
00065      * the vector is the next sample from the <EM>i</EM>th channel. This
00066      * is most easily handled by sending the output to a
00067      * gr_vector_to_streams block to handle the conversion and passing
00068      * <EM>M</EM> streams out.
00069      *
00070      * The input and output formatting is done using a hier_block2 called
00071      * pfb_channelizer_ccf. This can take in a single stream and outputs
00072      * <EM>M</EM> streams based on the behavior described above.
00073      *
00074      * The filter's taps should be based on the input sampling rate.
00075      *
00076      * For example, using the GNU Radio's firdes utility to building
00077      * filters, we build a low-pass filter with a sampling rate of
00078      * <EM>fs</EM>, a 3-dB bandwidth of <EM>BW</EM> and a transition
00079      * bandwidth of <EM>TB</EM>. We can also specify the out-of-band
00080      * attenuation to use, <EM>ATT</EM>, and the filter window
00081      * function (a Blackman-harris window in this case). The first input
00082      *  is the gain of the filter, which we specify here as unity.
00083      *
00084      *      <B><EM>self._taps = filter.firdes.low_pass_2(1, fs, BW, TB,
00085      *           attenuation_dB=ATT, window=filter.firdes.WIN_BLACKMAN_hARRIS)</EM></B>
00086      *
00087      * The filter output can also be overs ampled. The over sampling rate
00088      * is the ratio of the the actual output sampling rate to the normal
00089      * output sampling rate. It must be rationally related to the number
00090      * of channels as N/i for i in [1,N], which gives an outputsample rate
00091      * of [fs/N, fs] where fs is the input sample rate and N is the number
00092      * of channels.
00093      *
00094      * For example, for 6 channels with fs = 6000 Hz, the normal rate is
00095      * 6000/6 = 1000 Hz. Allowable oversampling rates are 6/6, 6/5, 6/4,
00096      * 6/3, 6/2, and 6/1 where the output sample rate of a 6/1 oversample
00097      * ratio is 6000 Hz, or 6 times the normal 1000 Hz. A rate of 6/5 = 1.2,
00098      * so the output rate would be 1200 Hz.
00099      *
00100      * The theory behind this block can be found in Chapter 6 of
00101      * the following book.
00102      *
00103      *    <B><EM>f. harris, "Multirate Signal Processing for Communication
00104      *       Systems," Upper Saddle River, NJ: Prentice Hall, Inc. 2004.</EM></B>
00105      *
00106      */
00107     
00108     class FILTER_API pfb_channelizer_ccf : virtual public gr_block
00109     {
00110     public:
00111       // gr::filter::pfb_channelizer_ccf::sptr
00112       typedef boost::shared_ptr<pfb_channelizer_ccf> sptr;
00113 
00114       /*!
00115        * Build the polyphase filterbank decimator.
00116        * \param numchans (unsigned integer) Specifies the number of
00117        *                 channels <EM>M</EM>
00118        * \param taps (vector/list of floats) The prototype filter to
00119        *             populate the filterbank.
00120        * \param oversample_rate (float) The over sampling rate is the
00121        *                                ratio of the the actual output
00122        *                                sampling rate to the normal
00123        *                                output sampling rate.  It must
00124        *                                be rationally related to the
00125        *                                number of channels as N/i for
00126        *                                i in [1,N], which gives an
00127        *                                outputsample rate of [fs/N,
00128        *                                fs] where fs is the input
00129        *                                sample rate and N is the
00130        *                                number of channels.
00131        *
00132        *                                For example, for 6 channels
00133        *                                with fs = 6000 Hz, the normal
00134        *                                rateis 6000/6 = 1000
00135        *                                Hz. Allowable oversampling
00136        *                                rates are 6/6, 6/5, 6/4, 6/3,
00137        *                                6/2, and 6/1 where the output
00138        *                                sample rate of a 6/1
00139        *                                oversample ratio is 6000 Hz,
00140        *                                or 6 times the normal 1000 Hz.
00141        */
00142       static sptr make(unsigned int numchans,
00143                                   const std::vector<float> &taps,
00144                                   float oversample_rate);
00145 
00146       /*!
00147        * Resets the filterbank's filter taps with the new prototype filter
00148        * \param taps (vector/list of floats) The prototype filter to populate the filterbank.
00149        */
00150       virtual void set_taps(const std::vector<float> &taps) = 0;
00151 
00152       /*!
00153        * Print all of the filterbank taps to screen.
00154        */
00155       virtual void print_taps() = 0;
00156       
00157       /*!
00158        * Return a vector<vector<>> of the filterbank taps
00159        */
00160       virtual std::vector<std::vector<float> > taps() const = 0;
00161 
00162       /*!
00163        * Set the channel map. Channels are numbers as:
00164        *
00165        *     N/2+1 | ... | N-1 | 0 | 1 |  2 | ... | N/2
00166        *    <------------------- 0 -------------------->
00167        *                        freq
00168        *
00169        * So output stream 0 comes from channel 0, etc. Setting a new
00170        * channel map allows the user to specify which channel in frequency
00171        * he/she wants to got to which output stream.
00172        *
00173        * The map should have the same number of elements as the number
00174        * of output connections from the block. The minimum value of
00175        * the map is 0 (for the 0th channel) and the maximum number is
00176        * N-1 where N is the number of channels.
00177        *
00178        * We specify M as the number of output connections made where M
00179        * <= N, so only M out of N channels are driven to an output
00180        * stream. The number of items in the channel map should be at
00181        * least M long. If there are more channels specified, any value
00182        * in the map over M-1 will be ignored. If the size of the map
00183        * is less than M the behavior is unknown (we don't wish to
00184        * check every entry into the work function).
00185        *
00186        * This means that if the channelizer is splitting the signal up
00187        * into N channels but only M channels are specified in the map
00188        * (where M <= N), then M output streams must be connected and
00189        * the map and the channel numbers used must be less than
00190        * N-1. Output channel number can be reused, too. By default,
00191        * the map is [0...M-1] with M = N.
00192        */
00193       virtual void set_channel_map(const std::vector<int> &map) = 0;
00194       
00195       /*!
00196        * Gets the current channel map.
00197        */
00198       virtual std::vector<int> channel_map() const = 0;
00199     };
00200 
00201   } /* namespace filter */
00202 } /* namespace gr */
00203 
00204 #endif /* INCLUDED_FILTER_PFB_CHANNELIZER_CCF_H */