GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
fft.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003,2008,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 #ifndef _FFT_FFT_H_
24 #define _FFT_FFT_H_
25 
26 /*
27  * Wrappers for FFTW single precision 1d dft
28  */
29 
30 #include <gnuradio/fft/api.h>
31 #include <gnuradio/gr_complex.h>
32 #include <boost/thread.hpp>
33 
34 namespace gr {
35 namespace fft {
36 
37 
38 /*! \brief Helper function for allocating complex* buffers
39  */
41 
42 /*! \brief Helper function for allocating float* buffers
43  */
44 FFT_API float* malloc_float(int size);
45 
46 /*! \brief Helper function for allocating double* buffers
47  */
48 FFT_API double* malloc_double(int size);
49 
50 /*! \brief Helper function for freeing fft buffers
51  */
52 FFT_API void free(void* b);
53 
54 /*!
55  * \brief Export reference to planner mutex for those apps that
56  * want to use FFTW w/o using the fft_impl_fftw* classes.
57  */
59 {
60 public:
62  /*!
63  * Return reference to planner mutex
64  */
65  static boost::mutex& mutex();
66 };
67 
68 /*!
69  * \brief FFT: complex in, complex out
70  * \ingroup misc
71  */
73 {
74  int d_fft_size;
75  int d_nthreads;
76  gr_complex* d_inbuf;
77  gr_complex* d_outbuf;
78  void* d_plan;
79 
80 public:
81  fft_complex(int fft_size, bool forward = true, int nthreads = 1);
82  virtual ~fft_complex();
83 
84  /*
85  * These return pointers to buffers owned by fft_impl_fft_complex
86  * into which input and output take place. It's done this way in
87  * order to ensure optimal alignment for SIMD instructions.
88  */
89  gr_complex* get_inbuf() const { return d_inbuf; }
90  gr_complex* get_outbuf() const { return d_outbuf; }
91 
92  int inbuf_length() const { return d_fft_size; }
93  int outbuf_length() const { return d_fft_size; }
94 
95  /*!
96  * Set the number of threads to use for caclulation.
97  */
98  void set_nthreads(int n);
99 
100  /*!
101  * Get the number of threads being used by FFTW
102  */
103  int nthreads() const { return d_nthreads; }
104 
105  /*!
106  * compute FFT. The input comes from inbuf, the output is placed in
107  * outbuf.
108  */
109  void execute();
110 };
111 
112 /*!
113  * \brief FFT: real in, complex out
114  * \ingroup misc
115  */
117 {
118  int d_fft_size;
119  int d_nthreads;
120  float* d_inbuf;
121  gr_complex* d_outbuf;
122  void* d_plan;
123 
124 public:
125  fft_real_fwd(int fft_size, int nthreads = 1);
126  virtual ~fft_real_fwd();
127 
128  /*
129  * These return pointers to buffers owned by fft_impl_fft_real_fwd
130  * into which input and output take place. It's done this way in
131  * order to ensure optimal alignment for SIMD instructions.
132  */
133  float* get_inbuf() const { return d_inbuf; }
134  gr_complex* get_outbuf() const { return d_outbuf; }
135 
136  int inbuf_length() const { return d_fft_size; }
137  int outbuf_length() const { return d_fft_size / 2 + 1; }
138 
139  /*!
140  * Set the number of threads to use for caclulation.
141  */
142  void set_nthreads(int n);
143 
144  /*!
145  * Get the number of threads being used by FFTW
146  */
147  int nthreads() const { return d_nthreads; }
148 
149  /*!
150  * compute FFT. The input comes from inbuf, the output is placed in
151  * outbuf.
152  */
153  void execute();
154 };
155 
156 /*!
157  * \brief FFT: complex in, float out
158  * \ingroup misc
159  */
161 {
162  int d_fft_size;
163  int d_nthreads;
164  gr_complex* d_inbuf;
165  float* d_outbuf;
166  void* d_plan;
167 
168 public:
169  fft_real_rev(int fft_size, int nthreads = 1);
170  virtual ~fft_real_rev();
171 
172  /*
173  * These return pointers to buffers owned by fft_impl_fft_real_rev
174  * into which input and output take place. It's done this way in
175  * order to ensure optimal alignment for SIMD instructions.
176  */
177  gr_complex* get_inbuf() const { return d_inbuf; }
178  float* get_outbuf() const { return d_outbuf; }
179 
180  int inbuf_length() const { return d_fft_size / 2 + 1; }
181  int outbuf_length() const { return d_fft_size; }
182 
183  /*!
184  * Set the number of threads to use for caclulation.
185  */
186  void set_nthreads(int n);
187 
188  /*!
189  * Get the number of threads being used by FFTW
190  */
191  int nthreads() const { return d_nthreads; }
192 
193  /*!
194  * compute FFT. The input comes from inbuf, the output is placed in
195  * outbuf.
196  */
197  void execute();
198 };
199 
200 } /* namespace fft */
201 } /*namespace gr */
202 
203 #endif /* _FFT_FFT_H_ */
gr_complex * get_inbuf() const
Definition: fft.h:177
int outbuf_length() const
Definition: fft.h:137
gr_complex * get_inbuf() const
Definition: fft.h:89
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:49
#define FFT_API
Definition: gr-fft/include/gnuradio/fft/api.h:30
gr_complex * get_outbuf() const
Definition: fft.h:134
FFT: complex in, complex out.
Definition: fft.h:72
int nthreads() const
Definition: fft.h:103
FFT_API double * malloc_double(int size)
Helper function for allocating double* buffers.
int outbuf_length() const
Definition: fft.h:93
FFT_API gr_complex * malloc_complex(int size)
Helper function for allocating complex* buffers.
int outbuf_length() const
Definition: fft.h:181
int inbuf_length() const
Definition: fft.h:92
std::complex< float > gr_complex
Definition: gr_complex.h:27
FFT_API float * malloc_float(int size)
Helper function for allocating float* buffers.
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
int nthreads() const
Definition: fft.h:147
FFT_API void free(void *b)
Helper function for freeing fft buffers.
Export reference to planner mutex for those apps that want to use FFTW w/o using the fft_impl_fftw* c...
Definition: fft.h:58
boost::mutex::scoped_lock scoped_lock
Definition: fft.h:61
int nthreads() const
Definition: fft.h:191
FFT: real in, complex out.
Definition: fft.h:116
FFT: complex in, float out.
Definition: fft.h:160
float * get_outbuf() const
Definition: fft.h:178
int inbuf_length() const
Definition: fft.h:136
gr_complex * get_outbuf() const
Definition: fft.h:90
boost::mutex mutex
Definition: thread.h:48
int inbuf_length() const
Definition: fft.h:180
float * get_inbuf() const
Definition: fft.h:133