随机采集到的数据,怎么找峰值?
从串口采集上来的数据,横左边和纵坐标分别存在一个数据里,要实时的画曲线并要找到曲线的峰值,请大侠们说一说怎么能找出峰值啊?提供一下思路。
谢谢!
[最优解释]
这就得看楼主如何界定了, 如果只要某点相邻的左右两点的值都比它小就算. 那信号噪点会送你一堆峰值.
如果想把噪音去除,就要先对采集到的信号滤波.
然后就是楼书如何界定范围了,到底多大范围内的最高值才算一个峰值? 10个采集信号还是1000个呢?
超过平均值多少才算峰值?这也是一个阀值的控制.
所以楼主还需要好好定下心来把这些问题研究清楚才能动手.
否则冒冒失失写出来的代码实在无法帮助你分析数据.
[其他解释]
这个正弦曲线的更好看些
Option Explicit
Dim intIndex As Integer
Private Type Point
x As Long
y As Double
End Type
Rem 记录曲线上三个点,如果中间比两边的大,或者比两边的小,表示这是一个拐点
Dim DataOne As Point
Dim DataTwo As Point
Dim DataThree As Point
Private Sub Form_Load()
With picMap
.ScaleMode = 3
.AutoRedraw = True
.Width = 8775
.Height = 4815
End With
picMap.Scale (0, 11)-(500, -1) '定义坐标系统
DataOne.x = 0
DataOne.y = 0
DataTwo.x = 0
DataTwo.y = 0
DataThree.x = 0
DataThree.y = 0
Timer1.Interval = 20
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim intP As Integer
Dim intT As Integer
Dim lngP As Long
If intIndex > 500 Then
Timer1.Enabled = False
Exit Sub
End If
DataOne.x = DataTwo.x
DataOne.y = DataTwo.y
DataTwo.x = DataThree.x
DataTwo.y = DataThree.y
DataThree.x = intIndex
DataThree.y = 5 * Sin(intIndex * 2 * 3.1415926 / 500) + 5
intIndex = intIndex + 1
If intIndex <= 2 Then Exit Sub
If intIndex = 3 Then picMap.PSet (DataThree.x, DataThree.y)
picMap.Line (DataOne.x, DataOne.y)-(DataTwo.x, DataTwo.y)
If DataTwo.y > DataOne.y And DataTwo.y > DataThree.y Then
picMap.Circle (DataTwo.x, DataTwo.y), 2, vbRed
End If
If DataTwo.y < DataOne.y And DataTwo.y < DataThree.y Then
picMap.Circle (DataTwo.x, DataTwo.y), 2, vbRed
End If
End Sub
Option Explicit
Dim intIndex As Integer
Private Type Point
x As Long
y As Double
End Type
Rem 记录曲线上三个点,如果中间比两边的大,或者比两边的小,表示这是一个拐点
Dim DataOne As Point
Dim DataTwo As Point
Dim DataThree As Point
Private Sub Form_Load()
With picMap
.ScaleMode = 3
.AutoRedraw = True
.Width = 8775
.Height = 4815
End With
picMap.Scale (0, 11)-(50, -1) '定义坐标系统
DataOne.x = 0
DataOne.y = 0
DataTwo.x = 0
DataTwo.y = 0
DataThree.x = 0
DataThree.y = 0
Timer1.Interval = 500
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim intP As Integer
Dim intT As Integer
Dim lngP As Long
If intIndex > 500 Then
Timer1.Enabled = False
Exit Sub
End If
DataOne.x = DataTwo.x
DataOne.y = DataTwo.y
DataTwo.x = DataThree.x
DataTwo.y = DataThree.y
DataThree.x = intIndex
DataThree.y = 7 + 3 * Rnd
intIndex = intIndex + 1
If intIndex <= 2 Then Exit Sub
If intIndex = 3 Then picMap.PSet (DataThree.x, DataThree.y)
picMap.Line (DataOne.x, DataOne.y)-(DataTwo.x, DataTwo.y)
If DataTwo.y > DataOne.y And DataTwo.y > DataThree.y Then
picMap.Circle (DataTwo.x, DataTwo.y), 0.2, vbRed
End If
If DataTwo.y < DataOne.y And DataTwo.y < DataThree.y Then
picMap.Circle (DataTwo.x, DataTwo.y), 0.2, vbRed
End If
End Sub
select * from my_table where y in(select max(y) from my_table)