Edinburgh Speech Tools  2.1-release
EST_sigpr_frame.h
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1995,1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 
34 #ifndef __EST_SIGPR_FRAME_H__
35 #define __EST_SIGPR_FRAME_H__
36 
37 #include "EST_FMatrix.h"
38 
39 /** @defgroup FunctionsForGeneratingFrames Functions for Generating Frames
40 
41 */
42 
43 /**@defgroup LinearPredictionfunctions Linear Prediction functions
44  @brief Including, generation of coefficients from the signal, reflection
45 coefficients, line spectral frequencies, areas.
46  @ingroup FunctionsForGeneratingFrames
47  @{
48  \fn void sig2lpc(const EST_FVector &sig, EST_FVector &acf, EST_FVector &ref, EST_FVector &lpc)
49  \fn void lpc2cep(const EST_FVector &lpc, EST_FVector &cep)
50  \fn void sig2lpc(const EST_FVector &sig, EST_FVector &lpc)
51  \fn void sig2ref(const EST_FVector &sig, EST_FVector &ref)
52  @}
53  */
54 
55 
56 /** Produce the full set of linear prediction coefficients from a
57  frame of speech waveform.
58 
59  @param sig: the frame of input waveform
60  @param acf: the autocorrelation coefficients
61  @param ref: the reflection coefficients
62  @param lpc: the LPC coefficients
63 
64 The order of the lpc analysis is given as the size of the
65 `lpc` vector - 1. The coefficients are placed in the
66 locations `1 - size`, and the energy is placed in location `0`.
67 */
68 void sig2lpc(const EST_FVector &sig, EST_FVector &acf,
69  EST_FVector &ref, EST_FVector &lpc);
70 
71 
72 /** Calculate cepstral coefficients from lpc coefficients.
73 
74 It is possible to calculate a set of cepstral coefficients from
75 lpc coefficients using the relationship:
76 
77 \f[c_{k}= a_{k} + \frac{1}{k}\sum_{i=1}^{k-1} i c_{i} a_{k-1}\f]
78 
79 The order of the cepstral analysis can be different from the lpc
80 order. If the cepstral order is greater, interpolation is used (FINISH
81 add equation). Both orders are taken from the lengths of the
82 respective vectors. Note that these cepstral coefficients take on the
83 assumptions (and errors) of the lpc model and hence will not be the
84 same as cepstral coefficients calculated using DFT functions.
85 
86  @param lpc: the LPC coefficients (input)
87  @param lpc: the cepstral coefficients (output)
88 */
89 void lpc2cep(const EST_FVector &lpc, EST_FVector &cep);
90 
91 
92 
93 /** Produce a set linear prediction coefficients from a
94  frame of speech waveform. `sig` is the frame of input waveform,
95  and `lpc` are the LPC coefficients. The
96  **order** of the lpc analysis is given as the size of the `lpc`
97  vector -1. The coefficients are placed in the locations 1 - size, and
98  the energy is placed in location 0.
99 */
100 void sig2lpc(const EST_FVector &sig, EST_FVector &lpc);
101 
102 /** Produce a set of reflection coefficients from a
103  frame of speech waveform. `sig` is the frame of input waveform,
104  and `ref` are the LPC coefficients. The
105  **order** of the lpc analysis is given as the size of the **lpc**
106  vector -1. The coefficients are placed in the locations 1 - size, and
107  the energy is placed in location 0.
108 */
109 void sig2ref(const EST_FVector &sig, EST_FVector &ref);
110 
111 
112 /**@defgroup AreaFunctions Area Functions
113  @ingroup LinearPredictionfunctions
114  @details Using the analogy of the lossless tube, the cross-sectional
115  areas of the sections of this tube are related to the reflection
116  coefficients and can be calculated from the following relationship:
117 
118  \f[\frac{A_{i+1}}{A_{i}} = \frac{i - k_{i}}{1 + k_{i}} \f]
119 
120  @{
121 */
122 /** The area according to the formula. */
123 void ref2truearea(const EST_FVector &ref, EST_FVector &area);
124 
125 /** An approximation of the area is calculate by skipping the denominator
126 in the formula. */
127 void ref2area(const EST_FVector &ref, EST_FVector &area);
128 
129 /** The logs of the areas. */
130 void ref2logarea(const EST_FVector &ref, EST_FVector &logarea);
131 ///@}
132 
133 /** \addtogroup LinearPredictionfunctions
134  @{
135 */
136 
137 /** Calculate the reflection coefficients from the lpc
138 coefficients. Note that in the standard linear prediction analysis,
139 the reflection coefficients are generated as a by-product. @see
140 sig2lpc */
141 void lpc2ref(const EST_FVector &lpc, EST_FVector &ref);
142 
143 /** Calculate the linear prediction coefficients from the reflection
144 coefficients.
145 Use the equation:
146 \f[power=\frac{1}{n}\sum_{i=1}^{n}a_{i}^2\f]
147 
148 @see lpc2ref*/
149 void ref2lpc(const EST_FVector &ref, EST_FVector &lpc);
150 
151 /** Calculate line spectral frequencies from linear prediction coefficients.
152 Use the equation:
153 \f[power=\frac{1}{n}\sum_{i=1}^{n}a_{i}^2\f]
154 
155 @see lsf2lpc
156 */
157 void lpc2lsf(const EST_FVector &lpc, EST_FVector &lsf);
158 
159 /** Calculate line spectral frequencies from linear prediction coefficients.
160 Use the equation:
161 \f[power=\frac{1}{n}\sum_{i=1}^{n}a_{i}^2\f]
162 
163 @see lpc2lsf
164 */
165 void lsf2lpc(const EST_FVector &lsf, EST_FVector &lpc);
166 ///@}
167 
168 void frame_convert(const EST_FVector &in_frame, const EST_String &in_type,
169  EST_FVector &out_frame, const EST_String &out_type);
170 
171 // end of lpc functions
172 
173 /**@defgroup Energyandpowerframefunctions Energy and power frame functions
174  @ingroup FunctionsForGeneratingFrames
175 */
176 ///@{
177 
178 /** Calculate the power for a frame of speech. This is defined as
179 \f[power=\frac{1}{n}\sum_{i=1}^{n}a_{i}^2\f]
180 */
181 void sig2pow(EST_FVector &frame, float &power);
182 
183 /** Calculate the root mean square energy for a frame of speech. This
184 is defined as \f[energy=\sqrt{\frac{1}{n}\sum_{i=1}^{n}a_{i}^2}\f] */
185 void sig2rms(EST_FVector &frame, float &rms_energy);
186 
187 ///@}
188 // end of power and energy
189 
190 /**@defgroup Framebasedfilterbankandcepstralanalysis Frame based filter bank and cepstral analysis
191  @ingroup FunctionsForGeneratingFrames
192 */
193 
194 ///@{
195 
196 /** Calculate the (log) energy (or power) in each channel of a Mel
197 scale filter bank for a frame of speech. The filters are triangular, are
198 evenly spaced and are all of equal width, on a Mel scale. The upper and lower
199 cutoffs of each filter are at the centre frequencies of the adjacent filters.
200 The Mel scale is described under `Hz2Mel`.
201 
202 @see Hz2Mel
203 @see sig2fft
204 @see fft2fbank
205 */
206 void sig2fbank(const EST_FVector &sig,
207  EST_FVector &fbank_frame,
208  const float sample_rate,
209  const bool use_power_rather_than_energy,
210  const bool take_log);
211 
212 /** Calculate the energy (or power) spectrum of a frame of speech. The FFT
213 order is determined by the number of samples in the frame of speech, and is
214 a power of 2. Note that the FFT vector returned corresponds to frequencies
215 from 0 to half the sample rate. Energy is the magnitude of the FFT; power is
216 the squared magnitude.
217 
218 @see fft2fbank
219 @see sig2fbank
220 */
221 void sig2fft(const EST_FVector &sig,
222  EST_FVector &fft_vec,
223  const bool use_power_rather_than_energy);
224 
225 /** Given a Mel filter bank description, bin the FFT coefficients
226 to compute the output of the filters. The first and last elements of
227 `mel_fbank_frequencies` define the lower and upper bound of
228 the first and last filters respectively and the intervening elements
229 give the filter centre frequencies. That is, `mel_fbank_frequencies` has
230 two more elements than `fbank_vec`.
231 
232 @see fastFFT
233 @see sig2fft
234 @see sig2fbank
235 @see fbank2melcep
236 */
237 void fft2fbank(const EST_FVector &fft_frame,
238  EST_FVector &fbank_vec,
239  const float Hz_per_fft_coeff,
240  const EST_FVector &mel_fbank_frequencies);
241 
242 /** Compute the discrete cosine transform of log Mel-scale filter bank output
243 to get the Mel cepstral coefficients for a frame of speech.
244 Optional liftering (filtering in the cepstral domain) can be applied to
245 normalise the magnitudes of the coefficients. This is useful because,
246 typically, the higher order cepstral coefficients are significantly
247 smaller than the lower ones and it is often desirable to normalise
248 the means and variances across coefficients.
249 
250 The lifter (cepstral filter) used is:
251 \f[c_i' = \{ 1 + \frac{L}{2} sin \frac{\Pi i}{L} \} \; c_i\f]
252 
253 A typical value of L used in speech recognition is 22. A value of L=0 is taken
254 to mean no liftering. This is equivalent to L=1.
255 
256 @see sig2fft
257 @see fft2fbank
258 @see sig2fbank
259 */
260 void fbank2melcep(const EST_FVector &fbank_vec,
261  EST_FVector &mfcc,
262  const float liftering_parameter,
263  const bool include_c0 = false);
264 
265 /** Make a triangular Mel scale filter. The filter is centred at
266 `this_mel_centre` and
267 extends from `this_mel_low` to `this_mel_high`. `half_fft_order`
268 is the length of a power/energy spectrum covering 0Hz to half the sampling
269 frequency with a resolution of `Hz_per_fft_coeff`.
270 
271 The routine returns a vector of weights to be applied to the energy/power
272 spectrum starting at element `fft_index_start`.
273 The number of points (FFT coefficients) covered
274 by the filter is given by the length of the returned vector `filter`.
275 
276 @see fft2fbank
277 @see Hz2Mel
278 @see Mel2Hz
279 */
280 void make_mel_triangular_filter(const float this_mel_centre,
281  const float this_mel_low,
282  const float this_mel_high,
283  const float Hz_per_fft_coeff,
284  const int half_fft_order,
285  int &fft_index_start,
286  EST_FVector &filter);
287 
288 ///@}
289 /// end of filter bank and cepstral analysis
290 
291 /**@defgroup frequencyconversionfunctions Frequency conversion functions
292  * @ingroup Framebasedfilterbankandcepstralanalysis
293  @brief These are functions used in filter bank and cepstral analysis.
294 */
295 
296 ///@{
297 
298 /** Convert Hertz to Mel. The Mel scale is defined by
299 \f[f_{\mbox{Mel}} = 1127 \; log( 1 + \frac{f_{\mbox{Hertz}}}{700} )\f]
300 
301 @see Mel2Hz
302 @see Frequency conversion functions
303 */
304 float Hz2Mel(float frequency_in_Hertz);
305 
306 /**
307 Convert Mel to Hertz.
308 
309 @see Hz2Mel
310 */
311 float Mel2Hz(float frequency_in_Mel);
312 
313 ///@}
314 /// end of frequency conversion functions
315 
316 
317 
318 
319 
320 #endif /* __EST_SIGPR_FRAME_H__ */
void make_mel_triangular_filter(const float this_mel_centre, const float this_mel_low, const float this_mel_high, const float Hz_per_fft_coeff, const int half_fft_order, int &fft_index_start, EST_FVector &filter)
Definition: sigpr_frame.cc:730
void fft2fbank(const EST_FVector &fft_frame, EST_FVector &fbank_vec, const float Hz_per_fft_coeff, const EST_FVector &mel_fbank_frequencies)
Definition: sigpr_frame.cc:635
void ref2area(const EST_FVector &ref, EST_FVector &area)
Definition: sigpr_frame.cc:261
void sig2ref(const EST_FVector &sig, EST_FVector &ref)
Definition: sigpr_frame.cc:253
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
Definition: EST_FMatrix.h:119
void sig2pow(EST_FVector &frame, float &power)
Definition: sigpr_frame.cc:472
void power(EST_Wave &sig, EST_Track &a, float factor)
Definition: sigpr_utt.cc:422
void lsf2lpc(const EST_FVector &lsf, EST_FVector &lpc)
Definition: sigpr_frame.cc:399
float Hz2Mel(float frequency_in_Hertz)
Definition: sigpr_frame.cc:790
void fbank2melcep(const EST_FVector &fbank_vec, EST_FVector &mfcc, const float liftering_parameter, const bool include_c0=false)
Definition: sigpr_frame.cc:684
void sig2rms(EST_FVector &frame, float &rms_energy)
Definition: sigpr_frame.cc:481
void sig2fft(const EST_FVector &sig, EST_FVector &fft_vec, const bool use_power_rather_than_energy)
Definition: sigpr_frame.cc:590
void ref2logarea(const EST_FVector &ref, EST_FVector &logarea)
Definition: sigpr_frame.cc:267
void ref2truearea(const EST_FVector &ref, EST_FVector &area)
Definition: sigpr_frame.cc:282
void frame_convert(const EST_FVector &in_frame, const EST_String &in_type, EST_FVector &out_frame, const EST_String &out_type)
Definition: sigpr_frame.cc:206
void ref2lpc(const EST_FVector &ref, EST_FVector &lpc)
Definition: sigpr_frame.cc:364
void lpc2ref(const EST_FVector &lpc, EST_FVector &ref)
Definition: sigpr_frame.cc:340
void sig2fbank(const EST_FVector &sig, EST_FVector &fbank_frame, const float sample_rate, const bool use_power_rather_than_energy, const bool take_log)
Definition: sigpr_frame.cc:538
void lpc2lsf(const EST_FVector &lpc, EST_FVector &lsf)
Definition: sigpr_frame.cc:392
void lpc2cep(const EST_FVector &lpc, EST_FVector &cep)
Definition: sigpr_frame.cc:291
float Mel2Hz(float frequency_in_Mel)
Definition: sigpr_frame.cc:795
void sig2lpc(const EST_FVector &sig, EST_FVector &acf, EST_FVector &ref, EST_FVector &lpc)
Definition: sigpr_frame.cc:406