3 * Copyright 2004 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 2, 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 <gr_fft_vfc.h>
28 #include <gr_io_signature.h>
34 // FIXME after this is working, change to use native real to complex fft.
35 // It should run twice as fast.
41 gr_make_fft_vfc (int fft_size, bool forward, const std::vector<float> window)
43 return gr_fft_vfc_sptr (new gr_fft_vfc (fft_size, forward, window));
46 gr_fft_vfc::gr_fft_vfc (int fft_size, bool forward, const std::vector<float> window)
47 : gr_sync_block ("fft_vfc",
48 gr_make_io_signature (1, 1, fft_size * sizeof (float)),
49 gr_make_io_signature (1, 1, fft_size * sizeof (gr_complex))),
50 d_fft_size(fft_size), d_window()
53 fprintf (stderr, "fft_vfc: forward must == true\n");
54 throw std::invalid_argument ("fft_vfc: forward must == true");
57 d_fft = new gri_fft_complex (d_fft_size, forward);
62 gr_fft_vfc::~gr_fft_vfc ()
68 gr_fft_vfc::work (int noutput_items,
69 gr_vector_const_void_star &input_items,
70 gr_vector_void_star &output_items)
72 const float *in = (const float *) input_items[0];
73 gr_complex *out = (gr_complex *) output_items[0];
75 unsigned int output_data_size = output_signature()->sizeof_stream_item (0);
79 while (count++ < noutput_items){
81 // copy input into optimally aligned buffer
84 gr_complex *dst = d_fft->get_inbuf();
85 for (unsigned int i = 0; i < d_fft_size; i++) // apply window
86 dst[i] = in[i] * d_window[i];
89 gr_complex *dst = d_fft->get_inbuf();
90 for (unsigned int i = 0; i < d_fft_size; i++) // float to complex conversion
97 // cpoy result to our output
98 memcpy (out, d_fft->get_outbuf (), output_data_size);
104 return noutput_items;
108 gr_fft_vfc::set_window(const std::vector<float> window)
110 if(window.size()==0 || window.size()==d_fft_size) {