feature-plp.h
Go to the documentation of this file.
1 // feat/feature-plp.h
2 
3 // Copyright 2009-2011 Petr Motlicek; Karel Vesely
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_FEAT_FEATURE_PLP_H_
21 #define KALDI_FEAT_FEATURE_PLP_H_
22 
23 #include <map>
24 #include <string>
25 
26 #include "feat/feature-common.h"
27 #include "feat/feature-functions.h"
28 #include "feat/feature-window.h"
29 #include "feat/mel-computations.h"
30 #include "itf/options-itf.h"
31 
32 namespace kaldi {
35 
36 
37 
42 struct PlpOptions {
46  int32 num_ceps; // num cepstra including zero
47  bool use_energy; // use energy; else C0
49  bool raw_energy; // If true, compute energy before preemphasis and windowing
53 
54  bool htk_compat; // if true, put energy/C0 last and introduce a factor of
55  // sqrt(2) on C0 to be the same as HTK.
56 
57  PlpOptions() : mel_opts(23),
58  // default number of mel-banks for the PLP computation; this
59  // seems to be common for 16kHz-sampled data. For 8kHz-sampled
60  // data, 15 may be better.
61  lpc_order(12),
62  num_ceps(13),
63  use_energy(true),
64  energy_floor(0.0),
65  raw_energy(true),
66  compress_factor(0.33333),
67  cepstral_lifter(22),
68  cepstral_scale(1.0),
69  htk_compat(false) {}
70 
71  void Register(OptionsItf *opts) {
72  frame_opts.Register(opts);
73  mel_opts.Register(opts);
74  opts->Register("lpc-order", &lpc_order,
75  "Order of LPC analysis in PLP computation");
76  opts->Register("num-ceps", &num_ceps,
77  "Number of cepstra in PLP computation (including C0)");
78  opts->Register("use-energy", &use_energy,
79  "Use energy (not C0) for zeroth PLP feature");
80  opts->Register("energy-floor", &energy_floor,
81  "Floor on energy (absolute, not relative) in PLP computation. "
82  "Only makes a difference if --use-energy=true; only necessary if "
83  "--dither=0.0. Suggested values: 0.1 or 1.0");
84  opts->Register("raw-energy", &raw_energy,
85  "If true, compute energy before preemphasis and windowing");
86  opts->Register("compress-factor", &compress_factor,
87  "Compression factor in PLP computation");
88  opts->Register("cepstral-lifter", &cepstral_lifter,
89  "Constant that controls scaling of PLPs");
90  opts->Register("cepstral-scale", &cepstral_scale,
91  "Scaling constant in PLP computation");
92  opts->Register("htk-compat", &htk_compat,
93  "If true, put energy or C0 last. Warning: not sufficient "
94  "to get HTK compatible features (need to change other "
95  "parameters).");
96  }
97 };
98 
99 
101 class PlpComputer {
102  public:
104  explicit PlpComputer(const PlpOptions &opts);
105  PlpComputer(const PlpComputer &other);
106 
108  return opts_.frame_opts;
109  }
110 
111  int32 Dim() const { return opts_.num_ceps; }
112 
113  bool NeedRawLogEnergy() const { return opts_.use_energy && opts_.raw_energy; }
114 
136  void Compute(BaseFloat signal_raw_log_energy,
137  BaseFloat vtln_warp,
138  VectorBase<BaseFloat> *signal_frame,
139  VectorBase<BaseFloat> *feature);
140 
141  ~PlpComputer();
142  private:
143 
144  const MelBanks *GetMelBanks(BaseFloat vtln_warp);
145 
146  const Vector<BaseFloat> *GetEqualLoudness(BaseFloat vtln_warp);
147 
152  std::map<BaseFloat, MelBanks*> mel_banks_; // BaseFloat is VTLN coefficient.
153  std::map<BaseFloat, Vector<BaseFloat>* > equal_loudness_;
155 
156  // temporary vector used inside Compute; size is opts_.mel_opts.num_bins + 2
158  // temporary vector used inside Compute; size is opts_.lpc_order + 1
160  // temporary vector used inside Compute; size is opts_.lpc_order
162  // temporary vector used inside Compute; size is opts_.lpc_order
164 
165  // Disallow assignment.
166  PlpComputer &operator =(const PlpComputer &other);
167 };
168 
170 
172 
173 } // namespace kaldi
174 
175 
176 #endif // KALDI_FEAT_FEATURE_PLP_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
BaseFloat compress_factor
Definition: feature-plp.h:50
int32 Dim() const
Definition: feature-plp.h:111
void Register(OptionsItf *opts)
BaseFloat log_energy_floor_
Definition: feature-plp.h:151
PlpOptions Options
Definition: feature-plp.h:103
Vector< BaseFloat > mel_energies_duplicated_
Definition: feature-plp.h:157
This is the new-style interface to the PLP computation.
Definition: feature-plp.h:101
OfflineFeatureTpl< PlpComputer > Plp
Definition: feature-plp.h:169
Vector< BaseFloat > lifter_coeffs_
Definition: feature-plp.h:149
Vector< BaseFloat > lpc_coeffs_
Definition: feature-plp.h:161
kaldi::int32 int32
MelBanksOptions mel_opts
Definition: feature-plp.h:44
virtual void Register(const std::string &name, bool *ptr, const std::string &doc)=0
Vector< BaseFloat > autocorr_coeffs_
Definition: feature-plp.h:159
PlpOptions opts_
Definition: feature-plp.h:148
Matrix< BaseFloat > idft_bases_
Definition: feature-plp.h:150
const FrameExtractionOptions & GetFrameOptions() const
Definition: feature-plp.h:107
bool NeedRawLogEnergy() const
Definition: feature-plp.h:113
FrameExtractionOptions frame_opts
Definition: feature-plp.h:43
void Register(OptionsItf *opts)
Definition: feature-plp.h:71
BaseFloat energy_floor
Definition: feature-plp.h:48
std::map< BaseFloat, Vector< BaseFloat > *> equal_loudness_
Definition: feature-plp.h:153
BaseFloat cepstral_scale
Definition: feature-plp.h:52
void Register(OptionsItf *opts)
A class representing a vector.
Definition: kaldi-vector.h:406
Vector< BaseFloat > raw_cepstrum_
Definition: feature-plp.h:163
PlpOptions contains basic options for computing PLP features.
Definition: feature-plp.h:42
This templated class is intended for offline feature extraction, i.e.
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
SplitRadixRealFft< BaseFloat > * srfft_
Definition: feature-plp.h:154
std::map< BaseFloat, MelBanks * > mel_banks_
Definition: feature-plp.h:152