Statistics
| Branch: | Tag: | Revision:

gnuradio / gr-analog / lib / quadrature_demod_cf_impl.cc @ master

History | View | Annotate | Download (2.26 KB)

1
/* -*- c++ -*- */
2
/*
3
 * Copyright 2004,2005,2010,2012 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
#ifdef HAVE_CONFIG_H
24
#include "config.h"
25
#endif
26

27
#include "quadrature_demod_cf_impl.h"
28
#include <gnuradio/io_signature.h>
29
#include <gnuradio/math.h>
30
#include <volk/volk.h>
31

32
namespace gr {
33
  namespace analog {
34

35
    quadrature_demod_cf::sptr
36
    quadrature_demod_cf::make(float gain)
37
    {
38
      return gnuradio::get_initial_sptr
39
        (new quadrature_demod_cf_impl(gain));
40
    }
41

42
    quadrature_demod_cf_impl::quadrature_demod_cf_impl(float gain)
43
      : sync_block("quadrature_demod_cf",
44
                      io_signature::make(1, 1, sizeof(gr_complex)),
45
                      io_signature::make(1, 1, sizeof(float))),
46
        d_gain(gain)
47
    {
48
      const int alignment_multiple =
49
        volk_get_alignment() / sizeof(gr_complex);
50
      set_alignment(std::max(1, alignment_multiple));
51

52
      set_history(2); // we need to look at the previous value
53
    }
54

55
    quadrature_demod_cf_impl::~quadrature_demod_cf_impl()
56
    {
57
    }
58

59
    int
60
    quadrature_demod_cf_impl::work(int noutput_items,
61
                                   gr_vector_const_void_star &input_items,
62
                                   gr_vector_void_star &output_items)
63
    {
64
      gr_complex *in = (gr_complex*)input_items[0];
65
      float *out = (float*)output_items[0];
66

67
      std::vector<gr_complex> tmp(noutput_items);
68
      volk_32fc_x2_multiply_conjugate_32fc(&tmp[0], &in[1], &in[0], noutput_items);
69
      for(int i = 0; i < noutput_items; i++) {
70
        out[i] = d_gain * gr::fast_atan2f(imag(tmp[i]), real(tmp[i]));
71
      }
72

73
      return noutput_items;
74
    }
75

76
  } /* namespace analog */
77
} /* namespace gr */