时间序列 - 识别方波型信号的方法
Time Series - Approach for Identifying Square Wave-type Signals
我正在尝试找到一种方法来过滤掉具有如下模式的信号。
该模式可以描述为具有方波,通常在多个时间段内具有恒定的波动值 +-1、+-2 或 +-0。信号通常会瞬间下降到 5-100 std dev,然后在很短的时间内保持恒定速率,然后再次上升。这些类型的信号可以有一个或多个不同长度的方波,但总是在信号中呈现方波。
此信号的数据:
y = array([ 8., 8., 173., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 173., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 173., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 130., 130., 130., 130., 130., 130., 130., 130.,130., 130., 130., 130., 130., 130., 130., 130., 130., 130., 130.,130., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 173., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172.,172., 172., 172., 172., 172., 131., 131., 131., 131., 131., 131.,131., 131., 131., 131., 131., 131., 131., 131., 131., 131., 131.,172., 172., 172., 172., 173., 172., 172., 172., 172., 172., 173.,172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172.,172., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 173.,172., 172., 172., 172., 172., 172., 172., 172., 173., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172.])
我需要找到一种方法来帮助我聚类或过滤掉大约 3000 个信号中的这些信号。我试过以下方法,结果好坏参半:
- 带 TSLearn 和 DTW 的单变量时间序列聚类 python 包在一些与方差相关的特征上(混合结果)
- 使用 K-Means、KNN 等进行多元聚类(通常可以为单个信号分配多个聚类。规则是一个信号一个桶,而不是多个桶)
- 在数组中查找子序列的条件逻辑,希望找到方波(我对此无能为力,因为好信号的一半长度可以等于信号重要部分长度的一半; 方波)
- 核分布估计(我有其他信号与此信号具有相同的分布,因此我无法根据 ranking/clustering 系数过滤掉它们)
你能推荐其他方法来帮助我从一组其他信号中识别出这种类型的信号吗?如果您的方法是傅里叶变换,您能否举例说明我如何使用它从一组其他信号中滤除该信号?
这样做就可以了:
def first_der(df):
y = df.NREVS.values
x = df.cum_int.values
dy=np.diff(y,1)
dx=np.diff(x,1)
yfirst=dy/dx
return yfirst
def zero_runs(yfirst):
# Create an array that is 1 where a is 0, and pad each end with an extra 0.
iszero = np.concatenate(([0], np.equal(a, 0).view(np.int8), [0]))
absdiff = np.abs(np.diff(iszero))
# Runs start and end where absdiff is 1.
ranges = np.where(absdiff == 1)[0].reshape(-1,2)
return yind
def square_finder(yfirst, yind, df):
xmax = yind.shape[0] #max value in first position where y_first can be indexed
ymax = yind.shape[1] #max value in second position
thresh = 4
for i in range(0,xmax):
if yind[i][1] < len(yfirst):
if ((yfirst[yind[i][1]] > 5) | (yfirst[yind[i][1]] < -5)):
#if ((yfirst[yind[i-1][1]+1] > 3) | (yfirst[yind[i-1][1]+1] < -3)):
zeros = yind[i][1] - yind[i-1][1] - 2
if zeros >= thresh:
df['category'] = 'square'
else:
pass
else:
pass
else:
pass
return df
我正在尝试找到一种方法来过滤掉具有如下模式的信号。
该模式可以描述为具有方波,通常在多个时间段内具有恒定的波动值 +-1、+-2 或 +-0。信号通常会瞬间下降到 5-100 std dev,然后在很短的时间内保持恒定速率,然后再次上升。这些类型的信号可以有一个或多个不同长度的方波,但总是在信号中呈现方波。
此信号的数据:
y = array([ 8., 8., 173., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 173., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 173., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 130., 130., 130., 130., 130., 130., 130., 130.,130., 130., 130., 130., 130., 130., 130., 130., 130., 130., 130.,130., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 173., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172.,172., 172., 172., 172., 172., 131., 131., 131., 131., 131., 131.,131., 131., 131., 131., 131., 131., 131., 131., 131., 131., 131.,172., 172., 172., 172., 173., 172., 172., 172., 172., 172., 173.,172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172.,172., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 173., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 173.,172., 172., 172., 172., 172., 172., 172., 172., 173., 172., 172.,172., 172., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 173., 172., 172., 172., 172., 172., 172., 172., 172., 172.,172., 172., 172., 172., 172.])
我需要找到一种方法来帮助我聚类或过滤掉大约 3000 个信号中的这些信号。我试过以下方法,结果好坏参半:
- 带 TSLearn 和 DTW 的单变量时间序列聚类 python 包在一些与方差相关的特征上(混合结果)
- 使用 K-Means、KNN 等进行多元聚类(通常可以为单个信号分配多个聚类。规则是一个信号一个桶,而不是多个桶)
- 在数组中查找子序列的条件逻辑,希望找到方波(我对此无能为力,因为好信号的一半长度可以等于信号重要部分长度的一半; 方波)
- 核分布估计(我有其他信号与此信号具有相同的分布,因此我无法根据 ranking/clustering 系数过滤掉它们)
你能推荐其他方法来帮助我从一组其他信号中识别出这种类型的信号吗?如果您的方法是傅里叶变换,您能否举例说明我如何使用它从一组其他信号中滤除该信号?
这样做就可以了:
def first_der(df):
y = df.NREVS.values
x = df.cum_int.values
dy=np.diff(y,1)
dx=np.diff(x,1)
yfirst=dy/dx
return yfirst
def zero_runs(yfirst):
# Create an array that is 1 where a is 0, and pad each end with an extra 0.
iszero = np.concatenate(([0], np.equal(a, 0).view(np.int8), [0]))
absdiff = np.abs(np.diff(iszero))
# Runs start and end where absdiff is 1.
ranges = np.where(absdiff == 1)[0].reshape(-1,2)
return yind
def square_finder(yfirst, yind, df):
xmax = yind.shape[0] #max value in first position where y_first can be indexed
ymax = yind.shape[1] #max value in second position
thresh = 4
for i in range(0,xmax):
if yind[i][1] < len(yfirst):
if ((yfirst[yind[i][1]] > 5) | (yfirst[yind[i][1]] < -5)):
#if ((yfirst[yind[i-1][1]+1] > 3) | (yfirst[yind[i-1][1]+1] < -3)):
zeros = yind[i][1] - yind[i-1][1] - 2
if zeros >= thresh:
df['category'] = 'square'
else:
pass
else:
pass
else:
pass
return df