PlpComputer Class Reference

This is the new-style interface to the PLP computation. More...

#include <feature-plp.h>

Collaboration diagram for PlpComputer:

Public Types

typedef PlpOptions Options
 

Public Member Functions

 PlpComputer (const PlpOptions &opts)
 
 PlpComputer (const PlpComputer &other)
 
const FrameExtractionOptionsGetFrameOptions () const
 
int32 Dim () const
 
bool NeedRawLogEnergy () const
 
void Compute (BaseFloat signal_raw_log_energy, BaseFloat vtln_warp, VectorBase< BaseFloat > *signal_frame, VectorBase< BaseFloat > *feature)
 Function that computes one frame of features from one frame of signal. More...
 
 ~PlpComputer ()
 

Private Member Functions

const MelBanksGetMelBanks (BaseFloat vtln_warp)
 
const Vector< BaseFloat > * GetEqualLoudness (BaseFloat vtln_warp)
 
PlpComputeroperator= (const PlpComputer &other)
 

Private Attributes

PlpOptions opts_
 
Vector< BaseFloatlifter_coeffs_
 
Matrix< BaseFloatidft_bases_
 
BaseFloat log_energy_floor_
 
std::map< BaseFloat, MelBanks * > mel_banks_
 
std::map< BaseFloat, Vector< BaseFloat > *> equal_loudness_
 
SplitRadixRealFft< BaseFloat > * srfft_
 
Vector< BaseFloatmel_energies_duplicated_
 
Vector< BaseFloatautocorr_coeffs_
 
Vector< BaseFloatlpc_coeffs_
 
Vector< BaseFloatraw_cepstrum_
 

Detailed Description

This is the new-style interface to the PLP computation.

Definition at line 101 of file feature-plp.h.

Member Typedef Documentation

◆ Options

Definition at line 103 of file feature-plp.h.

Constructor & Destructor Documentation

◆ PlpComputer() [1/2]

PlpComputer ( const PlpOptions opts)
explicit

Definition at line 26 of file feature-plp.cc.

References PlpOptions::cepstral_lifter, kaldi::ComputeLifterCoeffs(), PlpOptions::energy_floor, PlpOptions::frame_opts, PlpComputer::GetMelBanks(), PlpComputer::idft_bases_, kaldi::InitIdftBases(), PlpComputer::lifter_coeffs_, kaldi::Log(), PlpComputer::log_energy_floor_, PlpOptions::lpc_order, PlpOptions::mel_opts, MelBanksOptions::num_bins, PlpOptions::num_ceps, PlpComputer::opts_, FrameExtractionOptions::PaddedWindowSize(), and PlpComputer::srfft_.

26  :
27  opts_(opts), srfft_(NULL),
32 
33  if (opts.cepstral_lifter != 0.0) {
34  lifter_coeffs_.Resize(opts.num_ceps);
35  ComputeLifterCoeffs(opts.cepstral_lifter, &lifter_coeffs_);
36  }
38  &idft_bases_);
39 
40  if (opts.energy_floor > 0.0)
41  log_energy_floor_ = Log(opts.energy_floor);
42 
43  int32 padded_window_size = opts.frame_opts.PaddedWindowSize();
44  if ((padded_window_size & (padded_window_size-1)) == 0) // Is a power of two...
45  srfft_ = new SplitRadixRealFft<BaseFloat>(padded_window_size);
46 
47  // We'll definitely need the filterbanks info for VTLN warping factor 1.0.
48  // [note: this call caches it.]
49  GetMelBanks(1.0);
50 }
BaseFloat log_energy_floor_
Definition: feature-plp.h:151
Vector< BaseFloat > mel_energies_duplicated_
Definition: feature-plp.h:157
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
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
double Log(double x)
Definition: kaldi-math.h:100
void ComputeLifterCoeffs(BaseFloat Q, VectorBase< BaseFloat > *coeffs)
void InitIdftBases(int32 n_bases, int32 dimension, Matrix< BaseFloat > *mat_out)
const MelBanks * GetMelBanks(BaseFloat vtln_warp)
Definition: feature-plp.cc:83
Vector< BaseFloat > raw_cepstrum_
Definition: feature-plp.h:163
SplitRadixRealFft< BaseFloat > * srfft_
Definition: feature-plp.h:154

◆ PlpComputer() [2/2]

PlpComputer ( const PlpComputer other)

Definition at line 52 of file feature-plp.cc.

References PlpComputer::equal_loudness_, PlpComputer::mel_banks_, and PlpComputer::srfft_.

52  :
53  opts_(other.opts_), lifter_coeffs_(other.lifter_coeffs_),
54  idft_bases_(other.idft_bases_), log_energy_floor_(other.log_energy_floor_),
55  mel_banks_(other.mel_banks_), equal_loudness_(other.equal_loudness_),
56  srfft_(NULL),
61  for (std::map<BaseFloat, MelBanks*>::iterator iter = mel_banks_.begin();
62  iter != mel_banks_.end(); ++iter)
63  iter->second = new MelBanks(*(iter->second));
64  for (std::map<BaseFloat, Vector<BaseFloat>*>::iterator
65  iter = equal_loudness_.begin();
66  iter != equal_loudness_.end(); ++iter)
67  iter->second = new Vector<BaseFloat>(*(iter->second));
68  if (other.srfft_ != NULL)
69  srfft_ = new SplitRadixRealFft<BaseFloat>(*(other.srfft_));
70 }
BaseFloat log_energy_floor_
Definition: feature-plp.h:151
Vector< BaseFloat > mel_energies_duplicated_
Definition: feature-plp.h:157
Vector< BaseFloat > lifter_coeffs_
Definition: feature-plp.h:149
Vector< BaseFloat > lpc_coeffs_
Definition: feature-plp.h:161
MelBanksOptions mel_opts
Definition: feature-plp.h:44
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
float BaseFloat
Definition: kaldi-types.h:29
std::map< BaseFloat, Vector< BaseFloat > *> equal_loudness_
Definition: feature-plp.h:153
Vector< BaseFloat > raw_cepstrum_
Definition: feature-plp.h:163
SplitRadixRealFft< BaseFloat > * srfft_
Definition: feature-plp.h:154
std::map< BaseFloat, MelBanks * > mel_banks_
Definition: feature-plp.h:152

◆ ~PlpComputer()

Definition at line 72 of file feature-plp.cc.

References PlpComputer::equal_loudness_, PlpComputer::mel_banks_, and PlpComputer::srfft_.

72  {
73  for (std::map<BaseFloat, MelBanks*>::iterator iter = mel_banks_.begin();
74  iter != mel_banks_.end(); ++iter)
75  delete iter->second;
76  for (std::map<BaseFloat, Vector<BaseFloat>* >::iterator
77  iter = equal_loudness_.begin();
78  iter != equal_loudness_.end(); ++iter)
79  delete iter->second;
80  delete srfft_;
81 }
float BaseFloat
Definition: kaldi-types.h:29
std::map< BaseFloat, Vector< BaseFloat > *> equal_loudness_
Definition: feature-plp.h:153
SplitRadixRealFft< BaseFloat > * srfft_
Definition: feature-plp.h:154
std::map< BaseFloat, MelBanks * > mel_banks_
Definition: feature-plp.h:152

Member Function Documentation

◆ Compute()

void Compute ( BaseFloat  signal_raw_log_energy,
BaseFloat  vtln_warp,
VectorBase< BaseFloat > *  signal_frame,
VectorBase< BaseFloat > *  feature 
)

Function that computes one frame of features from one frame of signal.

