【问题标题】:filtering signal eliminate neighbouring peaks matlab滤波信号消除相邻峰matlab
【发布时间】:2023-03-08 13:26:01
【问题描述】:

我想过滤一个非常嘈杂的信号,以便获得超过某个阈值的峰值数量。这是我使用的matlab代码:

thresh = 3;  % Specify threshold
x = VarName1; 
% Essentially need to pick out values which exceed threshold with the condition that the previous value  
% needs to be below the threshold
idxl = x>=thresh;
idxl(1) = 0;
idx = find(idxl);
yest = x(idx-1)<thresh; 
idx(yest)  % Final output

但是我得到的值太高了,事实上,当我在图中找到峰值时,它还识别出跨越阈值的相邻值,如附图所示。但我想在每次超过阈值时计算一个峰值。你知道我该怎么做吗? image_matlab

【问题讨论】:

    标签: matlab filtering threshold


    【解决方案1】:

    假设您有峰的索引,那么为了计算它们,您必须对它们进行分段。这很容易通过获取索引之间的差异,然后应用某个阈值,即每个峰值之间的最小距离来完成。

    peaks = unique([randi([100,110],1,randi(10)),randi([150,160],1,randi(10)),randi([210,220],1,randi(10))]); %Create some peaks
    thresh = 20; %Set a threshold
    nextPeak = diff([-inf,peaks])>thresh; % Find peak seperators
    

    如果您对峰值的数量感兴趣,您可以只计算分隔符的数量,例如

    NumPeaks = sum(nextPeak);
    

    如果您对峰的位置感兴趣,您将不得不决定如何定义“峰”,它是峰的中心点还是最大值等?

    在所有情况下,您都必须经历峰值的数量

    nextPeakIdx = [find(nextPeak),length(peaks)+1];
    for i = 1:length(nextPeakIdx)-1
        peakIdx = peaks(nextPeakIdx(i):(nextPeakIdx(i+1)-1));
        %Decide which index to keep
    end
    

    【讨论】:

    • 使用您分享的第一个代码我收到以下错误:Error using horzcat
    • 有趣,它对我有用。三行中的哪一行给了你错误?请张贴。
    • 这是行:nextPeak = diff([-inf,peaks])>thresh; % 查找峰值分隔符
    • 你的“peaks”变量是什么样子的?
    【解决方案2】:

    Matlab 有一个 findpeaks() 函数,应该适用于您的情况。特别是,您可以将 MinPeakDistance 参数设置为智能量以仅检测您想要的峰值。

    % Build some noisy signal
    signal = peaks;  
    signal = repmat(signal(18,:) , 1,3);
    noisy_signal = signal + randn(1,3*49).*0.5;
    
    % Find peaks and plot them
    findpeaks(noisy_signal , 'MinPeakDistance' , 15);
    hold on;
    plot(signal)
    

    这是我得到的,黄线是原始信号,蓝色是噪声信号,箭头指向检测到的峰值(当然是在噪声信号中)。 你只需要调整你的 MinPeakDistance 参数。

    【讨论】:

    • 感谢您的回答,您知道是否也可以设置阈值吗?例如,如果我只想提取大于 2 个单位的峰值?
    • findpeaks 是一个不错的函数,但特别是在这种情况下,OP 的顶部已被切断,它作为一个黑盒函数受到了很大的影响。尝试将您的数据调整为noisy_signal(noisy_signal&gt;2)=2+0.001*randn(1,3*49);,然后峰值不是很明确。
    猜你喜欢
    • 2017-08-14
    • 2012-09-07
    • 2020-11-28
    • 2011-10-26
    • 2012-09-22
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多