Hi,
I want to trigger an event based on two conditions: at a fixed percentage of a data value of a local maxima, after a local maxima occurs in the data, to turn the event on. Alternatively, at fixed a percentage of the data value where a local minima occurs, to turn the event off. Data values after local maxima will be decreasing and vice versa following a local minima. The data values are pretty much sinusoidal, varying with time, and have some minor peak to peak amplitude variations.
Said more simply, turn on when signal decreases to some percentage of last peak value; turn off when signal value increases some percentage above last minimum value.
The output of the trigger can be binary, 1 when turned it on, 0 when turned off.
I started with the following code to find the maxima and minima, it seems to work:
It's pretty simple but does not account for potential noise in the data.
I am stuck though and need some help getting the trigger points added to the code. Is there anyone in the Forum who could help out with some code to add the on/off trigger?
Thanks for any help,
-Art
I want to trigger an event based on two conditions: at a fixed percentage of a data value of a local maxima, after a local maxima occurs in the data, to turn the event on. Alternatively, at fixed a percentage of the data value where a local minima occurs, to turn the event off. Data values after local maxima will be decreasing and vice versa following a local minima. The data values are pretty much sinusoidal, varying with time, and have some minor peak to peak amplitude variations.
Said more simply, turn on when signal decreases to some percentage of last peak value; turn off when signal value increases some percentage above last minimum value.
The output of the trigger can be binary, 1 when turned it on, 0 when turned off.
I started with the following code to find the maxima and minima, it seems to work:
Code:
Sub FindMaximaMinima()
Application.ScreenUpdating = False
Dim i As Long
Dim Change As Boolean
For i = 1 To Range("B" & Rows.Count).End(xlUp).Row
If Change Then
If Range("B" & i) > Range("B" & i + 1) Then
Range("C" & i) = "Max"
Change = False
End If
Else
If Range("B" & i) < Range("B" & i + 1) Then
Range("C" & i) = "Min"
Change = True
End If
End If
Next i
Application.ScreenUpdating = True
End Sub
It's pretty simple but does not account for potential noise in the data.
I am stuck though and need some help getting the trigger points added to the code. Is there anyone in the Forum who could help out with some code to add the on/off trigger?
Thanks for any help,
-Art