寻找峰值MATLAB [英] Finding peaks MATLAB

查看:411
本文介绍了寻找峰值MATLAB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个向量,它包含图像一行中的灰度级像素。 vec = IM(:,65);
我展示了我要检测的数组部分。这些部分将是我的对象'piksels。

I have a vector which includes a gray levels of pixels in a one line of an image. vec=IM(:,65); I showed the parts of the array I want to detect. These parts will be my objects' piksels.

如何检测这些对象像素?

How can I detect these object pixels?

vec的情节:

矢量在这里:
vec

推荐答案

这可以通过 findpeaks 。具体来说,对于您的数据我不得不这样称呼:

This can easily be solved using findpeaks from the Signal Processing Toolbox. Specifically, for your data I had to call it this way:

[pks, locs] = findpeaks(max(vec)-vec, 'minpeakdistance', 160, 'minpeakheight', 22);

findpeaks 仅发现正峰值(局部最大值) )。因此,我们需要做的是将其反转,以便所有局部最小值成为局部最大值。我通过获取向量的最大值并用向量减去来做到这一点。因为有很多局部峰值, minpeakdistance 字段允许您在每个峰值之间找到至少相隔很多的峰值。我将其调整为160.此外,最小峰高会发现大于某个数字的峰值,我将其调整为22. pks 查找实际峰值并且 locs 为您提供信号中峰值的位置。我们需要使用 locs 来查找实际的峰值数据,因为我们在信号的镜像反射版本上执行了此操作。因此,要获得实际的峰值数据,请执行以下操作:

findpeaks only finds positive peaks (local maxima). As such, what we need to do is invert this so that all of the local minima become local maxima. I did this by taking the maximum value of the vector and subtracting with the vector. Because there are so many local peaks, the minpeakdistance field allows you to find peaks that are at least separated by this much in between each peak. I tuned this to 160. Also, the minimum peak height finds peaks that are greater than a certain number, which I tuned to be 22. pks finds the actual peak values and locs gives you the locations of the peaks in your signal. We need to use locs to find the actual peak data because we performed this on the mirror reflected version of your signal. As such, to get the actual peak data, do this:

pks_final = vecs(loc);

作为演示,让我们绘制此信号以及<$ c $所定位的峰值c> findpeaks :

As a demonstration, let's plot this signal as well as the peaks that were located by findpeaks:

plot(1:numel(vec), vec, locs, vec(locs), 'r.');

原始数据以蓝色绘制,而检测到的峰以红色绘制。这就是我得到的:

The original data is plotted in blue while the detected peaks are plotted in red. This is what I get:

祝你好运!

这篇关于寻找峰值MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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