srfft.h
Go to the documentation of this file.
1 // matrix/srfft.h
2 
3 // Copyright 2009-2011 Microsoft Corporation; Go Vivace Inc.
4 // 2014 Daniel Povey
5 //
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 // This file includes a modified version of code originally published in Malvar,
22 // H., "Signal processing with lapped transforms, " Artech House, Inc., 1992. The
23 // current copyright holder of the original code, Henrique S. Malvar, has given
24 // his permission for the release of this modified version under the Apache
25 // License v2.0.
26 
27 #ifndef KALDI_MATRIX_SRFFT_H_
28 #define KALDI_MATRIX_SRFFT_H_
29 
30 #include "matrix/kaldi-vector.h"
31 #include "matrix/kaldi-matrix.h"
32 
33 namespace kaldi {
34 
37 
38 
39 // This class is based on code by Henrique (Rico) Malvar, from his book
40 // "Signal Processing with Lapped Transforms" (1992). Copied with
41 // permission, optimized by Go Vivace Inc., and converted into C++ by
42 // Microsoft Corporation
43 // This is a more efficient way of doing the complex FFT than ComplexFft
44 // (declared in matrix-functios.h), but it only works for powers of 2.
45 // Note: in multi-threaded code, you would need to have one of these objects per
46 // thread, because multiple calls to Compute in parallel would not work.
47 template<typename Real>
49  public:
51 
52  // N is the number of complex points (must be a power of two, or this
53  // will crash). Note that the constructor does some work so it's best to
54  // initialize the object once and do the computation many times.
55  SplitRadixComplexFft(Integer N);
56 
57  // Copy constructor
59 
60  // Does the FFT computation, given pointers to the real and
61  // imaginary parts. If "forward", do the forward FFT; else
62  // do the inverse FFT (without the 1/N factor).
63  // xr and xi are pointers to zero-based arrays of size N,
64  // containing the real and imaginary parts
65  // respectively.
66  void Compute(Real *xr, Real *xi, bool forward) const;
67 
68  // This version of Compute takes a single array of size N*2,
69  // containing [ r0 im0 r1 im1 ... ]. Otherwise its behavior is the
70  // same as the version above.
71  void Compute(Real *x, bool forward);
72 
73 
74  // This version of Compute is const; it operates on an array of size N*2
75  // containing [ r0 im0 r1 im1 ... ], but it uses the argument "temp_buffer" as
76  // temporary storage instead of a class-member variable. It will allocate it if
77  // needed.
78  void Compute(Real *x, bool forward, std::vector<Real> *temp_buffer) const;
79 
81 
82  protected:
83  // temp_buffer_ is allocated only if someone calls Compute with only one Real*
84  // argument and we need a temporary buffer while creating interleaved data.
85  std::vector<Real> temp_buffer_;
86  private:
87  void ComputeTables();
88  void ComputeRecursive(Real *xr, Real *xi, Integer logn) const;
89  void BitReversePermute(Real *x, Integer logn) const;
90 
91  Integer N_;
92  Integer logn_; // log(N)
93 
94  Integer *brseed_;
95  // brseed is Evans' seed table, ref: (Ref: D. M. W.
96  // Evans, "An improved digit-reversal permutation algorithm ...",
97  // IEEE Trans. ASSP, Aug. 1987, pp. 1120-1125).
98  Real **tab_; // Tables of butterfly coefficients.
99 
100  // Disallow assignment.
102 };
103 
104 template<typename Real>
106  public:
107  SplitRadixRealFft(MatrixIndexT N): // will fail unless N>=4 and N is a power of 2.
108  SplitRadixComplexFft<Real> (N/2), N_(N) { }
109 
110  // Copy constructor
112  SplitRadixComplexFft<Real>(other), N_(other.N_) { }
113 
121  void Compute(Real *x, bool forward);
122 
123 
126  void Compute(Real *x, bool forward, std::vector<Real> *temp_buffer) const;
127 
128  private:
129  // Disallow assignment.
131  int N_;
132 };
133 
134 
136 
137 } // end namespace kaldi
138 
139 
140 #endif
141 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void BitReversePermute(Real *x, Integer logn) const
Definition: srfft.cc:185
void ComputeRecursive(Real *xr, Real *xi, Integer logn) const
Definition: srfft.cc:211
SplitRadixRealFft(MatrixIndexT N)
Definition: srfft.h:107
std::vector< Real > temp_buffer_
Definition: srfft.h:85
MatrixIndexT Integer
Definition: srfft.h:50
int32 MatrixIndexT
Definition: matrix-common.h:98
void Compute(Real *xr, Real *xi, bool forward) const
Definition: srfft.cc:136
SplitRadixComplexFft & operator=(const SplitRadixComplexFft< Real > &other)
SplitRadixRealFft(const SplitRadixRealFft< Real > &other)
Definition: srfft.h:111
SplitRadixComplexFft(Integer N)
Definition: srfft.cc:35