You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Python识别带噪声时序信号的稳定起始点

高噪声时序信号稳态起始点自动识别Python实现

噪声信号时序图

核心思路

高噪声信号的稳态本质是滑动窗口内的统计特征收敛到稳定阈值范围,结合你给出的1~2000的预搜索区间,可以大幅降低误判概率,核心逻辑如下:

  • 先对原始信号做滑动平均平滑,过滤高频毛刺噪声
  • 在搜索区间内滑动计算指定窗口的信号方差
  • 找到第一个连续N个窗口方差均低于预设阈值的位置,即为稳态起始点

完整实现代码

import numpy as np

def find_stable_start(x, y, search_start=1, search_end=2000, 
                      smooth_window=5, stat_window=20, 
                      var_threshold=0.05, min_consecutive=5):
    """
    查找高噪声时序信号进入稳态的起始x值
    参数:
        x: 输入x轴数组
        y: 输入对应y值数组
        search_start: 预搜索区间左边界
        search_end: 预搜索区间右边界
        smooth_window: 滑动平均窗口大小,用于过滤高频噪声
        stat_window: 计算方差用的统计窗口大小
        var_threshold: 稳态判定的方差阈值
        min_consecutive: 连续满足方差要求的窗口数,避免偶发误判
    返回:
        稳态起始对应的x轴取值
    """
    # 截取预搜索区间内的信号
    search_mask = (x >= search_start) & (x <= search_end)
    x_search = x[search_mask]
    y_search = y[search_mask]
    
    # 滑动平均平滑去噪
    y_smooth = np.convolve(y_search, np.ones(smooth_window)/smooth_window, mode='same')
    
    # 滑动计算每个窗口的方差
    window_vars = np.array([
        np.var(y_smooth[i:i+stat_window]) 
        for i in range(len(y_smooth) - stat_window + 1)
    ])
    
    # 查找连续满足阈值的起始位置
    satisfy = window_vars < var_threshold
    count = 0
    start_idx = -1
    for i in range(len(satisfy)):
        if satisfy[i]:
            count += 1
            if count == min_consecutive:
                start_idx = i - min_consecutive + 1
                break
        else:
            count = 0
    
    if start_idx == -1:
        raise ValueError("指定区间内未识别到稳定区间,请调整阈值或窗口参数")
    
    return x_search[start_idx]

测试用例

# 构造模拟带噪信号测试
x = np.arange(0, 3000)
# 前100个点为上升过渡段,后2900个点为稳态加高斯噪声
y = np.concatenate([
    np.linspace(0, 10, 100) + np.random.normal(0, 0.5, 100),
    np.random.normal(10, 0.2, 2900)
])

stable_start_x = find_stable_start(x, y)
print(f"稳态起始点x值:{stable_start_x}")

调参说明

  • 若信号噪声极高,可适当调大smooth_window参数,增强去噪效果
  • 方差阈值var_threshold可先手动计算你目测的稳定区间内的方差,取该值的1.2~1.5倍即可
  • 若存在偶发低方差波动导致误判,可调大min_consecutive参数
  • 若信号整体幅值变化大,可将方差判定替换为变异系数(方差/窗口均值),消除幅值影响

内容的提问来源于stack exchange,提问作者Rishabh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 00:24:03