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

computes the pitch chroma from the magnitude spectrum More...

Functions

 FeatureSpectralPitchChroma (X, f_s)
 computes the pitch chroma from the magnitude spectrum
 
 generatePcFilters (iSpecLength, f_s)
 

Detailed Description

computes the pitch chroma from the magnitude spectrum

Args: X: spectrogram (dimension FFTLength X Observations) f_s: sample rate of audio data

Returns: v_pc: pitch chroma

Function Documentation

◆ FeatureSpectralPitchChroma()

FeatureSpectralPitchChroma ( X,
f_s )

computes the pitch chroma from the magnitude spectrum

Parameters
Xspectrogram (dimension FFTLength X Observations)
f_ssample rate of audio data
Returns
v_pc: pitch chroma

Definition at line 23 of file FeatureSpectralPitchChroma.py.

23def FeatureSpectralPitchChroma(X, f_s):
24
25 isSpectrum = X.ndim == 1
26 if isSpectrum:
27 X = np.expand_dims(X, axis=1)
28
29 # generate filter matrix
30 H = generatePcFilters(X.shape[0], f_s)
31
32 # compute pitch chroma
33 v_pc = np.dot(H, X**2)
34
35 # norm pitch chroma to a sum of 1 but avoid div by zero
36 norm = v_pc.sum(axis=0, keepdims=True)
37 norm[norm == 0] = 1
38 v_pc = v_pc / norm
39
40 return np.squeeze(v_pc) if isSpectrum else v_pc
41
42
Here is the call graph for this function:

◆ generatePcFilters()

generatePcFilters ( iSpecLength,
f_s )

Definition at line 43 of file FeatureSpectralPitchChroma.py.

43def generatePcFilters(iSpecLength, f_s):
44
45 # initialization at C4
46 f_mid = 261.63
47 iNumOctaves = 4
48 iNumPitchesPerOctave = 12
49
50 # sanity check
51 while f_mid * 2**iNumOctaves > f_s / 2.:
52 iNumOctaves = iNumOctaves - 1
53
54 H = np.zeros([iNumPitchesPerOctave, iSpecLength])
55
56 # for each pitch class i create weighting factors in each octave j
57 for i in range(0, iNumPitchesPerOctave):
58 afBounds = np.array([2**(-1 / (2 * iNumPitchesPerOctave)), 2**(1 / (2 * iNumPitchesPerOctave))]) * f_mid * 2 * (iSpecLength - 1) / f_s
59 for j in range(0, iNumOctaves):
60 iBounds = np.array([math.ceil(2**j * afBounds[0]), math.ceil(2**j * afBounds[1])])
61 H[i, range(iBounds[0], iBounds[1])] = 1 / (iBounds[1] - iBounds[0] + 1)
62
63 # increment to next semi-tone
64 f_mid = f_mid * 2**(1 / iNumPitchesPerOctave)
65
66 return H
Here is the caller graph for this function: