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

MATLAB电池内阻序列数据NaN值与异常值去除优化求助

电池内阻序列数据异常值优化处理方案

我有一组包含测量误差和缺失值(NaN)的电池内阻序列数据,已通过inpaint_nans工具包填补NaN值,再用MATLAB的filloutliers函数结合7阶移动均值处理异常值,但处理效果不佳——尤其是索引32附近的尖峰未被有效抑制,寻求优化方案。

当前处理代码:

no_nans = results(52).internal_resistance_no_nans;

no_outliers = filloutliers(no_nans, 'linear','median');

with_mean = movmean(no_outliers,7);

原始数据图:
电池内阻原始数据(索引32附近存在明显尖峰)

优化方案:

  • 调整filloutliers的异常值检测规则
    默认中位数方法对尖锐异常值敏感度不足,可换用基于标准差的检测逻辑,或手动扩大阈值范围:

    % 基于均值+3倍标准差检测异常值,并用线性插值填补
    no_outliers = filloutliers(no_nans, 'linear', 'mean', 'ThresholdFactor', 3);
    % 或基于四分位数,调整阈值因子增强敏感度
    no_outliers = filloutliers(no_nans, 'linear', 'quartiles', 'ThresholdFactor', 1.5);
    
  • 颠倒平滑与异常值处理的顺序
    先做平滑预处理,再检测异常值,避免原始尖峰干扰检测逻辑:

    % 先做7阶移动均值平滑
    pre_smoothed = movmean(no_nans, 7);
    % 再处理异常值
    no_outliers = filloutliers(pre_smoothed, 'linear', 'median');
    % 最后用小窗口二次平滑优化细节
    final_data = movmean(no_outliers, 5);
    
  • 改用更适合的平滑算法
    简单移动均值对尖峰抑制能力有限,可尝试Savitzky-Golay滤波(需Signal Processing Toolbox),它能在保留数据趋势的同时更好地平滑噪声:

    % 3阶多项式拟合,7点窗口的Savitzky-Golay滤波
    sg_filtered = sgolayfilt(no_outliers, 3, 7);
    
  • 针对性处理局部已知尖峰
    针对索引32附近的明确尖峰,直接用相邻正常数据的均值替换:

    target_idx = 32;
    % 取前后2个有效点的均值替换尖峰
    no_outliers(target_idx) = mean(no_outliers(max(1, target_idx-2):min(length(no_outliers), target_idx+2)));
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 00:27:14