pyACA: Documentation 0.3.1
Source Code for Audio Content Analysis
Loading...
Searching...
No Matches
Functions
pyACA.ToolFreq2Mel Namespace Reference

Functions

 ToolFreq2Mel (fInHz, cModel='Fant')
 helper function: convert Hz to Mel scale
 

Function Documentation

◆ ToolFreq2Mel()

ToolFreq2Mel ( fInHz,
cModel = 'Fant' )

helper function: convert Hz to Mel scale

Parameters
fInHzfrequency to be converted, can be scalar or vector
cModelname of the model ('Fant' [default], 'Shaughnessy', 'Umesh')
Returns
fMel: Mel values

Definition at line 13 of file ToolFreq2Mel.py.

13def ToolFreq2Mel(fInHz, cModel='Fant'):
14 # Fant
15 def acaFant_scalar(f):
16 return 1000 * math.log2(1 + f/1000)
17
18 # Shaughnessy
19 def acaShaughnessy_scalar(f):
20 return 2595 * math.log10(1 + f/700)
21
22 # Umesh
23 def acaUmesh_scalar(f):
24 return f/(2.4e-4*f + 0.741)
25
26 f = np.asarray(fInHz)
27 if f.ndim == 0:
28 if cModel == 'Shaughnessy':
29 return acaShaughnessy_scalar(f)
30 elif cModel == 'Umesh':
31 return acaUmesh_scalar(f)
32 else:
33 return acaFant_scalar(f)
34
35 fMel = np.zeros(f.shape)
36 if cModel == 'Shaughnessy':
37 for k, fi in enumerate(f):
38 fMel[k] = acaShaughnessy_scalar(fi)
39 elif cModel == 'Umesh':
40 for k, fi in enumerate(f):
41 fMel[k] = acaUmesh_scalar(fi)
42 else:
43 for k, fi in enumerate(f):
44 fMel[k] = acaFant_scalar(fi)
45
46 return fMel