从串口采集上来的数据,横左边和纵坐标分别存在一个数据里,要实时的画曲线并要找到曲线的峰值,请大侠们说一说怎么能找出峰值啊?提供一下思路。
谢谢!

解决方案 »

  1.   

    本帖最后由 bcrun 于 2010-12-14 10:19:44 编辑
      

  2.   


    Option Explicit
    Dim intIndex As Integer
    Private Type Point
        x As Long
        y As Double
    End TypeRem 记录曲线上三个点,如果中间比两边的大,或者比两边的小,表示这是一个拐点
    Dim DataOne As Point
    Dim DataTwo As Point
    Dim DataThree As PointPrivate 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 SubPrivate 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
      

  3.   

    这个正弦曲线的更好看些Option Explicit
    Dim intIndex As Integer
    Private Type Point
        x As Long
        y As Double
    End TypeRem 记录曲线上三个点,如果中间比两边的大,或者比两边的小,表示这是一个拐点
    Dim DataOne As Point
    Dim DataTwo As Point
    Dim DataThree As PointPrivate 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 SubPrivate 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