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