root / gnuradio-core / src / lib / general / gr_pll_refout_cc.cc @ 0a9b999b
History | View | Annotate | Download (2.7 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2004,2010 Free Software Foundation, Inc. |
| 4 | * |
| 5 | * This file is part of GNU Radio |
| 6 | * |
| 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) |
| 10 | * any later version. |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 21 | */ |
| 22 | |
| 23 | // WARNING: this file is machine generated. Edits will be over written
|
| 24 | |
| 25 | #ifdef HAVE_CONFIG_H
|
| 26 | #include "config.h" |
| 27 | #endif
|
| 28 | |
| 29 | #include <gr_pll_refout_cc.h> |
| 30 | #include <gr_io_signature.h> |
| 31 | #include <gr_sincos.h> |
| 32 | #include <math.h> |
| 33 | #include <gr_math.h> |
| 34 | |
| 35 | #define M_TWOPI (2*M_PI) |
| 36 | |
| 37 | gr_pll_refout_cc_sptr |
| 38 | gr_make_pll_refout_cc (float alpha, float beta, float max_freq, float min_freq) |
| 39 | {
|
| 40 | return gnuradio::get_initial_sptr(new gr_pll_refout_cc (alpha, beta, max_freq, min_freq)); |
| 41 | } |
| 42 | |
| 43 | gr_pll_refout_cc::gr_pll_refout_cc (float alpha, float beta, float max_freq, float min_freq) |
| 44 | : gr_sync_block ("pll_refout_cc",
|
| 45 | gr_make_io_signature (1, 1, sizeof (gr_complex)), |
| 46 | gr_make_io_signature (1, 1, sizeof (gr_complex))), |
| 47 | d_alpha(alpha), d_beta(beta), |
| 48 | d_max_freq(max_freq), d_min_freq(min_freq), |
| 49 | d_phase(0), d_freq((max_freq+min_freq)/2) |
| 50 | {
|
| 51 | } |
| 52 | |
| 53 | float
|
| 54 | gr_pll_refout_cc::mod_2pi (float in)
|
| 55 | {
|
| 56 | if(in>M_PI)
|
| 57 | return in-M_TWOPI;
|
| 58 | else if(in<-M_PI) |
| 59 | return in+M_TWOPI;
|
| 60 | else
|
| 61 | return in;
|
| 62 | } |
| 63 | |
| 64 | float
|
| 65 | gr_pll_refout_cc::phase_detector(gr_complex sample,float ref_phase)
|
| 66 | {
|
| 67 | float sample_phase;
|
| 68 | sample_phase = gr_fast_atan2f(sample.imag(),sample.real()); |
| 69 | return mod_2pi(sample_phase-ref_phase);
|
| 70 | } |
| 71 | |
| 72 | int
|
| 73 | gr_pll_refout_cc::work (int noutput_items,
|
| 74 | gr_vector_const_void_star &input_items, |
| 75 | gr_vector_void_star &output_items) |
| 76 | {
|
| 77 | const gr_complex *iptr = (gr_complex *) input_items[0]; |
| 78 | gr_complex *optr = (gr_complex *) output_items[0];
|
| 79 | |
| 80 | float error;
|
| 81 | float t_imag, t_real;
|
| 82 | int size = noutput_items;
|
| 83 | |
| 84 | while (size-- > 0) { |
| 85 | error = phase_detector(*iptr++,d_phase); |
| 86 | |
| 87 | d_freq = d_freq + d_beta * error; |
| 88 | d_phase = mod_2pi(d_phase + d_freq + d_alpha * error); |
| 89 | |
| 90 | if (d_freq > d_max_freq)
|
| 91 | d_freq = d_max_freq; |
| 92 | else if (d_freq < d_min_freq) |
| 93 | d_freq = d_min_freq; |
| 94 | gr_sincosf(d_phase,&t_imag,&t_real); |
| 95 | *optr++ = gr_complex(t_real,t_imag); |
| 96 | } |
| 97 | return noutput_items;
|
| 98 | } |