feature-spectrogram.h
Go to the documentation of this file.
1 // feat/feature-spectrogram.h
2 
3 // Copyright 2009-2012 Karel Vesely
4 // Copyright 2012 Navdeep Jaitly
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_SPECTROGRAM_H_
22 #define KALDI_FEAT_FEATURE_SPECTROGRAM_H_
23 
24 
25 #include <string>
26 
27 #include "feat/feature-common.h"
28 #include "feat/feature-functions.h"
29 #include "feat/feature-window.h"
30 
31 namespace kaldi {
34 
35 
41  bool raw_energy; // If true, compute energy before preemphasis and windowing
42  bool return_raw_fft; // If true, return the raw FFT spectrum
43  // Note that in that case the Dim() will return double
44  // the expected dimension (because of the complex domain of it)
45 
47  energy_floor(0.0),
48  raw_energy(true),
49  return_raw_fft(false) {}
50 
51  void Register(OptionsItf *opts) {
52  frame_opts.Register(opts);
53  opts->Register("energy-floor", &energy_floor,
54  "Floor on energy (absolute, not relative) in Spectrogram "
55  "computation. Caution: this floor is applied to the zeroth "
56  "component, representing the total signal energy. The "
57  "floor on the individual spectrogram elements is fixed at "
58  "std::numeric_limits<float>::epsilon().");
59  opts->Register("raw-energy", &raw_energy,
60  "If true, compute energy before preemphasis and windowing");
61  opts->Register("return-raw-fft", &return_raw_fft,
62  "If true, return raw FFT complex numbers instead of log magnitudes");
63  }
64 };
65 
68  public:
70  explicit SpectrogramComputer(const SpectrogramOptions &opts);
72 
74  return opts_.frame_opts;
75  }
76 
77  int32 Dim() const {
78  if (opts_.return_raw_fft) {
79  return opts_.frame_opts.PaddedWindowSize();
80  } else {
81  return opts_.frame_opts.PaddedWindowSize() / 2 + 1;
82  }
83  }
84 
85  bool NeedRawLogEnergy() const { return opts_.raw_energy; }
86 
87 
106  void Compute(BaseFloat signal_raw_log_energy,
107  BaseFloat vtln_warp,
108  VectorBase<BaseFloat> *signal_frame,
109  VectorBase<BaseFloat> *feature);
110 
112 
113  private:
117 
118  // Disallow assignment.
119  SpectrogramComputer &operator=(const SpectrogramComputer &other);
120 };
121 
123 
124 
126 } // namespace kaldi
127 
128 
129 #endif // KALDI_FEAT_FEATURE_SPECTROGRAM_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Class for computing spectrogram features.
kaldi::int32 int32
void Register(OptionsItf *opts)
virtual void Register(const std::string &name, bool *ptr, const std::string &doc)=0
void Register(OptionsItf *opts)
SplitRadixRealFft< BaseFloat > * srfft_
This templated class is intended for offline feature extraction, i.e.
SpectrogramOptions contains basic options for computing spectrogram features.
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
const FrameExtractionOptions & GetFrameOptions() const
FrameExtractionOptions frame_opts
OfflineFeatureTpl< SpectrogramComputer > Spectrogram