3 * Copyright 2006,2010 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 <atsc_fpll.h>
28 #include <gr_io_signature.h>
29 #include <atsc_consts.h>
31 #include "fpll_btloop_coupling.h"
37 return gnuradio::get_initial_sptr(new atsc_fpll());
42 * I strongly suggest that you not mess with these...
44 * They are strongly coupled into the symbol timing code and
45 * their value also sets the level of the symbols going
46 * into the equalizer and viterbi decoder.
48 static const float FPLL_AGC_REFERENCE = 2.5 * FPLL_BTLOOP_COUPLING_CONST;
49 static const float FPLL_AGC_RATE = 0.25e-6;
53 atsc_fpll::atsc_fpll()
54 : gr_sync_block("atsc_fpll",
55 gr_make_io_signature(1, 1, sizeof(float)),
56 gr_make_io_signature(1, 1, sizeof(float))),
59 initial_freq = 5.75e6 - 3e6 + 0.31e6 + 5e3; // a_initial_freq;
60 agc.set_rate (FPLL_AGC_RATE);
61 agc.set_reference (FPLL_AGC_REFERENCE);
67 atsc_fpll::initialize ()
71 float alpha = 1 - exp(-1.0 / Fs / 5e-6);
73 afci.set_taps (alpha);
74 afcq.set_taps (alpha);
76 printf("Setting initial_freq: %f\n",initial_freq);
77 nco.set_freq (initial_freq / Fs * 2 * M_PI);
78 nco.set_phase (initial_phase);
83 atsc_fpll::work (int noutput_items,
84 gr_vector_const_void_star &input_items,
85 gr_vector_void_star &output_items)
87 const float *in = (const float *) input_items[0];
88 float *out = (float *) output_items[0];
90 for (int k = 0; k < noutput_items; k++){
94 float input = agc.scale (in[k]);
96 nco.step (); // increment phase
97 nco.sincos (&a_sin, &a_cos); // compute cos and sin
99 float I = input * a_sin;
100 float Q = input * a_cos;
104 float filtered_I = afci.filter (I);
105 float filtered_Q = afcq.filter (Q);
109 // float x = atan2 (filtered_Q, filtered_I);
110 float x = gr_fast_atan2f(filtered_Q, filtered_I);
112 // avoid slamming filter with big transitions
114 static const float limit = M_PI / 2;
121 // static const float alpha = 0.037; // Max value
122 // static const float alpha = 0.005; // takes about 5k samples to pull in, stddev = 323
123 // static const float alpha = 0.002; // takes about 15k samples to pull in, stddev = 69
124 // or about 120k samples on noisy data,
125 static const float alpha = 0.001;
126 static const float beta = alpha * alpha / 4;
128 nco.adjust_phase (alpha * x);
129 nco.adjust_freq (beta * x);
133 return noutput_items;