3 * Copyright 2009 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 <noaa_carrier_pll_cc.h>
28 #include <gr_io_signature.h>
30 #include <gr_sincos.h>
32 #define M_TWOPI (2*M_PI)
34 noaa_carrier_pll_cc_sptr
35 noaa_make_carrier_pll_cc(float alpha, float beta, float max_offset)
37 return gnuradio::get_initial_sptr(new noaa_carrier_pll_cc(alpha, beta, max_offset));
40 noaa_carrier_pll_cc::noaa_carrier_pll_cc(float alpha, float beta, float max_offset)
41 : gr_sync_block("noaa_carrier_pll_cc",
42 gr_make_io_signature(1, 1, sizeof(gr_complex)),
43 gr_make_io_signature(1, 1, sizeof(gr_complex))),
44 d_alpha(alpha), d_beta(beta), d_max_offset(max_offset),
45 d_phase(0.0), d_freq(0.0)
50 phase_wrap(float phase)
61 noaa_carrier_pll_cc::work(int noutput_items,
62 gr_vector_const_void_star &input_items,
63 gr_vector_void_star &output_items)
65 const gr_complex *in = (const gr_complex *) input_items[0];
66 gr_complex *out = (gr_complex *) output_items[0];
68 for (int i = 0; i < noutput_items; i++) {
70 // Adjust PLL phase/frequency
71 float error = phase_wrap(gr_fast_atan2f(in[i].imag(), in[i].real()) - d_phase);
72 d_freq = gr_branchless_clip(d_freq + error*d_beta, d_max_offset);
73 d_phase = phase_wrap(d_phase + error*d_alpha + d_freq);
75 // Generate and mix out carrier
77 gr_sincosf(d_phase, &im, &re);
78 out[i] = in[i]*gr_complex(re, -im);