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

Functions

 FeatureSpectralTonalPowerRatio (X, f_s, G_T=5e-4)
 computes the tonal power ratio from the magnitude spectrum
 

Function Documentation

◆ FeatureSpectralTonalPowerRatio()

FeatureSpectralTonalPowerRatio ( X,
f_s,
G_T = 5e-4 )

computes the tonal power ratio from the magnitude spectrum

Parameters
Xspectrogram (dimension FFTLength X Observations)
f_ssample rate of audio data
G_Tenergy threshold
Returns
vtpr: tonal power ratio

Definition at line 14 of file FeatureSpectralTonalPowerRatio.py.

14def FeatureSpectralTonalPowerRatio(X, f_s, G_T=5e-4):
15
16 isSpectrum = X.ndim == 1
17 if isSpectrum:
18 X = np.expand_dims(X, axis=1)
19
20 X = X**2
21
22 fSum = X.sum(axis=0)
23 vtpr = np.zeros(fSum.shape)
24
25 for n in range(0, X.shape[1]):
26 if fSum[n] < G_T:
27 continue
28
29 # find local maxima above the threshold
30 afPeaks = find_peaks(X[:, n], height=G_T)
31
32 if not afPeaks[0].size:
33 continue
34
35 # calculate ratio
36 vtpr[n] = X[afPeaks[0], n].sum() / fSum[n]
37
38 return np.squeeze(vtpr) if isSpectrum else vtpr