python - 组合时间序列中的相似信号

标签 python python-3.x signal-processing

假设我有一个这样的信号。我已经完成了多轮适配,现在可以更轻松地管理信号了。

但无论出于何种原因,我似乎无法消除一些微小的差异。

enter image description here

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd


a = [0.5]*20
b = [0.4]*20
c = [0.503]*20
d = [0.4]*20

signal = pd.Series(np.concatenate([a,b,c,d]))

plt.figure(figsize = (7,3))
plt.plot(signal, color = "firebrick")
plt.axhline(0.5, linestyle = ":")
plt.show()

# Identify the four different intensities, so they can be grouped
id = signal.transform(lambda x: (abs(x.diff()) > 0).cumsum())

我认为解决方案可能是将所有信号从低到高排列 [0.4, 0.4, 0.5, 0.503]

然后仔细检查它们,同时忽略微小的差异,例如0.010,所以

id = signal.transform(lambda x: (abs(x.diff()) > 0.010).cumsum())

然后我只能正确识别 2 种不同的强度。对于微小的差异,我可以只取平均值或中位数。这并没有什么区别。重要的是我没有计算超过 2 个不同的强度。

我该怎么做?

最佳答案

这是我在评论中提出的想法的详细阐述。

使用信号的平均值作为阈值。然后计算高于阈值和低于阈值的信号部分的中值。使用它们来转换您的数据。

med_high = signal[signal > signal.mean()].median()
med_low = signal[signal < signal.mean()].median()
print (med_low, med_high)

new_signal = signal.transform(lambda x: med_low if x < signal.mean() else med_high)
plt.figure(figsize = (7,3))
plt.plot(new_signal, color = "firebrick")
plt.axhline(0.5, linestyle = ":")
plt.show()

结果:

enter image description here

关于python - 组合时间序列中的相似信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47780379/

相关文章:

python - 替换 Python 字典中的值

shell - 在 Python 脚本的末尾使用 sys.exit(0) 是一种好习惯吗?

iphone - 使用超声波传输数据

c - 如何使用傅里叶变换从 WAV 文件中提取半精确频率

python - 在 Python 中解析 TCL 列表

python - 缩短字典中键的长度

regex - 如何使用python脚本在linux中压缩多个文件?

在倍频程上绘制 FFT

Python:替换 CSV 文件中的数据

python-3.x - 动态更新数据框的某些列