微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决时间序列-识别方波信号的方法

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

可以描述为具有方波的图案,该方波在许多时间段内通常具有恒定的波动值+ -1,+-2或+ -0。信号通常会立即在5-100 std dev内下降,然后在很短的时间内保持恒定速率,然后再次发射回去。这些类型的信号可以具有单个或多个不同长度的方波,但始终在信号中显示方波。

enter image description here

此信号的数据:

y = array([  8.,8.,173.,172.,130.,131.,172.])

我需要找到一种方法,可以帮助我聚类或滤除大约3000个信号中的这些信号。我已经尝试了以下方法,但结果却很复杂:

  • 带有TSLearn和DTW python软件包的单变量时间序列聚类,涉及许多与方差相关的功能(混合结果)
  • 具有K均值,KNN等的多元聚类(通常可以为单个信号分配多个聚类。规则是一个信号用于一个存储桶,而不是多个存储桶)
  • 条件逻辑,它找到阵列中的子序列,希望找到方波(我不能做任何事情,因为好的信号的一半长度可以等于信号重要部分的一半长度;方波)
  • 内核分布估计(我还有其他与该信号具有相同分布的信号,因此我无法基于系数的排序/聚类将其过滤掉)

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

解决方法

这可以做到:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。