feature-fbank.h
Go to the documentation of this file.
1 // feat/feature-fbank.h
2 
3 // Copyright 2009-2012 Karel Vesely
4 // 2016 Johns Hopkins University (author: 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 #ifndef KALDI_FEAT_FEATURE_FBANK_H_
22 #define KALDI_FEAT_FEATURE_FBANK_H_
23 
24 #include <map>
25 #include <string>
26 
27 #include "feat/feature-common.h"
28 #include "feat/feature-functions.h"
29 #include "feat/feature-window.h"
30 #include "feat/mel-computations.h"
31 
32 namespace kaldi {
35 
36 
41 struct FbankOptions {
44  bool use_energy; // append an extra dimension with energy to the filter banks
46  bool raw_energy; // If true, compute energy before preemphasis and windowing
47  bool htk_compat; // If true, put energy last (if using energy)
48  bool use_log_fbank; // if true (default), produce log-filterbank, else linear
49  bool use_power; // if true (default), use power in filterbank analysis, else magnitude.
50 
51  FbankOptions(): mel_opts(23),
52  // defaults the #mel-banks to 23 for the FBANK computations.
53  // this seems to be common for 16khz-sampled data,
54  // but for 8khz-sampled data, 15 may be better.
55  use_energy(false),
56  energy_floor(0.0),
57  raw_energy(true),
58  htk_compat(false),
59  use_log_fbank(true),
60  use_power(true) {}
61 
62  void Register(OptionsItf *opts) {
63  frame_opts.Register(opts);
64  mel_opts.Register(opts);
65  opts->Register("use-energy", &use_energy,
66  "Add an extra dimension with energy to the FBANK output.");
67  opts->Register("energy-floor", &energy_floor,
68  "Floor on energy (absolute, not relative) in FBANK computation. "
69  "Only makes a difference if --use-energy=true; only necessary if "
70  "--dither=0.0. Suggested values: 0.1 or 1.0");
71  opts->Register("raw-energy", &raw_energy,
72  "If true, compute energy before preemphasis and windowing");
73  opts->Register("htk-compat", &htk_compat, "If true, put energy last. "
74  "Warning: not sufficient to get HTK compatible features (need "
75  "to change other parameters).");
76  opts->Register("use-log-fbank", &use_log_fbank,
77  "If true, produce log-filterbank, else produce linear.");
78  opts->Register("use-power", &use_power,
79  "If true, use power, else use magnitude.");
80  }
81 };
82 
83 
87  public:
89 
90  explicit FbankComputer(const FbankOptions &opts);
91  FbankComputer(const FbankComputer &other);
92 
93  int32 Dim() const {
94  return opts_.mel_opts.num_bins + (opts_.use_energy ? 1 : 0);
95  }
96 
97  bool NeedRawLogEnergy() const { return opts_.use_energy && opts_.raw_energy; }
98 
100  return opts_.frame_opts;
101  }
102 
124  void Compute(BaseFloat signal_raw_log_energy,
125  BaseFloat vtln_warp,
126  VectorBase<BaseFloat> *signal_frame,
127  VectorBase<BaseFloat> *feature);
128 
129  ~FbankComputer();
130 
131  private:
132  const MelBanks *GetMelBanks(BaseFloat vtln_warp);
133 
134 
137  std::map<BaseFloat, MelBanks*> mel_banks_; // BaseFloat is VTLN coefficient.
139  // Disallow assignment.
140  FbankComputer &operator =(const FbankComputer &other);
141 };
142 
144 
146 } // namespace kaldi
147 
148 
149 #endif // KALDI_FEAT_FEATURE_FBANK_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
FbankOptions Options
Definition: feature-fbank.h:88
void Register(OptionsItf *opts)
Definition: feature-fbank.h:62
void Register(OptionsItf *opts)
kaldi::int32 int32
virtual void Register(const std::string &name, bool *ptr, const std::string &doc)=0
FrameExtractionOptions frame_opts
Definition: feature-fbank.h:42
bool NeedRawLogEnergy() const
Definition: feature-fbank.h:97
Class for computing mel-filterbank features; see Computing MFCC features for more information...
Definition: feature-fbank.h:86
OfflineFeatureTpl< FbankComputer > Fbank
BaseFloat energy_floor
Definition: feature-fbank.h:45
void Register(OptionsItf *opts)
int32 Dim() const
Definition: feature-fbank.h:93
SplitRadixRealFft< BaseFloat > * srfft_
BaseFloat log_energy_floor_
MelBanksOptions mel_opts
Definition: feature-fbank.h:43
This templated class is intended for offline feature extraction, i.e.
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
const FrameExtractionOptions & GetFrameOptions() const
Definition: feature-fbank.h:99
FbankOptions contains basic options for computing filterbank features.
Definition: feature-fbank.h:41
std::map< BaseFloat, MelBanks * > mel_banks_