3 * Copyright 2008 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.
28 #include <gr_fmdet_cf.h>
29 #include <gr_io_signature.h>
33 #define M_TWOPI (2*M_PI)
36 gr_make_fmdet_cf (float samplerate, float freq_low, float freq_high, float scl)
38 return gr_fmdet_cf_sptr (new gr_fmdet_cf (samplerate, freq_low, freq_high, scl));
41 gr_fmdet_cf::gr_fmdet_cf (float samplerate, float freq_low, float freq_high, float scl)
42 : gr_sync_block ("fmdet_cf",
43 gr_make_io_signature (1, 1, sizeof (gr_complex)),
44 gr_make_io_signature (1, 1, sizeof (float))),
48 const float h[]={0.003118678733, -0.012139843428, 0.027270898036, -0.051318579352,
49 0.090406910552, -0.162926865366, 0.361885392563, 0.000000000000,
50 -0.361885392563, 0.162926865366, -0.090406910552, 0.051318579352,
51 -0.027270898036, 0.012139843428, -0.003118678733};
57 std::vector<float> taps(15);
61 delta = (d_freqhi - d_freqlo);
63 d_bias = 0.5*scl*(d_freqhi+d_freqlo)/delta;
64 for (int i=0;i<15;i++) taps[i] = h[i];
65 // d_filter = gr_fir_util::create_gr_fir_ccf(taps);
70 gr_fmdet_cf::work (int noutput_items,
71 gr_vector_const_void_star &input_items,
72 gr_vector_void_star &output_items)
74 const gr_complex *iptr = (gr_complex *) input_items[0];
75 float *optr = (float *) output_items[0];
76 // const gr_complex *scaleiptr = (gr_complex *) input_items[0];
78 int size = noutput_items;
80 gr_complex Sdot,S0,S1=d_S1,S2=d_S2,S3=d_S3,S4=d_S4;
87 Sdot = d_scl * (-S0+d_8*S1-d_8*S1+S4);
89 d_freq = (S2.real()*Sdot.imag()-S2.imag()*Sdot.real())/
90 (S2.real()*S2.real()+S2.imag()*S2.imag());
98 *optr++ = d_freq-d_bias;
104 return noutput_items;