Parameters
[in]signal_raw_log_energyThe log-energy of the frame of the signal prior to windowing and pre-emphasis, or log(numeric_limits<float>::min()), whichever is greater. Must be ignored by this function if this class returns false from this->NeedsRawLogEnergy().
[in]vtln_warpThe VTLN warping factor that the user wants to be applied when computing features for this utterance. Will normally be 1.0, meaning no warping is to be done. The value will be ignored for feature types that don't support VLTN, such as spectrogram features.
[in]signal_frameOne frame of the signal, as extracted using the function ExtractWindow() using the options returned by this->GetFrameOptions(). The function will use the vector as a workspace, which is why it's a non-const pointer.
[out]featurePointer to a vector of size this->Dim(), to which the computed feature will be written.

Definition at line 112 of file feature-plp.cc.

References VectorBase< Real >::ApplyPow(), PlpComputer::autocorr_coeffs_, PlpOptions::cepstral_lifter, PlpOptions::cepstral_scale, PlpOptions::compress_factor, kaldi::ComputeLpc(), kaldi::ComputePowerSpectrum(), VectorBase< Real >::Data(), VectorBase< Real >::Dim(), PlpComputer::Dim(), PlpOptions::energy_floor, PlpOptions::frame_opts, PlpComputer::GetEqualLoudness(), PlpComputer::GetMelBanks(), PlpOptions::htk_compat, rnnlm::i, PlpComputer::idft_bases_, KALDI_ASSERT, kaldi::kNoTrans, PlpComputer::lifter_coeffs_, kaldi::Log(), PlpComputer::log_energy_floor_, kaldi::Lpc2Cepstrum(), PlpComputer::lpc_coeffs_, PlpOptions::lpc_order, PlpComputer::mel_energies_duplicated_, PlpOptions::mel_opts, VectorBase< Real >::MulElements(), MelBanksOptions::num_bins, PlpOptions::num_ceps, PlpComputer::opts_, FrameExtractionOptions::PaddedWindowSize(), VectorBase< Real >::Range(), PlpComputer::raw_cepstrum_, PlpOptions::raw_energy, kaldi::RealFft(), VectorBase< Real >::Scale(), PlpComputer::srfft_, PlpOptions::use_energy, and kaldi::VecVec().

