您对二进制时间序列的信号处理有什么建议吗?
Do you have some advices about signal processing on binary time series?
我有一个二进制时间序列,其中包含一些不同频率的 ASK 调制信号。
假设它是这样的:x = [0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0 ,0,1,1,1,1,0,0,0,0,0,0,0, ...]
对我来说重要的是所有“1”和“0”都在 4 个或更多样本的间隔内,但有时“0”和“1”会像这样改变位置:x1 = [0,0 ,0,1,1,1,1,1] 当它必须是 x2 = [0,0,0,0,1,1,1,1]
还有一些噪音,如 n1 = [0,0,0,0,0,0,1,1,0,0,0,0,0] 中看到的尖峰,而它应该仅为零.
我已经尝试过移动平均线,但它引入了对我的应用不利的信号延迟。
你对二进制时间序列的信号处理有什么建议吗?
以下代码查找长度小于4(min_cont_length
)的所有连续序列的索引。它还会为您提供有问题扇区的长度,以便您决定如何处理它们。
import numpy as np
def find_index_of_err(signal, min_cont_length = 4):
# pad sides to detect problems at the edges
signal = np.concatenate(([1-signal[0]],signal,[1-signal[-1]]))
# calculate differences from 1 element to the next
delta = np.concatenate(([0], np.diff(signal, 1)))
# detect discontinuities
discontinuity = np.where(delta!=0)[0]
# select discontinuities with matching length (< min_cont_length)
err_idx = discontinuity[:-1][np.diff(discontinuity) < min_cont_length] - 1
# get also the size of the gap
err_val = np.diff(discontinuity)[np.argwhere(np.diff(discontinuity) < min_cont_length).flatten()]
return err_idx, err_val
# some test signals
signals = np.array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]])
for sig in signals:
index, value = find_index_of_err(sig)
print(sig, index, value)
# Output:
# [1 0 0 0 0 0 0 0 0 0 0] [0] [1]
# [0 0 1 0 0 0 0 0 0 0 0] [0 2] [2 1]
# [0 0 0 0 1 0 0 0 0 0 0] [4] [1]
# [0 0 0 0 0 0 1 1 0 0 0] [6 8] [2 3]
# [0 0 0 0 0 0 1 1 1 1 1] [] []
我有一个二进制时间序列,其中包含一些不同频率的 ASK 调制信号。
假设它是这样的:x = [0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0 ,0,1,1,1,1,0,0,0,0,0,0,0, ...]
对我来说重要的是所有“1”和“0”都在 4 个或更多样本的间隔内,但有时“0”和“1”会像这样改变位置:x1 = [0,0 ,0,1,1,1,1,1] 当它必须是 x2 = [0,0,0,0,1,1,1,1]
还有一些噪音,如 n1 = [0,0,0,0,0,0,1,1,0,0,0,0,0] 中看到的尖峰,而它应该仅为零.
我已经尝试过移动平均线,但它引入了对我的应用不利的信号延迟。
你对二进制时间序列的信号处理有什么建议吗?
以下代码查找长度小于4(min_cont_length
)的所有连续序列的索引。它还会为您提供有问题扇区的长度,以便您决定如何处理它们。
import numpy as np
def find_index_of_err(signal, min_cont_length = 4):
# pad sides to detect problems at the edges
signal = np.concatenate(([1-signal[0]],signal,[1-signal[-1]]))
# calculate differences from 1 element to the next
delta = np.concatenate(([0], np.diff(signal, 1)))
# detect discontinuities
discontinuity = np.where(delta!=0)[0]
# select discontinuities with matching length (< min_cont_length)
err_idx = discontinuity[:-1][np.diff(discontinuity) < min_cont_length] - 1
# get also the size of the gap
err_val = np.diff(discontinuity)[np.argwhere(np.diff(discontinuity) < min_cont_length).flatten()]
return err_idx, err_val
# some test signals
signals = np.array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]])
for sig in signals:
index, value = find_index_of_err(sig)
print(sig, index, value)
# Output:
# [1 0 0 0 0 0 0 0 0 0 0] [0] [1]
# [0 0 1 0 0 0 0 0 0 0 0] [0 2] [2 1]
# [0 0 0 0 1 0 0 0 0 0 0] [4] [1]
# [0 0 0 0 0 0 1 1 0 0 0] [6 8] [2 3]
# [0 0 0 0 0 0 1 1 1 1 1] [] []