11-17-2015 03:36 AM
Hello,
I am reading in a generated sine wave and it seems to be working correctly, but I need to be able to find the peak as I am going to be comparing the voltage and current of an AC circuit when I get the basics working. The problem I'm having is that the peak detect wont work on the graph as I believe it does not just contain exclusively integer values, is there a way of just taking integer values from the graph and using the peak detect function.
The following is the code I have so far, the daq task was all completed using the wizard so it is just standard.
Public Class Form1 Dim amplitudePeak() As Double Dim waveform() As Double Dim locationPeak() As Double Dim secondDerivativePeak As Double Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim acquiredData() As NationalInstruments.AnalogWaveform(Of Double) = DaqTaskComponent1.Read ACsignal.PlotWaveforms(acquiredData) Catch ex As NationalInstruments.DAQmx.DaqException MessageBox.Show(ex.Message, "DAQ Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) End Try End Sub Private Sub DaqTaskComponent1_Error(sender As Object, e As DAQmx.ComponentModel.ErrorEventArgs) Handles DaqTaskComponent1.Error 'TODO: Handle DAQ errors. Dim message As String = e.Exception.Message MessageBox.Show(message, "DAQ Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) DaqTaskComponent1.StopTask() End Sub Private Sub DetectionOfPeaks() Dim waveform() As Double Dim peakPolarity As NationalInstruments.Analysis.Monitoring.PeakPolarity = Analysis.Monitoring.PeakPolarity.Peaks Dim peakDetect As NationalInstruments.Analysis.Monitoring.PeakDetector = New NationalInstruments.Analysis.Monitoring.PeakDetector ACsignal = waveform 'Detection of Peaks peakDetect.Detect(waveform, True, amplitudePeak, locationPeak, secondDerivativePeak)
This is the main error I am experiencing
Error 3 Value of type '1-dimensional array of Double' cannot be converted to 'NationalInstruments.UI.WindowsForms.WaveformGraph'.
Any help is greatly appreciated!
11-19-2015 10:05 AM
Hello gary,
Is it possible to send me the command that you are using when you are calling DetectionOfPeaks?
Is it also possible to send a screenshot of the error message?
Best regards,
Jonas
National Instruments
Applications Engineer UK&IRE
11-19-2015 10:27 AM
Hi Jonas,
I managed to solve the problem I was having with the peak detect I used the following code to get the peak and number of peaks
Dim acquiredData() As NationalInstruments.AnalogWaveform(Of Double) = DaqTaskComponent1.Read ACsignal.PlotWaveforms(acquiredData) Dim a() As Double a = acquiredData(0).GetScaledData initialthreshold = -2.4 'Setting the initial threshold' initialwidth = 10 'Setting the initial width' 'To detect the associated peaks withing the wave' peakdetect.Reset(initialthreshold, initialwidth, 0) peakdetect.Detect(a, True, amplitudePeak, locationPeak, secondDerivativePeak)
Now the graph is plotting fine, there is one more problem I am having, is there anyway that with the given "a" max amplitude along the Y axis, I am able to get a value for the corresponding X axis value which in this case would be a time value. As I am inputting 2 sine waves and I need to find the difference on the X axis between the 2 peaks. This is what I have so far,
Dim acquiredData() As NationalInstruments.AnalogWaveform(Of Double) = DaqTaskComponent1.Read ACsignal.PlotWaveforms(acquiredData) Dim a() As Double a = acquiredData(0).GetScaledData Dim b() As Double b = acquiredData(1).GetScaledData initialthreshold = -2.4 'Setting the initial threshold' initialwidth = 10 'Setting the initial width' 'To detect the associated peaks withing the wave' peakdetect.Reset(initialthreshold, initialwidth, 0) peakdetect.Detect(a, True, amplitudePeak, locationPeak, secondDerivativePeak) 'To detect the associated peaks withing the wave' peakdetect.Reset(initialthreshold, initialwidth, 0) peakdetect.Detect(b, True, amplitudePeak, locationPeak, secondDerivativePeak) 'To display the number of peaks found in signal numOfPeaksFound = amplitudePeak.Length peaksFoundNumericEdit.Text = numOfPeaksFound peakAmplitudeNumericEdita.Value = a.Max 'To display the number of peaks found in signal numOfPeaksFound = amplitudePeak.Length peaksFoundNumericEdit.Text = numOfPeaksFound peakAmplitudeNumericEditb.Value = b.Max
Thank you for the help it is greatly appreciated!
Gary