115  {
116  KALDI_ASSERT(signal_frame->Dim() == opts_.frame_opts.PaddedWindowSize() &&
117  feature->Dim() == this->Dim());
118 
119  const MelBanks &mel_banks = *GetMelBanks(vtln_warp);
120  const Vector<BaseFloat> &equal_loudness = *GetEqualLoudness(vtln_warp);
121 
122 
123  KALDI_ASSERT(opts_.num_ceps <= opts_.lpc_order+1); // our num-ceps includes C0.
124 
125 
127  signal_raw_log_energy = Log(std::max<BaseFloat>(VecVec(*signal_frame, *signal_frame),
128  std::numeric_limits<float>::min()));
129 
130  if (srfft_ != NULL) // Compute FFT using split-radix algorithm.
131  srfft_->Compute(signal_frame->Data(), true);
132  else // An alternative algorithm that works for non-powers-of-two.
133  RealFft(signal_frame, true);
134 
135  // Convert the FFT into a power spectrum.
136  ComputePowerSpectrum(signal_frame); // elements 0 ... signal_frame->Dim()/2
137 
138  SubVector<BaseFloat> power_spectrum(*signal_frame,
139  0, signal_frame->Dim() / 2 + 1);
140 
141  int32 num_mel_bins = opts_.mel_opts.num_bins;
142 
143  SubVector<BaseFloat> mel_energies(mel_energies_duplicated_, 1, num_mel_bins);
144 
145  mel_banks.Compute(power_spectrum, &mel_energies);
146 
147  mel_energies.MulElements(equal_loudness);
148 
149  mel_energies.ApplyPow(opts_.compress_factor);
150 
151  // duplicate first and last elements
153  mel_energies_duplicated_(num_mel_bins + 1) =
154  mel_energies_duplicated_(num_mel_bins);
155 
156  autocorr_coeffs_.SetZero(); // In case of NaNs or infs
157  autocorr_coeffs_.AddMatVec(1.0, idft_bases_, kNoTrans,
159 
160  BaseFloat residual_log_energy = ComputeLpc(autocorr_coeffs_, &lpc_coeffs_);
161 
162  residual_log_energy = std::max<BaseFloat>(residual_log_energy,
163  std::numeric_limits<float>::min());
164 
166  feature->Range(1, opts_.num_ceps - 1).CopyFromVec(
167  raw_cepstrum_.Range(0, opts_.num_ceps - 1));
168  (*feature)(0) = residual_log_energy;
169 
170  if (opts_.cepstral_lifter != 0.0)
171  feature->MulElements(lifter_coeffs_);
172 
173  if (opts_.cepstral_scale != 1.0)
174  feature->Scale(opts_.cepstral_scale);
175 
176  if (opts_.use_energy) {
177  if (opts_.energy_floor > 0.0 && signal_raw_log_energy < log_energy_floor_)
178  signal_raw_log_energy = log_energy_floor_;
179  (*feature)(0) = signal_raw_log_energy;
180  }
181 
182  if (opts_.htk_compat) { // reorder the features.
183  BaseFloat log_energy = (*feature)(0);
184  for (int32 i = 0; i < opts_.num_ceps-1; i++)
185  (*feature)(i) = (*feature)(i+1);
186  (*feature)(opts_.num_ceps-1) = log_energy;
187  }
188 }
BaseFloat compress_factor
Definition: feature-plp.h:50
int32 Dim() const
Definition: feature-plp.h:111
BaseFloat log_energy_floor_
Definition: feature-plp.h:151
void Lpc2Cepstrum(int n, const BaseFloat *pLPC, BaseFloat *pCepst)
Vector< BaseFloat > mel_energies_duplicated_
Definition: feature-plp.h:157
const Vector< BaseFloat > * GetEqualLoudness(BaseFloat vtln_warp)
Definition: feature-plp.cc:97
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
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
float BaseFloat
Definition: kaldi-types.h:29
double Log(double x)
Definition: kaldi-math.h:100
FrameExtractionOptions frame_opts
Definition: feature-plp.h:43
BaseFloat energy_floor
Definition: feature-plp.h:48
BaseFloat ComputeLpc(const VectorBase< BaseFloat > &autocorr_in, Vector< BaseFloat > *lpc_out)
BaseFloat cepstral_scale
Definition: feature-plp.h:52
void ComputePowerSpectrum(VectorBase< BaseFloat > *waveform)
const MelBanks * GetMelBanks(BaseFloat vtln_warp)
Definition: feature-plp.cc:83
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
Vector< BaseFloat > raw_cepstrum_
Definition: feature-plp.h:163
SplitRadixRealFft< BaseFloat > * srfft_
Definition: feature-plp.h:154
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Definition: kaldi-vector.cc:37
void RealFft(VectorBase< Real > *v, bool forward)
RealFft is a fourier transform of real inputs.

◆ Dim()

int32 Dim ( ) const
inline

Definition at line 111 of file feature-plp.h.

Referenced by PlpComputer::Compute().

111 { return opts_.num_ceps; }
PlpOptions opts_
Definition: feature-plp.h:148

◆ GetEqualLoudness()

const Vector< BaseFloat > * GetEqualLoudness ( BaseFloat  vtln_warp)
private

Definition at line 97 of file feature-plp.cc.

References PlpComputer::equal_loudness_, kaldi::GetEqualLoudnessVector(), and PlpComputer::GetMelBanks().

Referenced by PlpComputer::Compute().

97  {
98  const MelBanks *this_mel_banks = GetMelBanks(vtln_warp);
99  Vector<BaseFloat> *ans = NULL;
100  std::map<BaseFloat, Vector<BaseFloat>*>::iterator iter
101  = equal_loudness_.find(vtln_warp);
102  if (iter == equal_loudness_.end()) {
103  ans = new Vector<BaseFloat>;
104  GetEqualLoudnessVector(*this_mel_banks, ans);
105  equal_loudness_[vtln_warp] = ans;
106  } else {
107  ans = iter->second;
108  }
109  return ans;
110 }
std::map< BaseFloat, Vector< BaseFloat > *> equal_loudness_
Definition: feature-plp.h:153
const MelBanks * GetMelBanks(BaseFloat vtln_warp)
Definition: feature-plp.cc:83
void GetEqualLoudnessVector(const MelBanks &mel_banks, Vector< BaseFloat > *ans)

◆ GetFrameOptions()

const FrameExtractionOptions& GetFrameOptions ( ) const
inline

Definition at line 107 of file feature-plp.h.

107  {
108  return opts_.frame_opts;
109  }
PlpOptions opts_
Definition: feature-plp.h:148
FrameExtractionOptions frame_opts
Definition: feature-plp.h:43

◆ GetMelBanks()

const MelBanks * GetMelBanks ( BaseFloat  vtln_warp)
private

Definition at line 83 of file feature-plp.cc.

References PlpOptions::frame_opts, PlpComputer::mel_banks_, PlpOptions::mel_opts, and PlpComputer::opts_.

Referenced by PlpComputer::Compute(), PlpComputer::GetEqualLoudness(), and PlpComputer::PlpComputer().

83  {
84  MelBanks *this_mel_banks = NULL;
85  std::map<BaseFloat, MelBanks*>::iterator iter = mel_banks_.find(vtln_warp);
86  if (iter == mel_banks_.end()) {
87  this_mel_banks = new MelBanks(opts_.mel_opts,
89  vtln_warp);
90  mel_banks_[vtln_warp] = this_mel_banks;
91  } else {
92  this_mel_banks = iter->second;
93  }
94  return this_mel_banks;
95 }
MelBanksOptions mel_opts
Definition: feature-plp.h:44
PlpOptions opts_
Definition: feature-plp.h:148
FrameExtractionOptions frame_opts
Definition: feature-plp.h:43
std::map< BaseFloat, MelBanks * > mel_banks_
Definition: feature-plp.h:152

◆ NeedRawLogEnergy()

bool NeedRawLogEnergy ( ) const
inline

Definition at line 113 of file feature-plp.h.

113 { return opts_.use_energy && opts_.raw_energy; }
PlpOptions opts_
Definition: feature-plp.h:148

◆ operator=()

PlpComputer& operator= ( const PlpComputer other)
private

Member Data Documentation

◆ autocorr_coeffs_

Vector<BaseFloat> autocorr_coeffs_
private

Definition at line 159 of file feature-plp.h.

Referenced by PlpComputer::Compute().

◆ equal_loudness_

std::map<BaseFloat, Vector<BaseFloat>* > equal_loudness_
private

◆ idft_bases_

Matrix<BaseFloat> idft_bases_
private

Definition at line 150 of file feature-plp.h.

Referenced by PlpComputer::Compute(), and PlpComputer::PlpComputer().

◆ lifter_coeffs_

Vector<BaseFloat> lifter_coeffs_
private

Definition at line 149 of file feature-plp.h.

Referenced by PlpComputer::Compute(), and PlpComputer::PlpComputer().

◆ log_energy_floor_

BaseFloat log_energy_floor_
private

Definition at line 151 of file feature-plp.h.

Referenced by PlpComputer::Compute(), and PlpComputer::PlpComputer().

◆ lpc_coeffs_

Vector<BaseFloat> lpc_coeffs_
private

Definition at line 161 of file feature-plp.h.

Referenced by PlpComputer::Compute().

◆ mel_banks_

std::map<BaseFloat, MelBanks*> mel_banks_
private

◆ mel_energies_duplicated_

Vector<BaseFloat> mel_energies_duplicated_
private

Definition at line 157 of file feature-plp.h.

Referenced by PlpComputer::Compute().

◆ opts_

PlpOptions opts_
private

◆ raw_cepstrum_

Vector<BaseFloat> raw_cepstrum_
private

Definition at line 163 of file feature-plp.h.

Referenced by PlpComputer::Compute().

◆ srfft_


The documentation for this class was generated from the following files: