add Vcs entries to control file
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_freq_xlating_fir_filter_ccf.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003 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 /*
24  * WARNING: This file is automatically generated by
25  * generate_gr_freq_xlating_fir_filter_XXX.py 
26  * Any changes made to this file will be overwritten.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <gr_freq_xlating_fir_filter_ccf.h>
34 #include <gr_fir_ccc.h>
35 #include <gr_fir_util.h>
36 #include <gr_io_signature.h>
37
38 gr_freq_xlating_fir_filter_ccf_sptr 
39 gr_make_freq_xlating_fir_filter_ccf (int decimation, const std::vector<float> &taps,
40                      double center_freq, double sampling_freq)
41 {
42   return gr_freq_xlating_fir_filter_ccf_sptr (new gr_freq_xlating_fir_filter_ccf (decimation, taps, center_freq, sampling_freq));
43 }
44
45
46 gr_freq_xlating_fir_filter_ccf::gr_freq_xlating_fir_filter_ccf (
47
48         int decimation,
49         const std::vector<float> &taps,
50         double center_freq,
51         double sampling_freq)
52
53   : gr_sync_decimator ("freq_xlating_fir_filter_ccf",
54                        gr_make_io_signature (1, 1, sizeof (gr_complex)),
55                        gr_make_io_signature (1, 1, sizeof (gr_complex)),
56                        decimation),
57     d_proto_taps (taps), d_center_freq (center_freq), d_sampling_freq (sampling_freq),
58     d_updated (false)
59 {
60   std::vector<gr_complex>       dummy_taps;
61   d_composite_fir = gr_fir_util::create_gr_fir_ccc (dummy_taps);
62
63   set_history (d_proto_taps.size ());
64   build_composite_fir ();
65 }
66
67 gr_freq_xlating_fir_filter_ccf::~gr_freq_xlating_fir_filter_ccf ()
68 {
69   delete d_composite_fir;
70 }
71
72 void
73 gr_freq_xlating_fir_filter_ccf::build_composite_fir ()
74 {
75   std::vector<gr_complex> ctaps (d_proto_taps.size ());
76
77   float fwT0 = 2 * M_PI * d_center_freq / d_sampling_freq;
78   for (unsigned int i = 0; i < d_proto_taps.size (); i++)
79     ctaps[i] = d_proto_taps[i] * exp (gr_complex (0, i * fwT0));
80
81   d_composite_fir->set_taps (gr_reverse(ctaps));
82   d_r.set_phase_incr (exp (gr_complex (0, fwT0 * decimation ())));
83 }
84
85 void
86 gr_freq_xlating_fir_filter_ccf::set_center_freq (double center_freq)
87 {
88   d_center_freq = center_freq;
89   d_updated = true;
90 }
91
92 void
93 gr_freq_xlating_fir_filter_ccf::set_taps (const std::vector<float> &taps)
94 {
95   d_proto_taps = taps;
96   d_updated = true;
97 }
98
99 int
100 gr_freq_xlating_fir_filter_ccf::work (int noutput_items,
101                    gr_vector_const_void_star &input_items,
102                    gr_vector_void_star &output_items)
103 {
104   gr_complex     *in  = (gr_complex *) input_items[0];
105   gr_complex     *out = (gr_complex *) output_items[0];
106
107   // rebuild composite FIR if the center freq has changed
108
109   if (d_updated){
110     set_history (d_proto_taps.size ());
111     build_composite_fir ();
112     d_updated = false;
113     return 0;                // history requirements may have changed.
114   }
115
116   unsigned j = 0;
117   for (int i = 0; i < noutput_items; i++){
118     out[i] = d_r.rotate (d_composite_fir->filter (&in[j]));
119     j += decimation ();
120   }
121   
122   return noutput_items;
123 }