algorithm - 使用循环对数据进行分组(MATLAB 中的信号处理)

标签 algorithm matlab for-loop while-loop signal-processing

我在 MATLAB 中处理由连续下降组成的信号数据,如下所示。我正在尝试编写一个代码,将每个浸渍的内容分类到一个单独的组中。这样的代码的一般结构应该是什么样的?

以下是我的数据。我只对低于某个阈值 d(红线)的信号部分感兴趣:

Signal

这是所需的分组:

Grouping

这是一个不成功的尝试:

k=0; % Group number

for i = 1 : length(signal)
    if signal(i) < d
        k=k+1;
        while signal(i) < d
            NewSignal(i, k) = signal(i);
            i = i + 1; 
        end
    end
end

上面的代码生成了 310 个组,而不是所需的 12 个组。

如有任何解释,我们将不胜感激。

最佳答案

使用 Benl 生成的数据,您可以执行以下操作:

%generate data
x=1:1000;
y=sin(x/20);
for ii=1:9
    y=y+-10*exp(-(x-ii*100).^2./10);
end
y=awgn(y,4);


%set threshold
t=-4;
%threshold data
Y = char(double(y<t) + '0'); %// convert to string of zeros and ones
%search for start and ends

这个想法被采纳了from here

[s, e] = regexp(Y, '1+', 'start', 'end');

%and now plot and see that each pair of starts and end
% represents a group
plot(x,y)
hold on
for k=1:numel(s)
line(s(k)*ones(2,1),ylim,'Color','k','LineStyle','--')
line(e(k)*ones(2,1),ylim,'Color','k','LineStyle','-')
end
hold off
legend('Data','Starts','Ends')

Processed Data

评论:首先我选择了一个任意的阈值,你可以在你的数据中找到“最好的”那个。此外,我没有明确地对数据进行分组,而是这种方法为您提供了每个时期的开始和结束时的下降(您可以称之为分组)。所以你可以说每个索引都是分组索引。最后,我没有针对极端情况调试这种方法,当下降落在开始和结束时......

关于algorithm - 使用循环对数据进行分组(MATLAB 中的信号处理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55868182/

相关文章:

python - 如何合并两个链表

arrays - 如何在调用 MATLAB 的 arrayfun 时捕获多个返回值?

c - 循环展开以将两个矩阵 NxN 相乘?

python : How to check if input is not equal to any item in a 2d array?

algorithm - 换币算法

algorithm - 4 字节散列算法比较小文本(通常小于 2 kb)

algorithm - 协作投票算法的用户分布

matlab - 简化查找阿姆斯特朗数的代码

c++ - 具有多个函数的类对象的 MATLAB MEX 接口(interface)

swift - 如何在swift中的for循环中使用异步任务