annotate constant-q-cpp/src/dsp/FFT.h @ 372:af71cbdab621 tip

Update bqvec code
author Chris Cannam
date Tue, 19 Nov 2019 10:13:32 +0000
parents 5d0a2ebb4d17
children
rev   line source
Chris@366 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@366 2 /*
Chris@366 3 Constant-Q library
Chris@366 4 Copyright (c) 2013-2014 Queen Mary, University of London
Chris@366 5
Chris@366 6 Permission is hereby granted, free of charge, to any person
Chris@366 7 obtaining a copy of this software and associated documentation
Chris@366 8 files (the "Software"), to deal in the Software without
Chris@366 9 restriction, including without limitation the rights to use, copy,
Chris@366 10 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@366 11 of the Software, and to permit persons to whom the Software is
Chris@366 12 furnished to do so, subject to the following conditions:
Chris@366 13
Chris@366 14 The above copyright notice and this permission notice shall be
Chris@366 15 included in all copies or substantial portions of the Software.
Chris@366 16
Chris@366 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@366 18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@366 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@366 20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
Chris@366 21 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@366 22 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@366 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@366 24
Chris@366 25 Except as contained in this notice, the names of the Centre for
Chris@366 26 Digital Music; Queen Mary, University of London; and Chris Cannam
Chris@366 27 shall not be used in advertising or otherwise to promote the sale,
Chris@366 28 use or other dealings in this Software without prior written
Chris@366 29 authorization.
Chris@366 30 */
Chris@366 31
Chris@366 32 #ifndef FFT_H
Chris@366 33 #define FFT_H
Chris@366 34
Chris@366 35 class FFT
Chris@366 36 {
Chris@366 37 public:
Chris@366 38 /**
Chris@366 39 * Construct an FFT object to carry out complex-to-complex
Chris@366 40 * transforms of size nsamples. nsamples does not have to be a
Chris@366 41 * power of two.
Chris@366 42 */
Chris@366 43 FFT(int nsamples);
Chris@366 44 ~FFT();
Chris@366 45
Chris@366 46 /**
Chris@366 47 * Carry out a forward or inverse transform (depending on the
Chris@366 48 * value of inverse) of size nsamples, where nsamples is the value
Chris@366 49 * provided to the constructor above.
Chris@366 50 *
Chris@366 51 * realIn and (where present) imagIn should contain nsamples each,
Chris@366 52 * and realOut and imagOut should point to enough space to receive
Chris@366 53 * nsamples each.
Chris@366 54 *
Chris@366 55 * imagIn may be NULL if the signal is real, but the other
Chris@366 56 * pointers must be valid.
Chris@366 57 *
Chris@366 58 * The inverse transform is scaled by 1/nsamples.
Chris@366 59 */
Chris@366 60 void process(bool inverse,
Chris@366 61 const double *realIn, const double *imagIn,
Chris@366 62 double *realOut, double *imagOut);
Chris@366 63
Chris@366 64 private:
Chris@366 65 class D;
Chris@366 66 D *m_d;
Chris@366 67 };
Chris@366 68
Chris@366 69 class FFTReal
Chris@366 70 {
Chris@366 71 public:
Chris@366 72 /**
Chris@366 73 * Construct an FFT object to carry out real-to-complex transforms
Chris@366 74 * of size nsamples. nsamples does not have to be a power of two,
Chris@366 75 * but it does have to be even. (Use the complex-complex FFT above
Chris@366 76 * if you need an odd FFT size. This constructor will throw
Chris@366 77 * std::invalid_argument if nsamples is odd.)
Chris@366 78 */
Chris@366 79 FFTReal(int nsamples);
Chris@366 80 ~FFTReal();
Chris@366 81
Chris@366 82 /**
Chris@366 83 * Carry out a forward real-to-complex transform of size nsamples,
Chris@366 84 * where nsamples is the value provided to the constructor above.
Chris@366 85 *
Chris@366 86 * realIn, realOut, and imagOut must point to (enough space for)
Chris@366 87 * nsamples values. For consistency with the FFT class above, and
Chris@366 88 * compatibility with existing code, the conjugate half of the
Chris@366 89 * output is returned even though it is redundant.
Chris@366 90 */
Chris@366 91 void forward(const double *realIn,
Chris@366 92 double *realOut, double *imagOut);
Chris@366 93
Chris@366 94 /**
Chris@366 95 * Carry out a forward real-to-complex transform of size nsamples,
Chris@366 96 * where nsamples is the value provided to the constructor
Chris@366 97 * above. Return only the magnitudes of the complex output values.
Chris@366 98 *
Chris@366 99 * realIn and magOut must point to (enough space for) nsamples
Chris@366 100 * values. For consistency with the FFT class above, and
Chris@366 101 * compatibility with existing code, the conjugate half of the
Chris@366 102 * output is returned even though it is redundant.
Chris@366 103 */
Chris@366 104 void forwardMagnitude(const double *realIn, double *magOut);
Chris@366 105
Chris@366 106 /**
Chris@366 107 * Carry out an inverse real transform (i.e. complex-to-real) of
Chris@366 108 * size nsamples, where nsamples is the value provided to the
Chris@366 109 * constructor above.
Chris@366 110 *
Chris@366 111 * realIn and imagIn should point to at least nsamples/2+1 values;
Chris@366 112 * if more are provided, only the first nsamples/2+1 values of
Chris@366 113 * each will be used (the conjugate half will always be deduced
Chris@366 114 * from the first nsamples/2+1 rather than being read from the
Chris@366 115 * input data). realOut should point to enough space to receive
Chris@366 116 * nsamples values.
Chris@366 117 *
Chris@366 118 * The inverse transform is scaled by 1/nsamples.
Chris@366 119 */
Chris@366 120 void inverse(const double *realIn, const double *imagIn,
Chris@366 121 double *realOut);
Chris@366 122
Chris@366 123 private:
Chris@366 124 class D;
Chris@366 125 D *m_d;
Chris@366 126 };
Chris@366 127
Chris@366 128 #endif