summaryrefslogtreecommitdiff
path: root/gr-digital/lib/pfb_clock_sync_ccf_impl.h
blob: e5eef37645a7d75e1900598e989c00fe2de6575d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* -*- c++ -*- */
/*
 * Copyright 2009,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.
 */

#ifndef INCLUDED_DIGITAL_PFB_CLOCK_SYNC_CCF_IMPL_H
#define	INCLUDED_DIGITAL_PFB_CLOCK_SYNC_CCF_IMPL_H

#include <digital/pfb_clock_sync_ccf.h>

using namespace gr::filter;

namespace gr {
  namespace digital {

    class pfb_clock_sync_ccf_impl : public pfb_clock_sync_ccf
    {
    private:
      bool   d_updated;
      double d_sps;
      double d_sample_num;
      float  d_loop_bw;
      float  d_damping;
      float  d_alpha;
      float  d_beta;

      int                                  d_nfilters;
      int                                  d_taps_per_filter;
      std::vector<kernel::fir_filter_ccf*> d_filters;
      std::vector<kernel::fir_filter_ccf*> d_diff_filters;
      std::vector< std::vector<float> >    d_taps;
      std::vector< std::vector<float> >    d_dtaps;

      float d_k;
      float d_rate;
      float d_rate_i;
      float d_rate_f;
      float d_max_dev;
      int   d_filtnum;
      int   d_osps;
      float d_error;
      int   d_out_idx;

      void setup_rpc();

      void create_diff_taps(const std::vector<float> &newtaps,
			    std::vector<float> &difftaps);

    public:
      pfb_clock_sync_ccf_impl(double sps, float loop_bw,
			      const std::vector<float> &taps,
			      unsigned int filter_size=32,
			      float init_phase=0,
			      float max_rate_deviation=1.5,
			      int osps=1);
      ~pfb_clock_sync_ccf_impl();

      void update_gains();

      void set_taps(const std::vector<float> &taps,
		    std::vector< std::vector<float> > &ourtaps,
		    std::vector<kernel::fir_filter_ccf*> &ourfilter);

      std::vector< std::vector<float> > taps() const;
      std::vector< std::vector<float> > diff_taps() const;
      std::vector<float> channel_taps(int channel) const;
      std::vector<float> diff_channel_taps(int channel) const;
      std::string taps_as_string() const;
      std::string diff_taps_as_string() const;

      void set_loop_bandwidth(float bw);
      void set_damping_factor(float df);
      void set_alpha(float alpha);
      void set_beta(float beta);
      void set_max_rate_deviation(float m)
      {
	d_max_dev = m;
      }

      float loop_bandwidth() const;
      float damping_factor() const;
      float alpha() const;
      float beta() const;
      float clock_rate() const;

      /*!
       * \brief Returns the current error of the control loop.
       */
      float error() const;
  
      /*!
       * \brief Returns the current rate of the control loop.
       */
      float rate() const;

      /*!
       * \brief Returns the current phase arm of the control loop.
       */
      float phase() const;

      /*******************************************************************
       *******************************************************************/

      bool check_topology(int ninputs, int noutputs);

      int general_work(int noutput_items,
		       gr_vector_int &ninput_items,
		       gr_vector_const_void_star &input_items,
		       gr_vector_void_star &output_items);
    };

  } /* namespace digital */
} /* namespace gr */

#endif /* INCLUDED_DIGITAL_PFB_CLOCK_SYNC_CCF_IMPL_H */