Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

CWDSP.Peakdetector with Consecutive Blocks of Data

To whom it may concern,

I encountered a problem while processing CWDSP.Peakdetector with consecutive blocks of data. The result of the peakdetector was incorrect. We generated peaks manually, sometimes single peak and sometimes multiple peaks, but the peakdetection result seems to be incorrect. Most of the times, the peakdetector only return one peak, even if there are multiple peaks, and the peaklocation was located at the end of the peak, not the highest point; the other times, it returned multiple peaks, but the peaks are very close, and it was obviously incorrect.

The data was acquired by NI DAQ-6014 Card. The setting for data acquiring was- number of scans: 20, scan rate: 1 times/second, Data acquiring mode: continuously; the settings for peak detection- width: 5, threshold: 1. I called the sub-program, Sub PeakDetection (ScaledData As Variant), once while the number of scans was satisfied. Since the data acquiring was continuous, the Sub program, PeakDetection(ScaledData As Variant), should receive consecutive blocks of data.

The detail code was listed below; I don�t know where the problem is.

�Define global constants
Dim FirstBlockofData As Boolean
Dim LastBlockofData As Boolean

Dim Peaklocation_0 As Variant
Dim Peakamplitute_0 As Variant
Dim SD_0 As Variant
----------------------------------------------
Private Sub start_Click()
FirstBlockofData = True
LastBlockofData = False
CWAI1.Configure
CWAI1.start
End Sub
-----------------------------------------------
Private Sub stop_Click()
LogPeak
CWAI1.stop
End Sub
-----------------------------------------------

Private Sub CWAI1_AcquiredData(ScaledData As Variant, BinaryCodes As Variant)
CWGraph1.ChartY ScaledData
PeakDetection ScaledData

End Sub

-----------------------------------------------
Sub PeakDetection(ScaledData As Variant)

Dim ConsecutiveBlocksOfData_0(20) As Variant

Dim Thresh As Variant
Dim Widt As Variant
Dim Porv As Variant

Dim iScans As Integer
Dim iChannel As Integer
Dim sData As String

Thresh = Val(CWThreshold.Text)
Widt = Val(CWWidth.Text)
Porv = 0

For iChannel = LBound(ScaledData) To UBound(ScaledData) 'assign the data to each consecutive block of data for every single channel
For iScans = LBound(ScaledData, 2) To UBound(ScaledData, 2)
sData = Format(ScaledData(iChannel, iScans), ".##0") '.###0(below .XXXX) define the orders of effective number
If iChannel = 0 Then
ConsecutiveBlocksOfData_0(iScans) = sData
End If
Next iScans
Next iChannel


If FirstBlockofData = True Then 'The fist block of data
CWDSP1.PeakDetector ConsecutiveBlocksOfData_0, Thresh, Widt, Porv, FirstBlockofData, LastBlockofData, Peaklocation_0, Peakamplitute_0, SD_0
FirstBlockofData = False
Else
CWDSP1.PeakDetector ConsecutiveBlocksOfData_0, Thresh, Widt, Porv, FirstBlockofData, LastBlockofData, Peaklocation_0, Peakamplitute_0, SD_0
End If


End Sub
-----------------------------------------------------------------
Sub LogPeak()
Dim FileNumber_2 As Integer
Dim Chan As CWAIChannel

'Print Peaklocation_0(1)
FileNumber_2 = 2
If overwrite Then
Open PeakLogFile.Text For Output As #FileNumber_2
Else
Open PeakLogFile.Text For Append As #FileNumber_2
End If

For i = LBound(Peaklocation_0) To UBound(Peaklocation_0)
Print Peaklocation_0(i)
Print #FileNumber_2, "No: " & i & vbTab & "Peaklocation: " & Peaklocation_0(i) & vbTab & "Peakamplitute: " & Peakamplitute_0(i)
Print #FileNumber_2,
Next i

'Close the file
Close #FileNumber_2


End Sub
0 Kudos
Message 1 of 2
(5,979 Views)
Hi,

I really don't see anything wrong with your code. I think the behavior you are seeing is mainly due to what your setting is with the "width" parameter. Remember, this function takes a polynomial fit over the data over the range of the width. The peak is then determined based on this polynomial fit. So if your data in that width range is fairly jumpy, a polynomial fit may not fit as well as you expect, and it is not finding any peaks. If you want to be more picky with your peaks, set your width to be extremely small as well.

In your particular case, the width is 5 points. It depends a lot on how fast you move from a peak to a valley, but if it is under 5 seconds, you may miss a peak or a valley. In any case, if there is any confusion about the definit
ion of this function, perhaps a few data points and the peaks that were found on these data points would help explain why the peaks are different than you expect.

Also, perhaps you have a different criteria for peaks that you are looking for that would be best served by another function. I would recommend checking the function definition in the documentation to ensure that it is indeed the function you wish to use.

Best Regards,
Allen P.
National Instruments
0 Kudos
Message 2 of 2
(5,979 Views)