如何提取和绘制阵列的最小和最大峰值,分析 - 使用Matlab或excel [英] How to extract and plot only minimal and maximal peaks of an array , -graph analysis- With Matlab or excel
问题描述
我在做视频分析。
我得到的最终结果数组是这样的:
I'm doing video analysis.
The end result array I get is something like:
signal =
Columns 1 through 7
73960 73960 73960 73960 68102 68102 68102
Columns 8 through 14
68102 19187 19187 19187 19187 14664 14664
Columns 15 through 21
14664 14664 13715 13715 13715 13715 30832
Columns 22 through 28
30832 30832 30832 53031 53031 53031 53031
Columns 29 through 35
56897 56897 56897 16104 16104 16104 16104
Columns 36 through 42
15188 15188 15188 15188 13973 13973 13973
注意:实际数组我得到通常是600 +
Note: actual array I get is usually 600+
所以当我绘制这个,我得到非常糟糕的图表,所以我想过滤这个数组,只保留**最大和最小峰**本地最大值和最小值,以便该图将有更好的波
So when I plot this I get very bad looking graph, so I want to filter this array and only keep the ** maximal and minimal peaks** local maxima and minima so that the graph would have nicer waves
有没有办法可以用MATLAB?
Is there a way I can do it with MATLAB?
如果不能,我可以用excel吗?
,因为我通常将此数组保存到excel表格像这样
if not then can I do it with excel? as I usually save this array to excel sheet Like this
0.1 68102
0.15 19187
0.2 14664
0.25 13715
0.3 30832
0.35 53031
0.4 56897
0.45 16104
0.5 15188
0.55 13973
0.6 21437
0.65 66950
0.7 65356
0.75 22562
0.8 14154
0.85 13938
0.9 20692
0.95 72823
1 69975
1.05 15328
1.1 14494
1.15 13681
1.2 14205
1.25 65278
1.3 63055
1.35 16999
1.4 14050
1.45 14245
其中第一列是时间(y轴),第二列是幅度(x轴)
In which the 1st column is the time(y-axis) and 2nd column is the amplitude.(x-axis)
我使用这个公式计算局部最大值(感谢来自stackoverflow.com的 brettdj )
I use this formula to count local maxima (Thanks to brettdj from stackoverflow.com)
=SUMPRODUCT(--(B2:B149>B1:B148),--(B2:B149>B3:B150))
这个公式计算当地最小值
And this formula to count local minima
=SUMPRODUCT(--(B2:B149<B1:B148),--(B2:B149<B3:B150))
但是什么我需要的是过滤数组,只保留本地最大值和局部最小值,所以我可以得到很好的绘制曲线无噪音。
But what I need is to filter the array to only keep local maxima and local minima so I can get nicely drawn curve without noise.
推荐答案
如果你想要的最大值和最小值只是使用:
If you want the maximum and minimum values just use:
[sig_min, idx_min] = min(signal);
[sig_max, idx_max] = max(signal);
但是,我无法理解你想要什么...因为我的帐户是新的,我无法评论你的问题尝试了解更好。
But I couldnt understand exactly what you want… since my account is new, I cant comment on your question to try to understand it better.
- 编辑1:
好的,现在我明白你想要什么我不知道为什么你有这个数组有重复的数字,但假设你不想要它们,或者至少最好删除它们来找到本地的最大值和最小值,你应该这样做:
Ok, now I understand what you want. I don't know why you have this array with repetitive numbers, but supposing you don't want them, or, at least, that is better to remove them to find local maxima and minima, you should do:
sinal_norep = signal(find(diff(sinal)));
其中,signal_norep将是您的新数组,其中仅包含与上一个不同的值:
where signal_norep will be your new array containing only values that differs from the last one:
现在,我们可以通过执行以下操作来搜索本地最大值和最小值出现的索引:
Now we can search for the index where occurs local maxima and minima on this array, by doing:
minimas_idx = find(signal_norep(2:end-1)<signal_norep(1:end-2) & signal_norep(2:end-1)<signal_norep(3:end))+1;
maximas_idx = find(signal_norep(2:end-1)>signal_norep(1:end-2) & signal_norep(2:end-1)>signal_norep(3:end))+1;
他们的价值观:
signal_maximas = signal_norep(maximas_idx);
signal_minimas = signal_norep(minimas_idx);
这样它x)
这篇关于如何提取和绘制阵列的最小和最大峰值,分析 - 使用Matlab或excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!