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

Functions

 PitchSpectralHps (X, f_s)
 computes f0 via the maximum of the Harmonic Product Spectrum
 

Function Documentation

◆ PitchSpectralHps()

PitchSpectralHps ( X,
f_s )

computes f0 via the maximum of the Harmonic Product Spectrum

Parameters
Xspectrogram (dimension FFTLength X Observations)
f_ssample rate of audio data
Returns
f_0: fundamental frequency (in Hz)

Definition at line 12 of file PitchSpectralHps.py.

12def PitchSpectralHps(X, f_s):
13
14 # initialize
15 iOrder = 4
16 f_min = 300
17 f_0 = np.zeros(X.shape[1])
18
19 iLen = int((X.shape[0] - 1) / iOrder)
20 afHps = X[np.arange(0, iLen), :]
21 k_min = int(round(f_min / f_s * 2 * (X.shape[0] - 1)))
22
23 # compute the HPS
24 for j in range(1, iOrder):
25 X_d = X[::(j + 1), :]
26 afHps *= X_d[np.arange(0, iLen), :]
27
28 f_0 = np.argmax(afHps[np.arange(k_min, afHps.shape[0])], axis=0)
29
30 # find max index and convert to Hz
31 f_0 = (f_0 + k_min) / (X.shape[0] - 1) * f_s / 2
32
33 return f_0