GNU Radio 3.5.3.2 C++ API
digital_kurtotic_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_KURTOTIC_EQUALIZER_CC_H
00024 #define INCLUDED_DIGITAL_KURTOTIC_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_kurtotic_equalizer_cc;
00032 typedef boost::shared_ptr<digital_kurtotic_equalizer_cc> digital_kurtotic_equalizer_cc_sptr;
00033 
00034 DIGITAL_API digital_kurtotic_equalizer_cc_sptr 
00035 digital_make_kurtotic_equalizer_cc(int num_taps, float mu);
00036 
00037 /*!
00038  * \brief Implements a kurtosis-based adaptive equalizer on complex stream
00039  * \ingroup eq_blk
00040  * \ingroup digital
00041  *
00042  * Y. Guo, J. Zhao, Y. Sun, "Sign kurtosis maximization based blind
00043  * equalization algorithm," IEEE Conf. on Control, Automation,
00044  * Robotics and Vision, Vol. 3, Dec. 2004, pp. 2052 - 2057.
00045  */
00046 class DIGITAL_API digital_kurtotic_equalizer_cc : public gr_adaptive_fir_ccc
00047 {
00048 private:
00049   float d_mu;
00050   float d_p, d_m;
00051   gr_complex d_q, d_u;
00052   float d_alpha_p, d_alpha_q, d_alpha_m;
00053   
00054   friend DIGITAL_API digital_kurtotic_equalizer_cc_sptr digital_make_kurtotic_equalizer_cc(int num_taps,
00055                                                                                float mu);
00056   digital_kurtotic_equalizer_cc(int num_taps, float mu);
00057 
00058   gr_complex sign(gr_complex x)
00059   {
00060     float re = (float)(x.real() >= 0.0f);
00061     float im = (float)(x.imag() >= 0.0f);
00062     return gr_complex(re, im);
00063   }
00064 
00065 protected:
00066 
00067   virtual gr_complex error(const gr_complex &out) 
00068   {
00069 
00070     // p = E[|z|^2]
00071     // q = E[z^2]
00072     // m = E[|z|^4]
00073     // u = E[kurtosis(z)]
00074 
00075     float nrm = norm(out);
00076     gr_complex cnj = conj(out);
00077     float epsilon_f = 1e-12;
00078     gr_complex epsilon_c = gr_complex(1e-12, 1e-12);
00079 
00080     
00081     d_p = (1-d_alpha_p)*d_p + (d_alpha_p)*nrm + epsilon_f;
00082     d_q = (1-d_alpha_q)*d_q + (d_alpha_q)*out*out + epsilon_c;
00083     d_m = (1-d_alpha_m)*d_m + (d_alpha_m)*nrm*nrm + epsilon_f;
00084     d_u = d_m - 2.0f*(d_p*d_p) - d_q*d_q;
00085 
00086     gr_complex F = (1.0f / (d_p*d_p*d_p)) *
00087       (sign(d_u) * (nrm*cnj - 2.0f*d_p*cnj - conj(d_q)*out) -
00088        abs(d_u)*cnj);
00089 
00090     //std::cout << "out: " << out << "   p: " << d_p << "   q: " << d_q;
00091     //std::cout << "   m: " << d_m << "   u: " << d_u << std::endl;
00092     //std::cout << "error: " << F << std::endl;
00093     
00094     float re = gr_clip(F.real(), 1.0);
00095     float im = gr_clip(F.imag(), 1.0);
00096     return gr_complex(re, im);
00097   }
00098 
00099   virtual void update_tap(gr_complex &tap, const gr_complex &in) 
00100   {
00101     tap += d_mu*in*d_error;
00102   }
00103   
00104 public:
00105   void set_gain(float mu) 
00106   {
00107     if(mu < 0)
00108       throw std::out_of_range("digital_kurtotic_equalizer::set_gain: Gain value must be >= 0");
00109     d_mu = mu;
00110   }
00111 };
00112 
00113 #endif