diff options
21 files changed, 1745 insertions, 6 deletions
diff --git a/gnuradio-core/src/lib/general/gri_control_loop.cc b/gnuradio-core/src/lib/general/gri_control_loop.cc index 5a93737f9..bb3c4a326 100644 --- a/gnuradio-core/src/lib/general/gri_control_loop.cc +++ b/gnuradio-core/src/lib/general/gri_control_loop.cc @@ -144,6 +144,17 @@ gri_control_loop::set_phase(float phase) d_phase += M_TWOPI; } +void +gri_control_loop::set_max_freq(float freq) +{ + d_max_freq = freq; +} + +void +gri_control_loop::set_min_freq(float freq) +{ + d_min_freq = freq; +} /******************************************************************* GET FUNCTIONS @@ -185,3 +196,15 @@ gri_control_loop::get_phase() const { return d_phase; } + +float +gri_control_loop::get_max_freq() const +{ + return d_max_freq; +} + +float +gri_control_loop::get_min_freq() const +{ + return d_min_freq; +} diff --git a/gnuradio-core/src/lib/general/gri_control_loop.h b/gnuradio-core/src/lib/general/gri_control_loop.h index df260d2cf..304857ac7 100644 --- a/gnuradio-core/src/lib/general/gri_control_loop.h +++ b/gnuradio-core/src/lib/general/gri_control_loop.h @@ -141,9 +141,9 @@ class GR_CORE_API gri_control_loop void set_beta(float beta); /*! - * \brief Set the Costas loop's frequency. + * \brief Set the control loop's frequency. * - * Set's the Costas Loop's frequency. While this is normally updated by the + * Set's the control loop's frequency. While this is normally updated by the * inner loop of the algorithm, it could be useful to manually initialize, * set, or reset this under certain circumstances. * @@ -153,9 +153,9 @@ class GR_CORE_API gri_control_loop void set_frequency(float freq); /*! - * \brief Set the Costas loop's phase. + * \brief Set the control loop's phase. * - * Set's the Costas Loop's phase. While this is normally updated by the + * Set's the control loop's phase. While this is normally updated by the * inner loop of the algorithm, it could be useful to manually initialize, * set, or reset this under certain circumstances. * @@ -164,6 +164,23 @@ class GR_CORE_API gri_control_loop */ void set_phase(float phase); + /*! + * \brief Set the control loop's maximum frequency. + * + * Set the maximum frequency the control loop can track. + * + * \param freq (float) new max frequency + */ + void set_max_freq(float freq); + + /*! + * \brief Set the control loop's minimum frequency. + * + * Set the minimum frequency the control loop can track. + * + * \param freq (float) new min frequency + */ + void set_min_freq(float freq); /******************************************************************* GET FUNCTIONS @@ -190,14 +207,24 @@ class GR_CORE_API gri_control_loop float get_beta() const; /*! - * \brief Get the Costas loop's frequency estimate + * \brief Get the control loop's frequency estimate */ float get_frequency() const; /*! - * \brief Get the Costas loop's phase estimate + * \brief Get the control loop's phase estimate */ float get_phase() const; + + /*! + * \brief Get the control loop's maximum frequency. + */ + float get_max_freq() const; + + /*! + * \brief Get the control loop's minimum frequency. + */ + float get_min_freq() const; }; #endif /* GRI_CONTROL_LOOP */ diff --git a/gr-analog/grc/analog_block_tree.xml b/gr-analog/grc/analog_block_tree.xml index 54142e623..7283d9f5a 100644 --- a/gr-analog/grc/analog_block_tree.xml +++ b/gr-analog/grc/analog_block_tree.xml @@ -46,4 +46,10 @@ <name>Sources</name> <block>analog_noise_source_x</block> </cat> + <cat> + <name>Synchronizers</name> + <block>analog_pll_carriertracking_cc</block> + <block>analog_pll_freqdet_cf</block> + <block>analog_pll_refout_cc</block> + </cat> </cat> diff --git a/gr-analog/grc/analog_pll_carriertracking_cc.xml b/gr-analog/grc/analog_pll_carriertracking_cc.xml new file mode 100644 index 000000000..95ec4b415 --- /dev/null +++ b/gr-analog/grc/analog_pll_carriertracking_cc.xml @@ -0,0 +1,38 @@ +<?xml version="1.0"?> +<!-- +################################################### +##PLL Carrier Tracking +################################################### + --> +<block> + <name>PLL Carrier Tracking</name> + <key>analog_pll_carriertracking_cc</key> + <import>from gnuradio import analog</import> + <make>analog.pll_carriertracking_cc($w, $max_freq, $min_freq)</make> + <callback>set_loop_bandwidth($w)</callback> + <callback>set_max_freq($max_freq)</callback> + <callback>set_min_freq($min_freq)</callback> + <param> + <name>Loop Bandwidth</name> + <key>w</key> + <type>real</type> + </param> + <param> + <name>Max Freq</name> + <key>max_freq</key> + <type>real</type> + </param> + <param> + <name>Min Freq</name> + <key>min_freq</key> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> +</block> diff --git a/gr-analog/grc/analog_pll_freqdet_cf.xml b/gr-analog/grc/analog_pll_freqdet_cf.xml new file mode 100644 index 000000000..0d44c160b --- /dev/null +++ b/gr-analog/grc/analog_pll_freqdet_cf.xml @@ -0,0 +1,38 @@ +<?xml version="1.0"?> +<!-- +################################################### +##PLL Frequency Det +################################################### + --> +<block> + <name>PLL Freq Det</name> + <key>analog_pll_freqdet_cf</key> + <import>from gnuradio import analog</import> + <make>analog.pll_freqdet_cf($w, $max_freq, $min_freq)</make> + <callback>set_loop_bandwidth($w)</callback> + <callback>set_max_freq($max_freq)</callback> + <callback>set_min_freq($min_freq)</callback> + <param> + <name>Loop Bandwidth</name> + <key>w</key> + <type>real</type> + </param> + <param> + <name>Max Freq</name> + <key>max_freq</key> + <type>real</type> + </param> + <param> + <name>Min Freq</name> + <key>min_freq</key> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <source> + <name>out</name> + <type>float</type> + </source> +</block> diff --git a/gr-analog/grc/analog_pll_refout_cc.xml b/gr-analog/grc/analog_pll_refout_cc.xml new file mode 100644 index 000000000..eb2d752b2 --- /dev/null +++ b/gr-analog/grc/analog_pll_refout_cc.xml @@ -0,0 +1,38 @@ +<?xml version="1.0"?> +<!-- +################################################### +##PLL Reference Out +################################################### + --> +<block> + <name>PLL Ref Out</name> + <key>analog_pll_refout_cc</key> + <import>from gnuradio import analog</import> + <make>analog.pll_refout_cc($w, $max_freq, $min_freq)</make> + <callback>set_loop_bandwidth($w)</callback> + <callback>set_max_freq($max_freq)</callback> + <callback>set_min_freq($min_freq)</callback> + <param> + <name>Loop Bandwidth</name> + <key>w</key> + <type>real</type> + </param> + <param> + <name>Max Freq</name> + <key>max_freq</key> + <type>real</type> + </param> + <param> + <name>Min Freq</name> + <key>min_freq</key> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>complex</type> + </sink> + <source> + <name>out</name> + <type>complex</type> + </source> +</block> diff --git a/gr-analog/include/analog/CMakeLists.txt b/gr-analog/include/analog/CMakeLists.txt index fded7501a..ac1d65932 100644 --- a/gr-analog/include/analog/CMakeLists.txt +++ b/gr-analog/include/analog/CMakeLists.txt @@ -91,6 +91,9 @@ install(FILES fmdet_cf.h frequency_modulator_fc.h phase_modulator_fc.h + pll_carriertracking_cc.h + pll_freqdet_cf.h + pll_refout_cc.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/analog COMPONENT "analog_devel" ) diff --git a/gr-analog/include/analog/pll_carriertracking_cc.h b/gr-analog/include/analog/pll_carriertracking_cc.h new file mode 100644 index 000000000..3596429d4 --- /dev/null +++ b/gr-analog/include/analog/pll_carriertracking_cc.h @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2011,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ANALOG_PLL_CARRIERTRACKING_CC_H +#define INCLUDED_ANALOG_PLL_CARRIERTRACKING_CC_H + +#include <analog/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace analog { + + /*! + * \brief Implements a PLL which locks to the input frequency and outputs the + * input signal mixed with that carrier. + * \ingroup sync_blk + * + * Input stream 0: complex + * Output stream 0: complex + * + * This PLL locks onto a [possibly noisy] reference carrier on the + * input and outputs that signal, downconverted to DC + * + * All settings max_freq and min_freq are in terms of radians per + * sample, NOT HERTZ. The loop bandwidth determins the lock range + * and should be set around pi/200 -- 2pi/100. \sa + * pll_freqdet_cf, pll_carriertracking_cc + */ + class ANALOG_API pll_carriertracking_cc : virtual public gr_sync_block + { + public: + // gr::analog::pll_carriertracking_cc::sptr + typedef boost::shared_ptr<pll_carriertracking_cc> sptr; + + /* \brief Make a carrier tracking PLL block. + * + * \param loop_bw: control loop's bandwidth parameter. + * \param max_freq: maximum (normalized) frequency PLL will lock to. + * \param min_freq: minimum (normalized) frequency PLL will lock to. + */ + static sptr make(float loop_bw, float max_freq, float min_freq); + + virtual bool lock_detector(void) = 0; + virtual bool squelch_enable(bool) = 0; + virtual float set_lock_threshold(float) = 0; + + virtual void set_loop_bandwidth(float bw) = 0; + virtual void set_damping_factor(float df) = 0; + virtual void set_alpha(float alpha) = 0; + virtual void set_beta(float beta) = 0; + virtual void set_frequency(float freq) = 0; + virtual void set_phase(float phase) = 0; + virtual void set_min_freq(float freq) = 0; + virtual void set_max_freq(float freq) = 0; + + virtual float get_loop_bandwidth() const = 0; + virtual float get_damping_factor() const = 0; + virtual float get_alpha() const = 0; + virtual float get_beta() const = 0; + virtual float get_frequency() const = 0; + virtual float get_phase() const = 0; + virtual float get_min_freq() const = 0; + virtual float get_max_freq() const = 0; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_PLL_CARRIERTRACKING_CC_H */ diff --git a/gr-analog/include/analog/pll_freqdet_cf.h b/gr-analog/include/analog/pll_freqdet_cf.h new file mode 100644 index 000000000..613e85263 --- /dev/null +++ b/gr-analog/include/analog/pll_freqdet_cf.h @@ -0,0 +1,83 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ANALOG_PLL_FREQDET_CF_H +#define INCLUDED_ANALOG_PLL_FREQDET_CF_H + +#include <analog/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace analog { + + /*! + * \brief Implements a PLL which locks to the input frequency and outputs + * an estimate of that frequency. Useful for FM Demod. + * \ingroup sync_blk + * + * Input stream 0: complex + * Output stream 0: float + * + * This PLL locks onto a [possibly noisy] reference carrier on + * the input and outputs an estimate of that frequency in radians per sample. + * All settings max_freq and min_freq are in terms of radians per sample, + * NOT HERTZ. The loop bandwidth determins the lock range and should be set + * around pi/200 -- 2pi/100. + * \sa pll_refout_cc, pll_carriertracking_cc + */ + class ANALOG_API pll_freqdet_cf : virtual public gr_sync_block + { + public: + // gr::analog::pll_freqdet_cf::sptr + typedef boost::shared_ptr<pll_freqdet_cf> sptr; + + /* \brief Make PLL block that outputs the tracked signal's frequency. + * + * \param loop_bw: control loop's bandwidth parameter. + * \param max_freq: maximum (normalized) frequency PLL will lock to. + * \param min_freq: minimum (normalized) frequency PLL will lock to. + */ + static sptr make(float loop_bw, float max_freq, float min_freq); + + virtual void set_loop_bandwidth(float bw) = 0; + virtual void set_damping_factor(float df) = 0; + virtual void set_alpha(float alpha) = 0; + virtual void set_beta(float beta) = 0; + virtual void set_frequency(float freq) = 0; + virtual void set_phase(float phase) = 0; + virtual void set_min_freq(float freq) = 0; + virtual void set_max_freq(float freq) = 0; + + virtual float get_loop_bandwidth() const = 0; + virtual float get_damping_factor() const = 0; + virtual float get_alpha() const = 0; + virtual float get_beta() const = 0; + virtual float get_frequency() const = 0; + virtual float get_phase() const = 0; + virtual float get_min_freq() const = 0; + virtual float get_max_freq() const = 0; + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_PLL_FREQDET_CF_H */ diff --git a/gr-analog/include/analog/pll_refout_cc.h b/gr-analog/include/analog/pll_refout_cc.h new file mode 100644 index 000000000..a18d177e6 --- /dev/null +++ b/gr-analog/include/analog/pll_refout_cc.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2011,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ANALOG_PLL_REFOUT_CC_H +#define INCLUDED_ANALOG_PLL_REFOUT_CC_H + +#include <analog/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace analog { + + /*! + * \brief Implements a PLL which locks to the input frequency and outputs a carrier + * \ingroup sync_blk + * + * Input stream 0: complex + * Output stream 0: complex + * + * This PLL locks onto a [possibly noisy] reference carrier on the + * input and outputs a clean version which is phase and frequency + * aligned to it. + * + * All settings max_freq and min_freq are in terms of radians per + * sample, NOT HERTZ. The loop bandwidth determins the lock range + * and should be set around pi/200 -- 2pi/100. \sa + * pll_freqdet_cf, pll_carriertracking_cc + */ + class ANALOG_API pll_refout_cc : virtual public gr_sync_block + { + public: + // gr::analog::pll_refout_cc::sptr + typedef boost::shared_ptr<pll_refout_cc> sptr; + + /* \brief Make PLL block that outputs the tracked carrier signal. + * + * \param loop_bw: control loop's bandwidth parameter. + * \param max_freq: maximum (normalized) frequency PLL will lock to. + * \param min_freq: minimum (normalized) frequency PLL will lock to. + */ + static sptr make(float loop_bw, float max_freq, float min_freq); + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_PLL_REFOUT_CC_H */ diff --git a/gr-analog/lib/CMakeLists.txt b/gr-analog/lib/CMakeLists.txt index a151fbf76..20a86621e 100644 --- a/gr-analog/lib/CMakeLists.txt +++ b/gr-analog/lib/CMakeLists.txt @@ -117,6 +117,9 @@ list(APPEND analog_sources fmdet_cf_impl.cc frequency_modulator_fc_impl.cc phase_modulator_fc_impl.cc + pll_carriertracking_cc_impl.cc + pll_freqdet_cf_impl.cc + pll_refout_cc_impl.cc ) list(APPEND analog_libs diff --git a/gr-analog/lib/pll_carriertracking_cc_impl.cc b/gr-analog/lib/pll_carriertracking_cc_impl.cc new file mode 100644 index 000000000..c53e0f433 --- /dev/null +++ b/gr-analog/lib/pll_carriertracking_cc_impl.cc @@ -0,0 +1,228 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2010-2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "pll_carriertracking_cc_impl.h" +#include <gr_io_signature.h> +#include <gr_sincos.h> +#include <math.h> +#include <gr_math.h> + +namespace gr { + namespace analog { + +#ifndef M_TWOPI +#define M_TWOPI (2.0f*M_PI) +#endif + + pll_carriertracking_cc::sptr + pll_carriertracking_cc::make(float loop_bw, float max_freq, float min_freq) + { + return gnuradio::get_initial_sptr + (new pll_carriertracking_cc_impl(loop_bw, max_freq, min_freq)); + } + + pll_carriertracking_cc_impl::pll_carriertracking_cc_impl(float loop_bw, + float max_freq, + float min_freq) + : gr_sync_block("pll_carriertracking_cc", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(1, 1, sizeof(gr_complex))), + gri_control_loop(loop_bw, max_freq, min_freq), + d_locksig(0), d_lock_threshold(0), d_squelch_enable(false) + { + } + + pll_carriertracking_cc_impl::~pll_carriertracking_cc_impl() + { + } + + float + pll_carriertracking_cc_impl::mod_2pi(float in) + { + if(in>M_PI) + return in-M_TWOPI; + else if(in<-M_PI) + return in+M_TWOPI; + else + return in; + } + + float + pll_carriertracking_cc_impl::phase_detector(gr_complex sample, float ref_phase) + { + float sample_phase; + // sample_phase = atan2(sample.imag(),sample.real()); + sample_phase = gr_fast_atan2f(sample.imag(),sample.real()); + return mod_2pi(sample_phase-ref_phase); + } + + bool + pll_carriertracking_cc_impl::lock_detector(void) + { + return (fabsf(d_locksig) > d_lock_threshold); + } + + bool + pll_carriertracking_cc_impl::squelch_enable(bool set_squelch) + { + return d_squelch_enable = set_squelch; + } + + float + pll_carriertracking_cc_impl::set_lock_threshold(float threshold) + { + return d_lock_threshold = threshold; + } + + int + pll_carriertracking_cc_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *iptr = (gr_complex*)input_items[0]; + gr_complex *optr = (gr_complex*)output_items[0]; + + float error; + float t_imag, t_real; + + for(int i = 0; i < noutput_items; i++) { + gr_sincosf(d_phase, &t_imag, &t_real); + optr[i] = iptr[i] * gr_complex(t_real, -t_imag); + + error = phase_detector(iptr[i], d_phase); + + advance_loop(error); + phase_wrap(); + frequency_limit(); + + d_locksig = d_locksig * (1.0 - d_alpha) + \ + d_alpha*(iptr[i].real() * t_real + iptr[i].imag() * t_imag); + + if((d_squelch_enable) && !lock_detector()) + optr[i] = 0; + } + return noutput_items; + } + + void + pll_carriertracking_cc_impl::set_loop_bandwidth(float bw) + { + gri_control_loop::set_loop_bandwidth(bw); + } + + void + pll_carriertracking_cc_impl::set_damping_factor(float df) + { + gri_control_loop::set_damping_factor(df); + } + + void + pll_carriertracking_cc_impl::set_alpha(float alpha) + { + gri_control_loop::set_alpha(alpha); + } + + void + pll_carriertracking_cc_impl::set_beta(float beta) + { + gri_control_loop::set_beta(beta); + } + + void + pll_carriertracking_cc_impl::set_frequency(float freq) + { + gri_control_loop::set_frequency(freq); + } + + void + pll_carriertracking_cc_impl::set_phase(float phase) + { + gri_control_loop::set_phase(phase); + } + + void + pll_carriertracking_cc_impl::set_min_freq(float freq) + { + gri_control_loop::set_min_freq(freq); + } + + void + pll_carriertracking_cc_impl::set_max_freq(float freq) + { + gri_control_loop::set_max_freq(freq); + } + + + float + pll_carriertracking_cc_impl::get_loop_bandwidth() const + { + return gri_control_loop::get_loop_bandwidth(); + } + + float + pll_carriertracking_cc_impl::get_damping_factor() const + { + return gri_control_loop::get_damping_factor(); + } + + float + pll_carriertracking_cc_impl::get_alpha() const + { + return gri_control_loop::get_alpha(); + } + + float + pll_carriertracking_cc_impl::get_beta() const + { + return gri_control_loop::get_beta(); + } + + float + pll_carriertracking_cc_impl::get_frequency() const + { + return gri_control_loop::get_frequency(); + } + + float + pll_carriertracking_cc_impl::get_phase() const + { + return gri_control_loop::get_phase(); + } + + float + pll_carriertracking_cc_impl::get_min_freq() const + { + return gri_control_loop::get_min_freq(); + } + + float + pll_carriertracking_cc_impl::get_max_freq() const + { + return gri_control_loop::get_max_freq(); + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/pll_carriertracking_cc_impl.h b/gr-analog/lib/pll_carriertracking_cc_impl.h new file mode 100644 index 000000000..d67223db8 --- /dev/null +++ b/gr-analog/lib/pll_carriertracking_cc_impl.h @@ -0,0 +1,76 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2011,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ANALOG_PLL_CARRIERTRACKING_CC_IMPL_H +#define INCLUDED_ANALOG_PLL_CARRIERTRACKING_CC_IMPL_H + +#include <analog/pll_carriertracking_cc.h> +#include <gri_control_loop.h> + +namespace gr { + namespace analog { + + class pll_carriertracking_cc_impl + : public pll_carriertracking_cc, public gri_control_loop + { + private: + float d_locksig,d_lock_threshold; + bool d_squelch_enable; + + float mod_2pi(float in); + float phase_detector(gr_complex sample,float ref_phase); + + public: + pll_carriertracking_cc_impl(float loop_bw, float max_freq, float min_freq); + ~pll_carriertracking_cc_impl(); + + bool lock_detector(void); + bool squelch_enable(bool); + float set_lock_threshold(float); + + void set_loop_bandwidth(float bw); + void set_damping_factor(float df); + void set_alpha(float alpha); + void set_beta(float beta); + void set_frequency(float freq); + void set_phase(float phase); + void set_min_freq(float freq); + void set_max_freq(float freq); + + float get_loop_bandwidth() const; + float get_damping_factor() const; + float get_alpha() const; + float get_beta() const; + float get_frequency() const; + float get_phase() const; + float get_min_freq() const; + float get_max_freq() const; + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_PLL_CARRIERTRACKING_CC_IMPL_H */ diff --git a/gr-analog/lib/pll_freqdet_cf_impl.cc b/gr-analog/lib/pll_freqdet_cf_impl.cc new file mode 100644 index 000000000..27e8d02aa --- /dev/null +++ b/gr-analog/lib/pll_freqdet_cf_impl.cc @@ -0,0 +1,198 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010,2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "pll_freqdet_cf_impl.h" +#include <gr_io_signature.h> +#include <math.h> +#include <gr_math.h> + +namespace gr { + namespace analog { + +#ifndef M_TWOPI +#define M_TWOPI (2.0f*M_PI) +#endif + + pll_freqdet_cf::sptr + pll_freqdet_cf::make(float loop_bw, float max_freq, float min_freq) + { + return gnuradio::get_initial_sptr + (new pll_freqdet_cf_impl(loop_bw, max_freq, min_freq)); + } + + pll_freqdet_cf_impl::pll_freqdet_cf_impl(float loop_bw, float max_freq, float min_freq) + : gr_sync_block("pll_freqdet_cf", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(1, 1, sizeof(float))), + gri_control_loop(loop_bw, max_freq, min_freq) + { + } + + pll_freqdet_cf_impl::~pll_freqdet_cf_impl() + { + } + + float + pll_freqdet_cf_impl::mod_2pi(float in) + { + if(in > M_PI) + return in - M_TWOPI; + else if(in < -M_PI) + return in + M_TWOPI; + else + return in; + } + + float + pll_freqdet_cf_impl::phase_detector(gr_complex sample, float ref_phase) + { + float sample_phase; + sample_phase = gr_fast_atan2f(sample.imag(), sample.real()); + return mod_2pi(sample_phase - ref_phase); + } + + int + pll_freqdet_cf_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *iptr = (gr_complex*)input_items[0]; + float *optr = (float*)output_items[0]; + + float error; + int size = noutput_items; + + while(size-- > 0) { + *optr++ = d_freq; + + error = phase_detector(*iptr++, d_phase); + + advance_loop(error); + phase_wrap(); + frequency_limit(); + } + return noutput_items; + } + + void + pll_freqdet_cf_impl::set_loop_bandwidth(float bw) + { + gri_control_loop::set_loop_bandwidth(bw); + } + + void + pll_freqdet_cf_impl::set_damping_factor(float df) + { + gri_control_loop::set_damping_factor(df); + } + + void + pll_freqdet_cf_impl::set_alpha(float alpha) + { + gri_control_loop::set_alpha(alpha); + } + + void + pll_freqdet_cf_impl::set_beta(float beta) + { + gri_control_loop::set_beta(beta); + } + + void + pll_freqdet_cf_impl::set_frequency(float freq) + { + gri_control_loop::set_frequency(freq); + } + + void + pll_freqdet_cf_impl::set_phase(float phase) + { + gri_control_loop::set_phase(phase); + } + + void + pll_freqdet_cf_impl::set_min_freq(float freq) + { + gri_control_loop::set_min_freq(freq); + } + + void + pll_freqdet_cf_impl::set_max_freq(float freq) + { + gri_control_loop::set_max_freq(freq); + } + + + float + pll_freqdet_cf_impl::get_loop_bandwidth() const + { + return gri_control_loop::get_loop_bandwidth(); + } + + float + pll_freqdet_cf_impl::get_damping_factor() const + { + return gri_control_loop::get_damping_factor(); + } + + float + pll_freqdet_cf_impl::get_alpha() const + { + return gri_control_loop::get_alpha(); + } + + float + pll_freqdet_cf_impl::get_beta() const + { + return gri_control_loop::get_beta(); + } + + float + pll_freqdet_cf_impl::get_frequency() const + { + return gri_control_loop::get_frequency(); + } + + float + pll_freqdet_cf_impl::get_phase() const + { + return gri_control_loop::get_phase(); + } + + float + pll_freqdet_cf_impl::get_min_freq() const + { + return gri_control_loop::get_min_freq(); + } + + float + pll_freqdet_cf_impl::get_max_freq() const + { + return gri_control_loop::get_max_freq(); + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/pll_freqdet_cf_impl.h b/gr-analog/lib/pll_freqdet_cf_impl.h new file mode 100644 index 000000000..7acf53ebb --- /dev/null +++ b/gr-analog/lib/pll_freqdet_cf_impl.h @@ -0,0 +1,70 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2011,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ANALOG_PLL_FREQDET_CF_IMPL_H +#define INCLUDED_ANALOG_PLL_FREQDET_CF_IMPL_H + +#include <analog/pll_freqdet_cf.h> +#include <gri_control_loop.h> + +namespace gr { + namespace analog { + + class pll_freqdet_cf_impl : + public pll_freqdet_cf, public gri_control_loop + { + private: + float phase_detector(gr_complex sample,float ref_phase); + + public: + pll_freqdet_cf_impl(float loop_bw, float max_freq, float min_freq); + ~pll_freqdet_cf_impl(); + + float mod_2pi(float in); + + void set_loop_bandwidth(float bw); + void set_damping_factor(float df); + void set_alpha(float alpha); + void set_beta(float beta); + void set_frequency(float freq); + void set_phase(float phase); + void set_min_freq(float freq); + void set_max_freq(float freq); + + float get_loop_bandwidth() const; + float get_damping_factor() const; + float get_alpha() const; + float get_beta() const; + float get_frequency() const; + float get_phase() const; + float get_min_freq() const; + float get_max_freq() const; + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_PLL_FREQDET_CF_IMPL_H */ diff --git a/gr-analog/lib/pll_refout_cc_impl.cc b/gr-analog/lib/pll_refout_cc_impl.cc new file mode 100644 index 000000000..b94e3660a --- /dev/null +++ b/gr-analog/lib/pll_refout_cc_impl.cc @@ -0,0 +1,201 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010-2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "pll_refout_cc_impl.h" +#include <gr_io_signature.h> +#include <gr_sincos.h> +#include <math.h> +#include <gr_math.h> + +namespace gr { + namespace analog { + +#ifndef M_TWOPI +#define M_TWOPI (2.0f*M_PI) +#endif + + pll_refout_cc::sptr + pll_refout_cc::make(float loop_bw, float max_freq, float min_freq) + { + return gnuradio::get_initial_sptr + (new pll_refout_cc_impl(loop_bw, max_freq, min_freq)); + } + + pll_refout_cc_impl::pll_refout_cc_impl(float loop_bw, float max_freq, float min_freq) + : gr_sync_block("pll_refout_cc", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(1, 1, sizeof(gr_complex))), + gri_control_loop(loop_bw, max_freq, min_freq) + { + } + + pll_refout_cc_impl::~pll_refout_cc_impl() + { + } + + float + pll_refout_cc_impl::mod_2pi(float in) + { + if(in > M_PI) + return in - M_TWOPI; + else if(in < -M_PI) + return in+ M_TWOPI; + else + return in; + } + + float + pll_refout_cc_impl::phase_detector(gr_complex sample,float ref_phase) + { + float sample_phase; + sample_phase = gr_fast_atan2f(sample.imag(),sample.real()); + return mod_2pi(sample_phase-ref_phase); + } + + int + pll_refout_cc_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *iptr = (gr_complex*)input_items[0]; + gr_complex *optr = (gr_complex*)output_items[0]; + + float error; + float t_imag, t_real; + int size = noutput_items; + + while(size-- > 0) { + gr_sincosf(d_phase,&t_imag,&t_real); + *optr++ = gr_complex(t_real,t_imag); + + error = phase_detector(*iptr++,d_phase); + + advance_loop(error); + phase_wrap(); + frequency_limit(); + } + return noutput_items; + } + + void + pll_refout_cc_impl::set_loop_bandwidth(float bw) + { + gri_control_loop::set_loop_bandwidth(bw); + } + + void + pll_refout_cc_impl::set_damping_factor(float df) + { + gri_control_loop::set_damping_factor(df); + } + + void + pll_refout_cc_impl::set_alpha(float alpha) + { + gri_control_loop::set_alpha(alpha); + } + + void + pll_refout_cc_impl::set_beta(float beta) + { + gri_control_loop::set_beta(beta); + } + + void + pll_refout_cc_impl::set_frequency(float freq) + { + gri_control_loop::set_frequency(freq); + } + + void + pll_refout_cc_impl::set_phase(float phase) + { + gri_control_loop::set_phase(phase); + } + + void + pll_refout_cc_impl::set_min_freq(float freq) + { + gri_control_loop::set_min_freq(freq); + } + + void + pll_refout_cc_impl::set_max_freq(float freq) + { + gri_control_loop::set_max_freq(freq); + } + + + float + pll_refout_cc_impl::get_loop_bandwidth() const + { + return gri_control_loop::get_loop_bandwidth(); + } + + float + pll_refout_cc_impl::get_damping_factor() const + { + return gri_control_loop::get_damping_factor(); + } + + float + pll_refout_cc_impl::get_alpha() const + { + return gri_control_loop::get_alpha(); + } + + float + pll_refout_cc_impl::get_beta() const + { + return gri_control_loop::get_beta(); + } + + float + pll_refout_cc_impl::get_frequency() const + { + return gri_control_loop::get_frequency(); + } + + float + pll_refout_cc_impl::get_phase() const + { + return gri_control_loop::get_phase(); + } + + float + pll_refout_cc_impl::get_min_freq() const + { + return gri_control_loop::get_min_freq(); + } + + float + pll_refout_cc_impl::get_max_freq() const + { + return gri_control_loop::get_max_freq(); + } + + } /* namespace analog */ +} /* namespace gr */ diff --git a/gr-analog/lib/pll_refout_cc_impl.h b/gr-analog/lib/pll_refout_cc_impl.h new file mode 100644 index 000000000..9e8ae286b --- /dev/null +++ b/gr-analog/lib/pll_refout_cc_impl.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2011,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_ANALOG_PLL_REFOUT_CC_IMPL_H +#define INCLUDED_ANALOG_PLL_REFOUT_CC_IMPL_H + +#include <analog/pll_refout_cc.h> +#include <gri_control_loop.h> + +namespace gr { + namespace analog { + + class pll_refout_cc_impl + : public pll_refout_cc, public gri_control_loop + { + private: + float mod_2pi (float in); + float phase_detector(gr_complex sample, float ref_phase); + + public: + pll_refout_cc_impl(float loop_bw, float max_freq, float min_freq); + ~pll_refout_cc_impl(); + + void set_loop_bandwidth(float bw); + void set_damping_factor(float df); + void set_alpha(float alpha); + void set_beta(float beta); + void set_frequency(float freq); + void set_phase(float phase); + void set_min_freq(float freq); + void set_max_freq(float freq); + + float get_loop_bandwidth() const; + float get_damping_factor() const; + float get_alpha() const; + float get_beta() const; + float get_frequency() const; + float get_phase() const; + float get_min_freq() const; + float get_max_freq() const; + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace analog */ +} /* namespace gr */ + +#endif /* INCLUDED_ANALOG_PLL_REFOUT_CC_IMPL_H */ diff --git a/gr-analog/python/qa_pll_carriertracking.py b/gr-analog/python/qa_pll_carriertracking.py new file mode 100755 index 000000000..a292059d1 --- /dev/null +++ b/gr-analog/python/qa_pll_carriertracking.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010-2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import analog_swig as analog +import math + +class test_pll_carriertracking(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block() + + def tearDown (self): + self.tb = None + + def test_pll_carriertracking(self): + expected_result = ((1.00000238419+7.21919457547e-09j), + (0.998025715351+0.062790453434j), + (0.992777824402+0.119947694242j), + (0.985192835331+0.171441286802j), + (0.976061582565+0.217501848936j), + (0.966034710407+0.258409559727j), + (0.95565611124+0.294477283955j), + (0.945357382298+0.326030552387j), + (0.935475051403+0.353395611048j), + (0.926258146763+0.376889169216j), + (0.917895197868+0.39681750536j), + (0.910515546799+0.413470208645j), + (0.904196679592+0.427117019892j), + (0.898972511292+0.438006043434j), + (0.894769787788+0.446523308754j), + (0.891652584076+0.452715367079j), + (0.8895829916+0.456773489714j), + (0.888502895832+0.458873122931j), + (0.888343691826+0.459175437689j), + (0.889035582542+0.457833081484j), + (0.890497922897+0.454985737801j), + (0.892645597458+0.450762689114j), + (0.895388305187+0.445282936096j), + (0.898648142815+0.438664674759j), + (0.902342617512+0.431016951799j), + (0.906392872334+0.422441422939j), + (0.910642921925+0.413191765547j), + (0.915039420128+0.403358519077j), + (0.919594764709+0.392864197493j), + (0.92425006628+0.381792247295j), + (0.928944349289+0.370217680931j), + (0.933634519577+0.358220815659j), + (0.938279032707+0.345874190331j), + (0.942840516567+0.333247303963j), + (0.947280526161+0.32040438056j), + (0.951574921608+0.307409763336j), + (0.955703914165+0.294323593378j), + (0.959648966789+0.281201630831j), + (0.963392794132+0.268095195293j), + (0.966880619526+0.255221515894j), + (0.970162451267+0.242447137833j), + (0.973235487938+0.229809194803j), + (0.97609680891+0.217341512442j), + (0.978744983673+0.20507311821j), + (0.981189727783+0.193033605814j), + (0.983436584473+0.181248426437j), + (0.985490739346+0.169738590717j), + (0.987353682518+0.158523857594j), + (0.989041447639+0.147622272372j), + (0.990563035011+0.137049794197j), + (0.991928339005+0.126818582416j), + (0.993117690086+0.117111675441j), + (0.994156062603+0.107930034399j), + (0.995076179504+0.0990980416536j), + (0.995887458324+0.0906178802252j), + (0.996591091156+0.0824909061193j), + (0.997202515602+0.0747182965279j), + (0.997730851173+0.0672992765903j), + (0.998185396194+0.0602316558361j), + (0.99856698513+0.0535135567188j), + (0.998885989189+0.0471420884132j), + (0.99915266037+0.0411129891872j), + (0.999372899532+0.0354214012623j), + (0.999548316002+0.0300626158714j), + (0.999680638313+0.0252036750317j), + (0.999784469604+0.020652115345j), + (0.999865531921+0.0163950324059j), + (0.999923825264+0.0124222636223j), + (0.999960243702+0.00872156023979j), + (0.999983668327+0.00528120994568j), + (0.999997138977+0.00209015607834j), + (1.00000119209-0.00086285173893j), + (0.999992132187-0.00358882546425j), + (0.999979138374-0.00609711557627j), + (0.999963641167-0.00839691981673j), + (0.999947249889-0.0104993218556j), + (0.999924004078-0.0122378543019j), + (0.999904811382-0.0136305987835j), + (0.999888062477-0.0148707330227j), + (0.9998742342-0.0159679055214j), + (0.999856114388-0.0169314742088j), + (0.999839782715-0.0177700817585j), + (0.999826967716-0.0184917747974j), + (0.999818325043-0.0191045701504j), + (0.999807476997-0.0196143388748j), + (0.999797284603-0.0200265944004j), + (0.999791204929-0.0203481912613j), + (0.99978852272-0.0205836892128j), + (0.99978530407-0.0207380950451j), + (0.999785065651-0.0206423997879j), + (0.999787807465-0.0204866230488j), + (0.999794304371-0.0202808082104j), + (0.999800384045-0.0200312435627j), + (0.999803245068-0.0197458267212j), + (0.9998087883-0.0194311738014j), + (0.999816894531-0.0190933048725j), + (0.999825954437-0.0187371373177j), + (0.999829888344-0.0183679759502j), + (0.999835848808-0.017987690866j), + (0.999844014645-0.0176006518304j)) + + sampling_freq = 10e3 + freq = sampling_freq / 100 + + loop_bw = math.pi/100.0 + maxf = 1 + minf = -1 + + src = gr.sig_source_c(sampling_freq, gr.GR_COS_WAVE, freq, 1.0) + pll = analog.pll_carriertracking_cc(loop_bw, maxf, minf) + head = gr.head(gr.sizeof_gr_complex, int (freq)) + dst = gr.vector_sink_c() + + self.tb.connect(src, pll, head) + self.tb.connect(head, dst) + + self.tb.run() + dst_data = dst.data() + self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5) + +if __name__ == '__main__': + gr_unittest.run(test_pll_carriertracking, "test_pll_carriertracking.xml") diff --git a/gr-analog/python/qa_pll_freqdet.py b/gr-analog/python/qa_pll_freqdet.py new file mode 100755 index 000000000..1f808afa6 --- /dev/null +++ b/gr-analog/python/qa_pll_freqdet.py @@ -0,0 +1,161 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010-2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import analog_swig as analog +import math + +class test_pll_freqdet(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block() + + def tearDown (self): + self.tb = None + + def test_pll_freqdet(self): + expected_result = (0.0, + 4.33888922882e-08, + 0.367369994515, + 1.08135249597, + 2.10983253908, + 3.42221529438, + 4.98940390402, + 6.78379190842, + 8.77923286024, + 10.9510106794, + 13.2758363182, + 15.7317829127, + 18.2982902299, + 20.9561068599, + 23.6755271122, + 26.452952094, + 29.2731265301, + 32.1219053479, + 34.9862418188, + 37.8540971414, + 40.7144315483, + 43.5571390869, + 46.3730179743, + 49.1537231663, + 51.8917218889, + 54.58026103, + 57.2015358514, + 59.7513664199, + 62.2380533124, + 64.657612252, + 67.006640002, + 69.2822432184, + 71.4820384499, + 73.6041047056, + 75.6469478817, + 77.6094829742, + 79.4909866472, + 81.2911031615, + 83.0097850853, + 84.6355598352, + 86.1820937186, + 87.6504420946, + 89.0418441206, + 90.3577286819, + 91.5996432431, + 92.7692775646, + 93.8684162704, + 94.8989269904, + 95.8627662892, + 96.7619381633, + 97.598505899, + 98.362769679, + 99.0579904444, + 99.6992633875, + 100.288805948, + 100.828805921, + 101.321421457, + 101.76878699, + 102.17300138, + 102.536116055, + 102.860158727, + 103.147085962, + 103.398830608, + 103.617254366, + 103.792467691, + 103.939387906, + 104.060030865, + 104.15631756, + 104.230085975, + 104.283067372, + 104.316933727, + 104.333238432, + 104.333440018, + 104.318914008, + 104.290941063, + 104.250742554, + 104.187634452, + 104.103822339, + 104.013227468, + 103.916810336, + 103.815448432, + 103.709936239, + 103.600997093, + 103.489283183, + 103.375351833, + 103.259712936, + 103.142828952, + 103.025091195, + 102.90686726, + 102.776726069, + 102.648078982, + 102.521459607, + 102.397294831, + 102.275999684, + 102.157882471, + 102.043215927, + 101.93218978, + 101.824958181, + 101.72159228, + 101.622151366) + + sampling_freq = 10e3 + freq = sampling_freq / 100 + + loop_bw = math.pi/100.0 + maxf = 1 + minf = -1 + + src = gr.sig_source_c(sampling_freq, gr.GR_COS_WAVE, freq, 1.0) + pll = analog.pll_freqdet_cf(loop_bw, maxf, minf) + head = gr.head(gr.sizeof_float, int (freq)) + dst = gr.vector_sink_f() + + self.tb.connect(src, pll, head) + self.tb.connect(head, dst) + + self.tb.run() + dst_data = dst.data() + + # convert it from normalized frequency to absolute frequency (Hz) + dst_data = [i*(sampling_freq/(2*math.pi)) for i in dst_data] + + self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 3) + +if __name__ == '__main__': + gr_unittest.run(test_pll_freqdet, "test_pll_freqdet.xml") diff --git a/gr-analog/python/qa_pll_refout.py b/gr-analog/python/qa_pll_refout.py new file mode 100755 index 000000000..2831b2909 --- /dev/null +++ b/gr-analog/python/qa_pll_refout.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python +# +# Copyright 2004,2010,2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import analog_swig as analog +import math + +class test_pll_refout(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_pll_refout(self): + expected_result = ((1+0j), + (1+6.4087357643e-10j), + (0.999985277653+0.00542619498447j), + (0.999868750572+0.0162021834403j), + (0.99948567152+0.0320679470897j), + (0.99860727787+0.0527590736747j), + (0.996953129768+0.0780025869608j), + (0.994203746319+0.107512556016j), + (0.990011692047+0.140985429287j), + (0.984013140202+0.178095817566j), + (0.975838363171+0.218493551016j), + (0.965121984482+0.261800557375j), + (0.95151245594+0.307610183954j), + (0.934681296349+0.355486690998j), + (0.914401650429+0.404808044434j), + (0.890356600285+0.455263823271j), + (0.862329125404+0.506348133087j), + (0.830152392387+0.557536482811j), + (0.793714106083+0.608290970325j), + (0.752960026264+0.658066213131j), + (0.707896590233+0.706316053867j), + (0.658591926098+0.752500295639j), + (0.605175673962+0.796091973782j), + (0.547837555408+0.836584687233j), + (0.48682525754+0.873499393463j), + (0.42244040966+0.906390726566j), + (0.355197101831+0.934791445732j), + (0.285494059324+0.958380460739j), + (0.213591173291+0.976923108101j), + (0.139945343137+0.990159213543j), + (0.065038472414+0.997882783413j), + (-0.0106285437942+0.999943494797j), + (-0.0865436866879+0.996248066425j), + (-0.162189796567+0.986759603024j), + (-0.23705175519+0.971496999264j), + (-0.310622543097+0.950533330441j), + (-0.38240903616+0.923993110657j), + (-0.451937526464+0.89204955101j), + (-0.518758952618+0.854920566082j), + (-0.582311093807+0.812966048717j), + (-0.642372369766+0.76639264822j), + (-0.698591887951+0.715520322323j), + (-0.750654160976+0.660695314407j), + (-0.798280358315+0.602286040783j), + (-0.841228663921+0.540679454803j), + (-0.87929558754+0.476276367903j), + (-0.912315964699+0.409486919641j), + (-0.940161883831+0.340728074312j), + (-0.962742805481+0.270418733358j), + (-0.980004072189+0.198977485299j), + (-0.991925954819+0.126818284392j), + (-0.99851256609+0.0545223206282j), + (-0.999846458435-0.0175215266645j), + (-0.996021270752-0.0891158208251j), + (-0.987133920193-0.159895718098j), + (-0.973306238651-0.2295101583j), + (-0.954683184624-0.297624111176j), + (-0.931430280209-0.363919824362j), + (-0.903732538223-0.428097635508j), + (-0.871792256832-0.489875763655j), + (-0.835827112198-0.548992812634j), + (-0.796068251133-0.605206847191j), + (-0.752758979797-0.658296227455j), + (-0.706152498722-0.70805978775j), + (-0.656641483307-0.754202902317j), + (-0.604367733002-0.79670548439j), + (-0.549597978592-0.835429251194j), + (-0.492602348328-0.870254516602j), + (-0.433654457331-0.901079237461j), + (-0.373029649258-0.927819430828j), + (-0.31100410223-0.950408577919j), + (-0.247853919864-0.968797445297j), + (-0.183855071664-0.982953369617j), + (-0.119282215834-0.992860376835j), + (-0.0544078871608-0.998518764973j), + (0.0104992967099-0.999944865704j), + (0.0749994292855-0.997183561325j), + (0.138844624162-0.990314185619j), + (0.201967850327-0.979392170906j), + (0.264124274254-0.964488625526j), + (0.325075358152-0.945688128471j), + (0.3845885396-0.92308807373j), + (0.442438393831-0.89679890871j), + (0.498407125473-0.866943061352j), + (0.552284479141-0.833655714989j), + (0.603869199753-0.797083437443j), + (0.652970373631-0.757383465767j), + (0.69940674305-0.714723825455j), + (0.743007957935-0.66928255558j), + (0.78350687027-0.62138313055j), + (0.820889055729-0.571087777615j), + (0.855021059513-0.51859331131j), + (0.885780930519-0.46410369873j), + (0.913058102131-0.407829582691j), + (0.936754107475-0.349988251925j), + (0.956783294678-0.290801793337j), + (0.973072886467-0.230497643352j), + (0.985563337803-0.169307261705j), + (0.9942086339-0.1074674353j), + (0.9989772439-0.0452152714133j)) + + sampling_freq = 10e3 + freq = sampling_freq / 100 + + loop_bw = math.pi/100.0 + maxf = 1 + minf = -1 + + src = gr.sig_source_c(sampling_freq, gr.GR_COS_WAVE, freq, 1.0) + pll = analog.pll_refout_cc(loop_bw, maxf, minf) + head = gr.head(gr.sizeof_gr_complex, int (freq)) + dst = gr.vector_sink_c() + + self.tb.connect(src, pll, head) + self.tb.connect(head, dst) + + self.tb.run() + dst_data = dst.data() + self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_pll_refout, "test_pll_refout.xml") diff --git a/gr-analog/swig/analog_swig.i b/gr-analog/swig/analog_swig.i index 665da9686..b1bc61d5d 100644 --- a/gr-analog/swig/analog_swig.i +++ b/gr-analog/swig/analog_swig.i @@ -44,6 +44,9 @@ #include "analog/noise_source_f.h" #include "analog/noise_source_c.h" #include "analog/phase_modulator_fc.h" +#include "analog/pll_carriertracking_cc.h" +#include "analog/pll_freqdet_cf.h" +#include "analog/pll_refout_cc.h" #include "analog/squelch_base_cc.h" #include "analog/squelch_base_ff.h" %} @@ -65,6 +68,9 @@ %include "analog/noise_source_f.h" %include "analog/noise_source_c.h" %include "analog/phase_modulator_fc.h" +%include "analog/pll_carriertracking_cc.h" +%include "analog/pll_freqdet_cf.h" +%include "analog/pll_refout_cc.h" %include "analog/squelch_base_cc.h" %include "analog/squelch_base_ff.h" @@ -83,3 +89,6 @@ GR_SWIG_BLOCK_MAGIC2(analog, noise_source_i); GR_SWIG_BLOCK_MAGIC2(analog, noise_source_f); GR_SWIG_BLOCK_MAGIC2(analog, noise_source_c); GR_SWIG_BLOCK_MAGIC2(analog, phase_modulator_fc); +GR_SWIG_BLOCK_MAGIC2(analog, pll_carriertracking_cc); +GR_SWIG_BLOCK_MAGIC2(analog, pll_freqdet_cf); +GR_SWIG_BLOCK_MAGIC2(analog, pll_refout_cc); |