文章目录
- 一、时域处理
- 1.1 librosa.autocorrelate
- 1.1.1 语法与参数
- 1.1.2 例子
- 1.1.2.1 计算完全自相关y
- 1.1.2.2 计算长达 4 秒的起始强度自相关
一、时域处理
1.1 librosa.autocorrelate
https://librosa.org/doc/latest/generated/librosa.autocorrelate.html
1.1.1 语法与参数
librosa.autocorrelate(y, *, max_size=None, axis=- 1)[source]
有界滞后自相关
>参数y:np.ndarray数组自相关max_size:int > 0 or None最大相关滞后。如果未指定,则默认为y.shape[axis](无界)axis:int自相关所沿的轴。默认情况下,采用最后一个轴 (-1)。>返回值z:np.ndarrayy*y沿指定轴截断的自相关。如果max_size指定,则z.shape[axis]有界到max_size。
Notes
此函数缓存在 20 级。
1.1.2 例子
1.1.2.1 计算完全自相关y
# 计算完全自相关y
import librosay, sr = librosa.load(librosa.ex('trumpet'))
print(librosa.autocorrelate(y))
"""
[ 6.89931420e+02 6.23597636e+02 4.48787565e+02 ... -2.87956876e-093.70971744e-08 -1.79581785e-08]
"""
1.1.2.2 计算长达 4 秒的起始强度自相关
# 计算完全自相关y
import librosa
import matplotlib.pyplot as plty, sr = librosa.load(librosa.ex('trumpet'))
print(sr) # 22050
print(y)
"""
[-1.4068224e-03 -4.4607223e-04 -4.1098078e-04 ... 7.9623060e-06-3.0417003e-05 1.2765067e-05]
"""odf = librosa.onset.onset_strength(y=y, sr=sr, hop_length=512)
print(odf)
"""
[0.00000000e+00 0.00000000e+00 0.00000000e+00 4.17845964e+001.13509560e+00 1.82122588e-01 1.72356606e-01 1.18283510e-019.44824517e-01 3.77103591e+00 6.58177662e+00 8.25611687e+003.08506632e+00 3.13406616e-01 3.21937829e-01 6.42343104e-019.93093491e-01 4.78707838e+00 3.84358883e+00 1.58594739e+008.31244528e-01 6.17250919e-01 6.10312700e-01 2.01938367e+003.42684698e+00 1.95094514e+00 7.68183517e+00 6.41882753e+001.50753009e+00 4.19695750e-02 2.26590529e-01 2.75454521e+004.37553072e+00 2.39662790e+00 8.77303123e-01 5.22520900e-014.79927957e-01 9.28298354e-01 2.72709799e+00 3.76103878e+007.26637745e+00 5.59427738e+00 1.51596546e+00 7.97890782e-012.35249877e+00 5.24696827e+00 1.06628597e+00 5.39485574e-017.38652992e+00 1.74603093e+00 1.20418048e+00 1.48233950e+007.93847799e-01 5.63979506e-01 1.04662836e+00 1.12031078e+001.52801478e+00 2.27576208e+00 1.67852926e+00 5.42153120e-014.30115104e-01 1.14976578e+01 7.16263056e+00 1.58617485e+008.34993541e-01 1.45350015e+00 1.20756626e+00 2.30439115e+002.23954248e+00 1.16052115e+00 4.63239580e-01 1.82088804e+004.34435797e+00 1.93747187e+00 6.00777268e-01 1.12067342e+001.01238251e+00 9.11972642e-01 5.94635606e-01 4.24022168e-016.86975598e-01 2.40581989e+00 1.97992146e+00 2.59550065e-011.47426531e-01 2.51426369e-01 5.56935489e-01 9.42625761e-011.73099213e+01 9.25381374e+00 1.64803064e+00 3.17822486e-018.00392628e-02 1.61836475e-01 8.90664399e-01 4.78239107e+003.45063853e+00 1.85295865e-01 0.00000000e+00 2.01156676e-013.59036386e-01 1.59203696e+00 1.06260805e+01 6.80992413e+002.17226887e+00 1.31850600e+00 1.51034641e+00 1.46862054e+005.56796491e-01 2.81662226e+00 7.62025452e+00 4.23897266e+002.00937366e+00 7.33176589e-01 1.18238747e-01 3.85864466e-015.32984078e-01 6.84280992e-01 1.07605183e+00 5.22916436e-014.39226091e-01 4.45047468e-01 6.01421237e-01 6.27728999e-011.11530638e+00 1.18479598e+00 6.13896489e-01 4.82841969e-013.52134496e-01 1.86522460e+00 3.70014620e+00 2.87164974e+005.38166285e-01 6.92774355e-02 7.51249552e-01 7.63877273e-013.22526246e-01 3.95352423e-01 3.15897495e-01 4.12356138e-016.48618221e-01 3.21835697e-01 5.21747947e-01 4.26418334e-013.89231294e-01 3.27717274e-01 2.83269316e-01 2.52752095e-013.10896307e-01 2.42993012e-01 3.30240250e-01 1.92404851e-012.78108686e-01 3.10559481e-01 1.96977884e-01 2.10453570e-012.03978002e-01 7.99052417e-02 1.41900450e-01 2.24013209e-018.00894499e-02 5.86625934e-02 1.05982393e-01 1.56429648e-013.60565186e-02 3.05968225e-02 1.74235672e-01 1.86321586e-017.59349167e-02 2.53845155e-02 5.09086251e-03 1.57953560e-018.69446397e-02 5.50147891e-03 2.30761170e-02 1.36366785e-021.11565441e-01 9.87712741e-02 6.89095557e-02 5.31762838e-024.49128151e-02 8.09687376e-03 5.56744933e-02 1.94908381e-024.04570401e-02 3.24057639e-02 5.90607524e-03 1.78426504e-033.76984477e-03 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+000.00000000e+00 0.00000000e+00]
"""ac = librosa.autocorrelate(odf, max_size=4*sr//512)
print(ac)
"""
[1.53906712e+03 9.72211277e+02 4.92505001e+02 4.03518881e+024.01009760e+02 4.55849992e+02 6.30879802e+02 8.08636093e+027.22594166e+02 5.15360410e+02 4.17751475e+02 3.72633792e+024.01515542e+02 6.41693803e+02 8.10333052e+02 7.04471193e+026.59103241e+02 5.47369439e+02 4.10996238e+02 3.97787237e+025.36795931e+02 7.27394773e+02 7.21893275e+02 5.89398316e+024.69588717e+02 3.46915001e+02 4.22965487e+02 6.33560203e+025.72802961e+02 5.29171844e+02 5.35185634e+02 4.66096728e+023.67880019e+02 3.91257789e+02 5.09466514e+02 5.06506079e+024.17350796e+02 4.41280018e+02 4.14528568e+02 3.79579254e+025.31012676e+02 5.72173825e+02 4.65350621e+02 4.35922076e+024.17520243e+02 3.90662502e+02 3.46334063e+02 4.09263730e+025.00527804e+02 4.92848446e+02 4.67597709e+02 4.00200707e+023.07747809e+02 2.75222936e+02 3.58832558e+02 3.74153283e+023.67172822e+02 3.77770927e+02 3.38165891e+02 2.38069584e+022.31962478e+02 4.12046273e+02 5.62207889e+02 4.43822348e+023.73691208e+02 3.01545109e+02 2.12601367e+02 1.93659925e+022.61277135e+02 3.66016253e+02 4.15180653e+02 3.85427956e+022.70161026e+02 1.82499103e+02 1.58810504e+02 2.05499836e+023.04012456e+02 4.10349950e+02 4.47543010e+02 3.54504355e+022.11730394e+02 1.47646496e+02 1.59501251e+02 2.26138506e+023.11921796e+02 3.78457948e+02 2.75469899e+02 1.61481591e+021.16316245e+02 1.30806374e+02 1.77704839e+02 2.56155174e+022.94401117e+02 2.45425704e+02 1.65182036e+02 1.20023037e+021.02225389e+02 1.10797814e+02 1.61196699e+02 2.27559806e+021.95140666e+02 1.42654793e+02 1.12380182e+02 1.07640898e+021.06058834e+02 9.19490257e+01 9.56289088e+01 1.12639943e+028.85596608e+01 6.53390897e+01 5.73982420e+01 6.01536160e+017.10954285e+01 8.00590962e+01 7.28558421e+01 5.90015632e+014.90849105e+01 4.82818836e+01 6.28295448e+01 8.09906405e+018.24768210e+01 6.68630668e+01 4.81898681e+01 3.86925437e+013.48336984e+01 3.36460767e+01 4.08995839e+01 4.44533933e+013.68989018e+01 2.63342097e+01 2.36941134e+01 2.67743027e+012.52934559e+01 2.13689544e+01 1.96097660e+01 1.88746848e+011.86427164e+01 1.75929579e+01 1.51959437e+01 1.65010795e+011.54526910e+01 1.42109166e+01 1.28271039e+01 1.13763007e+011.14906392e+01 1.12357692e+01 8.63172385e+00 7.85063634e+007.74348190e+00 8.06154820e+00 7.65753230e+00 6.33001453e+006.18590446e+00 5.56364664e+00 4.72584960e+00 5.08954996e+005.58797583e+00 4.37632184e+00 3.64204534e+00 3.51674417e+003.85626082e+00 3.15784639e+00 2.47818328e+00 2.28884723e+002.08978321e+00 2.31281267e+00 2.39195938e+00 2.43994969e+002.53125267e+00 1.61125242e+00 9.51273640e-01 9.96806807e-01]进程已结束,退出代码0"""fig, ax = plt.subplots()
ax.plot(ac)
ax.set(title='Auto-correlation', xlabel='Lag(frames)')
plt.show()