索引周围任意数据点的中位数-MATLAB [英] Median of arbitrary datapoint around index - MATLAB

查看:85
本文介绍了索引周围任意数据点的中位数-MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直很成功地使用findpeaks功能来检测信号中的峰值.我的下一步是清理这些已识别的峰,并为其确定索引.

I've been using the findpeaks function with great success to detect peaks in my signal. My next step is to clean these identified peaks, for which I have the indices.

我的目标是计算给定索引之前的Y数据点的中值和给定索引之后的Y数据点的中值,并用这些新值(计算出的中值)替换任何值(噪声).

My goal is to calculate the median of Y data points before and Y data points after a given index and replace whatever values (noise) there are with these new values (the calculated median).

类似这样的东西:

%  points before, peak, points after
%        ↓         ↓         ↓
x = [1, 2, 3, 1,   34,   3, 2, 1, 3]

计算我的峰值之前和之后的4个数据点的中位数34 ...

Calculate the median of the 4 data points preceding and following my peak the peak of 34...

[1,2,3,1,3,2,1,3]的中位数是2.

用这个新值替换我的峰值:

Replace my peak with this new value:

% Replaced peak with surrounding median
%                  ↓
x1 = [1, 2, 3, 1,  2,  3, 2, 1, 3]

关于如何实施此建议?

推荐答案

查找峰,并将其替换为

Find the peaks and replace them with the results of medfilt1()

[~,idx]=findpeaks(x);
if ~isempty(idx)
    m = medfilt1(x,9);
    x(idx) = m(idx);
end

这篇关于索引周围任意数据点的中位数-MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