时间序列 - 识别方波型信号的方法

问题描述 投票:0回答:2

我正在尝试寻找一种方法来过滤掉具有如下模式的信号。

该形态可以描述为方波,通常在多个时间段内具有恒定的波动值 +-1、+-2 或 +-0。信号通常会瞬间下降到 5-100 标准差,然后在很短的时间内保持恒定速率,然后再次回升。这些类型的信号可以具有单个或多个不同长度的方波,但始终在信号中呈现方波。

此信号的数据:

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 等进行多元聚类(通常可以为单个信号分配多个聚类。规则是一个信号对应一个桶,而不是多个桶)
  • 在数组中查找子序列的条件逻辑,希望找到方波(我对此无能为力,因为好的信号的一半长度可以等于信号重要部分长度的一半;方波)
  • 核分布估计(我有其他信号与该信号具有相同的分布,因此我无法根据系数的排名/聚类过滤掉这些信号)

您能否推荐其他方法来帮助我从一组其他信号中识别出此类信号?如果您的方法是傅里叶变换,您能否提供一个示例,说明我如何使用它从一组其他信号中过滤掉该信号?

python time-series fft distribution curve-fitting
2个回答
0
投票

这样就可以了:

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

0
投票

@starbucks 请您解释一下这个答案。什么是 NERVS 和 cum_int?这些是数据框属性。我有一组与原始问题类似的值this is the array values plot

© www.soinside.com 2019 - 2024. All rights reserved.