3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gr_io_signature.h>
28 #include <gr_clock_recovery_mm_ff.h>
29 #include <gri_mmse_fir_interpolator.h>
32 #define DEBUG_CR_MM_FF 0 // must be defined as 0 or 1
36 gr_clock_recovery_mm_ff_sptr
37 gr_make_clock_recovery_mm_ff(float omega, float gain_omega, float mu, float gain_mu,
38 float omega_relative_limit)
40 return gr_clock_recovery_mm_ff_sptr (new gr_clock_recovery_mm_ff (omega,
44 omega_relative_limit));
47 gr_clock_recovery_mm_ff::gr_clock_recovery_mm_ff (float omega, float gain_omega, float mu, float gain_mu,
48 float omega_relative_limit)
49 : gr_block ("clock_recovery_mm_ff",
50 gr_make_io_signature (1, 1, sizeof (float)),
51 gr_make_io_signature (1, 1, sizeof (float))),
52 d_mu (mu), d_gain_omega(gain_omega), d_gain_mu(gain_mu),
53 d_last_sample(0), d_interp(new gri_mmse_fir_interpolator()),
54 d_logfile(0), d_omega_relative_limit(omega_relative_limit)
57 throw std::out_of_range ("clock rate must be > 0");
58 if (gain_mu < 0 || gain_omega < 0)
59 throw std::out_of_range ("Gains must be non-negative");
61 set_omega(omega); // also sets min and max omega
62 set_relative_rate (1.0 / omega);
65 d_logfile = fopen("cr_mm_ff.dat", "wb");
68 gr_clock_recovery_mm_ff::~gr_clock_recovery_mm_ff ()
72 if (DEBUG_CR_MM_FF && d_logfile){
79 gr_clock_recovery_mm_ff::forecast(int noutput_items, gr_vector_int &ninput_items_required)
81 unsigned ninputs = ninput_items_required.size();
82 for (unsigned i=0; i < ninputs; i++)
83 ninput_items_required[i] =
84 (int) ceil((noutput_items * d_omega) + d_interp->ntaps());
90 return x < 0 ? -1.0F : 1.0F;
94 * This implements the Mueller and Müller (M&M) discrete-time error-tracking synchronizer.
96 * See "Digital Communication Receivers: Synchronization, Channel
97 * Estimation and Signal Processing" by Heinrich Meyr, Marc Moeneclaey, & Stefan Fechtel.
101 gr_clock_recovery_mm_ff::general_work (int noutput_items,
102 gr_vector_int &ninput_items,
103 gr_vector_const_void_star &input_items,
104 gr_vector_void_star &output_items)
106 const float *in = (const float *) input_items[0];
107 float *out = (float *) output_items[0];
109 int ii = 0; // input index
110 int oo = 0; // output index
113 while (oo < noutput_items){
115 // produce output sample
116 out[oo] = d_interp->interpolate (&in[ii], d_mu);
117 mm_val = slice(d_last_sample) * out[oo] - slice(out[oo]) * d_last_sample;
118 d_last_sample = out[oo];
120 d_omega = d_omega + d_gain_omega * mm_val;
121 if (d_omega > d_max_omega)
122 d_omega = d_max_omega;
123 else if (d_omega < d_min_omega)
124 d_omega = d_min_omega;
126 d_mu = d_mu + d_omega + d_gain_mu * mm_val;
128 ii += (int) floor(d_mu);
129 d_mu = d_mu - floor(d_mu);
132 if (DEBUG_CR_MM_FF && d_logfile){
133 fwrite(&d_omega, sizeof(d_omega), 1, d_logfile);
139 return noutput_items;