GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  */
58  class FFT_API planner {
59  public:
61  /*!
62  * Return reference to planner mutex
63  */
64  static boost::mutex &mutex();
65  };
66 
67  /*!
68  * \brief FFT: complex in, complex out
69  * \ingroup misc
70  */
72  int d_fft_size;
73  int d_nthreads;
74  gr_complex *d_inbuf;
75  gr_complex *d_outbuf;
76  void *d_plan;
77 
78  public:
79  fft_complex(int fft_size, bool forward = true, int nthreads=1);
80  virtual ~fft_complex();
81 
82  /*
83  * These return pointers to buffers owned by fft_impl_fft_complex
84  * into which input and output take place. It's done this way in
85  * order to ensure optimal alignment for SIMD instructions.
86  */
87  gr_complex *get_inbuf() const { return d_inbuf; }
88  gr_complex *get_outbuf() const { return d_outbuf; }
89 
90  int inbuf_length() const { return d_fft_size; }
91  int outbuf_length() const { return d_fft_size; }
92 
93  /*!
94  * Set the number of threads to use for caclulation.
95  */
96  void set_nthreads(int n);
97 
98  /*!
99  * Get the number of threads being used by FFTW
100  */
101  int nthreads() const { return d_nthreads; }
102 
103  /*!
104  * compute FFT. The input comes from inbuf, the output is placed in
105  * outbuf.
106  */
107  void execute();
108  };
109 
110  /*!
111  * \brief FFT: real in, complex out
112  * \ingroup misc
113  */
115  int d_fft_size;
116  int d_nthreads;
117  float *d_inbuf;
118  gr_complex *d_outbuf;
119  void *d_plan;
120 
121  public:
122  fft_real_fwd (int fft_size, int nthreads=1);
123  virtual ~fft_real_fwd ();
124 
125  /*
126  * These return pointers to buffers owned by fft_impl_fft_real_fwd
127  * into which input and output take place. It's done this way in
128  * order to ensure optimal alignment for SIMD instructions.
129  */
130  float *get_inbuf() const { return d_inbuf; }
131  gr_complex *get_outbuf() const { return d_outbuf; }
132 
133  int inbuf_length() const { return d_fft_size; }
134  int outbuf_length() const { return d_fft_size / 2 + 1; }
135 
136  /*!
137  * Set the number of threads to use for caclulation.
138  */
139  void set_nthreads(int n);
140 
141  /*!
142  * Get the number of threads being used by FFTW
143  */
144  int nthreads() const { return d_nthreads; }
145 
146  /*!
147  * compute FFT. The input comes from inbuf, the output is placed in
148  * outbuf.
149  */
150  void execute();
151  };
152 
153  /*!
154  * \brief FFT: complex in, float out
155  * \ingroup misc
156  */
158  int d_fft_size;
159  int d_nthreads;
160  gr_complex *d_inbuf;
161  float *d_outbuf;
162  void *d_plan;
163 
164  public:
165  fft_real_rev(int fft_size, int nthreads=1);
166  virtual ~fft_real_rev();
167 
168  /*
169  * These return pointers to buffers owned by fft_impl_fft_real_rev
170  * into which input and output take place. It's done this way in
171  * order to ensure optimal alignment for SIMD instructions.
172  */
173  gr_complex *get_inbuf() const { return d_inbuf; }
174  float *get_outbuf() const { return d_outbuf; }
175 
176  int inbuf_length() const { return d_fft_size / 2 + 1; }
177  int outbuf_length() const { return d_fft_size; }
178 
179  /*!
180  * Set the number of threads to use for caclulation.
181  */
182  void set_nthreads(int n);
183 
184  /*!
185  * Get the number of threads being used by FFTW
186  */
187  int nthreads() const { return d_nthreads; }
188 
189  /*!
190  * compute FFT. The input comes from inbuf, the output is placed in
191  * outbuf.
192  */
193  void execute();
194  };
195 
196  } /* namespace fft */
197 } /*namespace gr */
198 
199 #endif /* _FFT_FFT_H_ */
gr_complex * get_inbuf() const
Definition: fft.h:173
float * get_inbuf() const
Definition: fft.h:130
int nthreads() const
Definition: fft.h:144
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:47
#define FFT_API
Definition: gr-fft/include/gnuradio/fft/api.h:30
int inbuf_length() const
Definition: fft.h:133
FFT: complex in, complex out.
Definition: fft.h:71
FFT_API double * malloc_double(int size)
Helper function for allocating double* buffers.
int outbuf_length() const
Definition: fft.h:177
FFT_API gr_complex * malloc_complex(int size)
Helper function for allocating complex* buffers.
std::complex< float > gr_complex
Definition: gr_complex.h:27
gr_complex * get_outbuf() const
Definition: fft.h:88
FFT_API float * malloc_float(int size)
Helper function for allocating float* buffers.
Include this header to use the message passing features.
Definition: logger.h:131
int nthreads() const
Definition: fft.h:187
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:60
FFT: real in, complex out.
Definition: fft.h:114
FFT: complex in, float out.
Definition: fft.h:157
int outbuf_length() const
Definition: fft.h:91
gr_complex * get_outbuf() const
Definition: fft.h:131
gr_complex * get_inbuf() const
Definition: fft.h:87
int outbuf_length() const
Definition: fft.h:134
float * get_outbuf() const
Definition: fft.h:174
boost::mutex mutex
Definition: thread.h:46
int nthreads() const
Definition: fft.h:101
int inbuf_length() const
Definition: fft.h:176
int inbuf_length() const
Definition: fft.h:90