You may try these algorithms to check if they can solve at least some of your requirements:
#include "Streaming.h"
const int DeltaThreshold = 200;
const int MaxThreshold = 350;
const int MinThreshold = 20;
int data[10 * 10]; // 10 data per second for 10 seconds
int dataLength = sizeof(data) / sizeof(data[0]);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
CreateData(8, 5, 405);
PrintData();
EvaluateDataChanges();
EvaluateTimeBetweenMaxMins();
}
void loop() {
// put your main code here, to run repeatedly:
}
void PrintData() {
for (int i = 0; i < dataLength; i++) {
if (i % 10 == 0) Serial << "\n";
Serial << data[i] << "\t";
}
Serial << "\n\n";
}
void EvaluateDataChanges() {
int Count = 0;
int CountChanges = 0;
for (int i = 0; i < dataLength - 1; i++) {
if (abs(data[i] - data[i + 1]) > DeltaThreshold) CountChanges++;
}
Serial << "No of Data Changes = " << CountChanges << "\n";
if (CountChanges == 0) {
if (data[0] > MaxThreshold ) Serial << "Data are HIGH";
if (data[0] < MinThreshold ) Serial << "Data are LOW";
}
Serial << "\n";
}
void EvaluateTimeBetweenMaxMins() {
int lastMaxPos = -1;
int lastMinPos = -1;
for (int i = 1; i < dataLength - 1; i++) {
if (abs(data[i] - data[i + 1]) > DeltaThreshold) {
if (data[i] > MaxThreshold) {
if (lastMaxPos >= 0) Serial << "MaxDiff = " << i - lastMaxPos << "\n";
lastMaxPos = i;
}
if (data[i] < MinThreshold) {
if (lastMinPos >= 0) Serial << "MinDiff = " << i - lastMinPos << "\n";;
lastMinPos = i;
}
}
}
Serial << "\n";
}
boolean CreateData(int Periode, int Min, int Max) { // Periode = 10 -> 1 Hz Periode
// assuming a measurement every 100 msec
int count = Periode / 2;
boolean writeMin = true;
for (int i = 0; i < dataLength; i++) {
count--;
if (count <= 0) {
count = Periode / 2;
writeMin = !writeMin;
}
data[i] = writeMin ? Min + random(10) : Max + random(10);
}
}
I have programmed a simple routine to create some test data (which might not really cover your raw data!). You can play around with this routine to create different kinds of "wave forms" ...
CreateData(8, 5, 405);
The first parameter gives a periode of the same number of highs and lows in 100 msecs (so 10 means 500 msec high, 500 msec low). The second is the low value , the third is the max value (which both get a random(10) added).
The data are stored in an array of 10 data per second for 10 seconds (10x10 = 100 data).
EvaluateDataChanges()
Counts the numbers of "edges" which are defined by a difference between two adjacent data of more than DeltaThreshold.
if no changes are detected, it returns whether data[0] is higher than MaxThreshold or lower than MinThreshold (should equal LED constantly on or off).
EvaluateTimeBetweenMaxMins()
Returns the difference between edges high to high and low to low. which is a measure for slow or quick blinking.
It works with artificial data and is a "quick shot", success or not also depends on your raw data. At least I hope you get the idea and may develop further from here ...
If you still have problems, feel free to post your raw data.
I created and checked the test sketch here:
https://wokwi.com/projects/326101695584010835