我正在尝试寻找一种方法来过滤掉具有如下模式的信号。
该形态可以描述为方波,通常在多个时间段内具有恒定的波动值 +-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 个信号中聚类出或过滤掉这些信号。我尝试了以下方法,但结果很复杂:
您能否推荐其他方法来帮助我从一组其他信号中识别出此类信号?如果您的方法是傅里叶变换,您能否提供一个示例,说明我如何使用它从一组其他信号中过滤掉该信号?
这样就可以了:
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