GNU Radio 3.5.1 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 alpha the loop gain used for phase adjustment
00054  * \param beta the loop gain for frequency adjustments
00055  * \param max_freq the maximum frequency deviation (radians/sample) the loop can handle
00056  * \param min_freq the minimum frequency deviation (radians/sample) the loop can handle
00057  * \param order the loop order, either 2 or 4
00058  */
00059 
00060 #include <digital_api.h>
00061 
00062 class digital_costas_loop_cc;
00063 typedef boost::shared_ptr<digital_costas_loop_cc> digital_costas_loop_cc_sptr;
00064 
00065 
00066 DIGITAL_API digital_costas_loop_cc_sptr 
00067 digital_make_costas_loop_cc (float loop_bw, int order
00068                              ) throw (std::invalid_argument);
00069 
00070 
00071 /*!
00072  * \brief Carrier tracking PLL for QPSK
00073  * \ingroup sync_blk
00074  * input: complex; output: complex
00075  * <br>The Costas loop can have two output streams:
00076  *    stream 1 is the baseband I and Q;
00077  *    stream 2 is the normalized frequency of the loop
00078  *
00079  * \p order must be 2 or 4.
00080  */
00081 class DIGITAL_API digital_costas_loop_cc : public gr_sync_block, public gri_control_loop
00082 {
00083   friend DIGITAL_API digital_costas_loop_cc_sptr
00084   digital_make_costas_loop_cc (float loop_bw, int order
00085                                ) throw (std::invalid_argument);
00086 
00087   int d_order;
00088 
00089   digital_costas_loop_cc (float loop_bw, int order
00090                           ) throw (std::invalid_argument);
00091   
00092   /*! \brief the phase detector circuit for 8th-order PSK loops
00093    *  \param sample complex sample
00094    *  \return the phase error
00095    */
00096   float phase_detector_8(gr_complex sample) const;    // for 8PSK
00097 
00098   /*! \brief the phase detector circuit for fourth-order loops
00099    *  \param sample complex sample
00100    *  \return the phase error
00101    */
00102   float phase_detector_4(gr_complex sample) const;    // for QPSK
00103 
00104   /*! \brief the phase detector circuit for second-order loops
00105    *  \param sample a complex sample
00106    *  \return the phase error
00107    */
00108   float phase_detector_2(gr_complex sample) const;    // for BPSK
00109 
00110 
00111   float (digital_costas_loop_cc::*d_phase_detector)(gr_complex sample) const;
00112 
00113 public:
00114 
00115   int work (int noutput_items,
00116             gr_vector_const_void_star &input_items,
00117             gr_vector_void_star &output_items);
00118 };
00119 
00120 #endif