GNU Radio 3.5.1 C++ API
digital_cma_equalizer_cc.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 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 #ifndef INCLUDED_DIGITAL_CMA_EQUALIZER_CC_H
00024 #define INCLUDED_DIGITAL_CMA_EQUALIZER_CC_H
00025 
00026 #include <digital_api.h>
00027 #include <gr_adaptive_fir_ccc.h>
00028 #include <gr_math.h>
00029 #include <iostream>
00030 
00031 class digital_cma_equalizer_cc;
00032 typedef boost::shared_ptr<digital_cma_equalizer_cc> digital_cma_equalizer_cc_sptr;
00033 
00034 DIGITAL_API digital_cma_equalizer_cc_sptr 
00035 digital_make_cma_equalizer_cc(int num_taps, float modulus, float mu, int sps);
00036 
00037 /*!
00038  * \brief Implements constant modulus adaptive filter on complex stream
00039  * \ingroup eq_blk
00040  * \ingroup digital
00041  *
00042  * The error value and tap update equations (for p=2) can be found in:
00043  *
00044  * D. Godard, "Self-Recovering Equalization and Carrier Tracking in
00045  * Two-Dimensional Data Communication Systems," IEEE Transactions on
00046  * Communications, Vol. 28, No. 11, pp. 1867 - 1875, 1980,
00047  */
00048 class DIGITAL_API digital_cma_equalizer_cc : public gr_adaptive_fir_ccc
00049 {
00050 private:
00051   float d_modulus;
00052   float d_mu;
00053   
00054   friend DIGITAL_API digital_cma_equalizer_cc_sptr digital_make_cma_equalizer_cc(int num_taps,
00055                                                                      float modulus,
00056                                                                      float mu,
00057                                                                      int sps);
00058   digital_cma_equalizer_cc(int num_taps, float modulus, float mu, int sps);
00059 
00060 protected:
00061 
00062   virtual gr_complex error(const gr_complex &out) 
00063   { 
00064     gr_complex error = out*(norm(out) - d_modulus);
00065     float re = gr_clip(error.real(), 1.0);
00066     float im = gr_clip(error.imag(), 1.0);
00067     return gr_complex(re, im);
00068   }
00069 
00070   virtual void update_tap(gr_complex &tap, const gr_complex &in) 
00071   {
00072     // Hn+1 = Hn - mu*conj(Xn)*zn*(|zn|^2 - 1)
00073     tap -= d_mu*conj(in)*d_error;
00074   }
00075   
00076 public:
00077   float get_gain() 
00078   {
00079     return d_mu;
00080   }
00081 
00082   void set_gain(float mu) 
00083   {
00084     if(mu < 0.0f || mu > 1.0f) {
00085       throw std::out_of_range("digital_cma_equalizer::set_gain: Gain value must be in [0,1]");
00086     }
00087     d_mu = mu;
00088   }
00089     
00090   float get_modulus() 
00091   {
00092     return d_modulus;
00093   }
00094 
00095   void set_modulus(float mod) 
00096   {
00097     if(mod < 0)
00098       throw std::out_of_range("digital_cma_equalizer::set_modulus: Modulus value must be >= 0");
00099     d_modulus = mod;
00100   }
00101 };
00102 
00103 #endif