Sethares和Staley周期变换
pyPeriod的Python项目详细描述
周期
Python中Sethares和Staley的周期性变换。见论文here。在
在效率方面还有很多工作要做,但它忠实地实现了本文中的思想和算法。这是一个alpha版本,所以希望在未来有突破性的变化。在
使用
import numpy as np
from pyPeriod import Periods
from random import uniform
# define a signal
sr = 1000 # samplerate
f1 = 10 # frequency
f2 = 17
noise = 0.2 # percent noise
# Make some signals with some noise. The second signal has a slightly offset phase.
a = [np.sin((x*np.pi*2*f1)/sr)+(uniform(-1*noise, noise)) for x in range(2000)]
b = [np.sin(((x*np.pi*2*f2)/sr) + (np.pi*1.1))+(uniform(-1*noise, noise)) for x in range(2000)]
c = np.array(a)+np.array(b) # combine the signals
# normalize, though the algorithms can handle any range of signals (best if DC is removed)
c /= np.max(np.abs(c),axis=0)
p = Periods(c) # make an instance of Period
"""
The output of each algorithm are three arrays consisting of:
periods: the integer values of the periods found
powers: the floating point values of the amount of "energy" removed by each period found
bases: the arrays, equal in length to the input signal length, that contain the periodicities found
"""
# find periodicities using the small-to-large algorithm
periods, powers, bases = p.small_to_large(thresh=0.1)
# find periodicities using the M-best algorithm
periods, powers, bases = p.m_best(num=10)
# find periodicities using the M-best gamma algorithm
periods, powers, bases = p.m_best_gamma(num=10)
# find periodicities using the best correlation algorithm
periods, powers, bases = p.best_correlation(num=10)
# find periodicities using the best frequency algorithm
periods, powers, bases = p.best_frequency(sr=sr, win_size=None, num=10)
## note that for best frequency, we need a samplerate. The window size, if not provided,
## is the same length as the input signal. A larger window is zero-padded, a smaller
## window is truncated (not good).
算法
- 从小到大
- M-最佳
- 最佳伽马射线
- 最佳相关性
- 最佳频率
文档
即将到来。在来源和论文之间,同时应该很容易理解。在
要求
numpy>=1.19.2
贡献者
- 雅各布·桑德斯特罗姆:加州大学圣地亚哥分校
- 项目
标签: