```
/*SAMPLING*/
for (int i = 0; i < SAMPLES; i++)
{
microseconds = micros(); //Overflows after around 70 minutes!
vReal[i] = euler.y(); //acceleration data generated
vImag[i] = 0;
while (micros() < (microseconds + sampling_period_us)) {
}
}
```

What is this supposed to do?

You don’t know how time calculations on Arduino work and the thing you do try makes that clear.

Unsigned rollover is not a problem when you get difference between 2 times by subtracting start time from end time. It ALWAYS WORKS up to the longest interval the time variables can hold minus 1.

while ( micros() - period_start_time < sampling_period ); // micros is granular to 4usecs

Arduino float and double are the same 32-bit IEEE 6/7 place floating point variables running as slow as could be expected on an 8 bit processor with no FPU.

Whatever frequencies you expect to detect, they need to be much slower than how you intend to detect them.

You can time > 60 milliseconds as 16 bit unsigned microseconds just more than twice as fast as using 32 bit unsigned longs. As long as you use unsigned integers the word length only limits the maximum interval.

You should be able to collect and store 8 analog reads per ms.