GNU Radio 3.5.3.2 C++ API
digital_costas_loop_cc.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2011 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_DIGITAL_COSTAS_LOOP_CC_H
00025 #define INCLUDED_DIGITAL_COSTAS_LOOP_CC_H
00026 
00027 #include <gr_sync_block.h>
00028 #include <gri_control_loop.h>
00029 #include <stdexcept>
00030 #include <fstream>
00031 
00032 
00033 /*! 
00034  * \brief A Costas loop carrier recovery module.
00035  * \ingroup sync_blk
00036  * \ingroup digital
00037  *  
00038  *  The Costas loop locks to the center frequency of a signal and
00039  *  downconverts it to baseband. The second (order=2) order loop is
00040  *  used for BPSK where the real part of the output signal is the
00041  *  baseband BPSK signal and the imaginary part is the error
00042  *  signal. When order=4, it can be used for quadrature modulations
00043  *  where both I and Q (real and imaginary) are outputted.
00044  *
00045  *  More details can be found online:
00046  *
00047  *  J. Feigin, "Practical Costas loop design: Designing a simple and
00048  *  inexpensive BPSK Costas loop carrier recovery circuit," RF signal
00049  *  processing, pp. 20-36, 2002.
00050  *
00051  *  http://rfdesign.com/images/archive/0102Feigin20.pdf
00052  *  
00053  * \param loop_bw  internal 2nd order loop bandwidth (~ 2pi/100)
00054  * \param order the loop order, either 2, 4, or 8
00055  */
00056 
00057 #include <digital_api.h>
00058 
00059 class digital_costas_loop_cc;
00060 typedef boost::shared_ptr<digital_costas_loop_cc> digital_costas_loop_cc_sptr;
00061 
00062 
00063 DIGITAL_API digital_costas_loop_cc_sptr 
00064 digital_make_costas_loop_cc (float loop_bw, int order
00065                              ) throw (std::invalid_argument);
00066 
00067 
00068 /*!
00069  * \brief Carrier tracking PLL for QPSK
00070  * \ingroup sync_blk
00071  * input: complex; output: complex
00072  * <br>The Costas loop can have two output streams:
00073  *    stream 1 is the baseband I and Q;
00074  *    stream 2 is the normalized frequency of the loop
00075  *
00076  * \p order must be 2, 4, or 8.
00077  */
00078 class DIGITAL_API digital_costas_loop_cc : public gr_sync_block, public gri_control_loop
00079 {
00080   friend DIGITAL_API digital_costas_loop_cc_sptr
00081   digital_make_costas_loop_cc (float loop_bw, int order
00082                                ) throw (std::invalid_argument);
00083 
00084   int d_order;
00085 
00086   digital_costas_loop_cc (float loop_bw, int order
00087                           ) throw (std::invalid_argument);
00088   
00089   /*! \brief the phase detector circuit for 8th-order PSK loops
00090    *  \param sample complex sample
00091    *  \return the phase error
00092    */
00093   float phase_detector_8(gr_complex sample) const;    // for 8PSK
00094 
00095   /*! \brief the phase detector circuit for fourth-order loops
00096    *  \param sample complex sample
00097    *  \return the phase error
00098    */
00099   float phase_detector_4(gr_complex sample) const;    // for QPSK
00100 
00101   /*! \brief the phase detector circuit for second-order loops
00102    *  \param sample a complex sample
00103    *  \return the phase error
00104    */
00105   float phase_detector_2(gr_complex sample) const;    // for BPSK
00106 
00107 
00108   float (digital_costas_loop_cc::*d_phase_detector)(gr_complex sample) const;
00109 
00110 public:
00111 
00112   int work (int noutput_items,
00113             gr_vector_const_void_star &input_items,
00114             gr_vector_void_star &output_items);
00115 };
00116 
00117 #endif