annotate dsp/transforms/DCT.h @ 191:857ca50ca25f

Add DCT
author Chris Cannam
date Wed, 07 Oct 2015 09:55:35 +0100
parents
children 701233f8ed41
rev   line source
Chris@191 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@191 2
Chris@191 3 /*
Chris@191 4 QM DSP Library
Chris@191 5
Chris@191 6 Centre for Digital Music, Queen Mary, University of London.
Chris@191 7 This file by Chris Cannam.
Chris@191 8
Chris@191 9 This program is free software; you can redistribute it and/or
Chris@191 10 modify it under the terms of the GNU General Public License as
Chris@191 11 published by the Free Software Foundation; either version 2 of the
Chris@191 12 License, or (at your option) any later version. See the file
Chris@191 13 COPYING included with this distribution for more information.
Chris@191 14 */
Chris@191 15
Chris@191 16 #ifndef DCT_H
Chris@191 17 #define DCT_H
Chris@191 18
Chris@191 19 #include "FFT.h"
Chris@191 20
Chris@191 21 #include <vector>
Chris@191 22
Chris@191 23 class DCT
Chris@191 24 {
Chris@191 25 public:
Chris@191 26 /**
Chris@191 27 * Construct a DCT object to calculate the Discrete Cosine
Chris@191 28 * Transform given input of size n samples. The transform is
Chris@191 29 * implemented using an FFT of size 4n, for simplicity.
Chris@191 30 */
Chris@191 31 DCT(int n);
Chris@191 32
Chris@191 33 ~DCT();
Chris@191 34
Chris@191 35 /**
Chris@191 36 * Carry out a type-II DCT of size n, where n is the value
Chris@191 37 * provided to the constructor above.
Chris@191 38 *
Chris@191 39 * The in and out pointers must point to (enough space for) n
Chris@191 40 * values.
Chris@191 41 */
Chris@191 42 void forward(const double *in, double *out);
Chris@191 43
Chris@191 44 /**
Chris@191 45 * Carry out a type-II unitary DCT of size n, where n is the value
Chris@191 46 * provided to the constructor above. This is a scaled version of
Chris@191 47 * the type-II DCT corresponding to a transform with an orthogonal
Chris@191 48 * matrix. This is the transform implemented by the dct() function
Chris@191 49 * in MATLAB.
Chris@191 50 *
Chris@191 51 * The in and out pointers must point to (enough space for) n
Chris@191 52 * values.
Chris@191 53 */
Chris@191 54 void forwardUnitary(const double *in, double *out);
Chris@191 55
Chris@191 56 /**
Chris@191 57 * Carry out a type-III (inverse) DCT of size n, where n is the
Chris@191 58 * value provided to the constructor above.
Chris@191 59 *
Chris@191 60 * The in and out pointers must point to (enough space for) n
Chris@191 61 * values.
Chris@191 62 */
Chris@191 63 void inverse(const double *in, double *out);
Chris@191 64
Chris@191 65 /**
Chris@191 66 * Carry out a type-III (inverse) unitary DCT of size n, where n
Chris@191 67 * is the value provided to the constructor above. This is the
Chris@191 68 * inverse of forwardUnitary().
Chris@191 69 *
Chris@191 70 * The in and out pointers must point to (enough space for) n
Chris@191 71 * values.
Chris@191 72 */
Chris@191 73 void inverseUnitary(const double *in, double *out);
Chris@191 74
Chris@191 75 private:
Chris@191 76 int m_n;
Chris@191 77 double m_scale;
Chris@191 78 std::vector<double> m_scaled;
Chris@191 79 std::vector<double> m_time2;
Chris@191 80 std::vector<double> m_freq2r;
Chris@191 81 std::vector<double> m_freq2i;
Chris@191 82 FFTReal m_fft;
Chris@191 83 };
Chris@191 84
Chris@191 85 #endif