decimateData<T> method
Decimates input data by reducing the sampling rate.
Reduces data size by keeping every nth sample where n is the decimation factor calculated from the ratio of actual rate to target rate. Used for downsampling high-frequency sensor data when lower resolution is sufficient for analysis.
Returns the decimated data list with reduced sample count.
Implementation
List<T> decimateData<T>(List<T> input, double targetRate, double actualRate) {
if (actualRate <= 0 || targetRate <= 0) return input;
int decimationFactor = (actualRate / targetRate).round();
if (decimationFactor <= 1) return input;
// Keep every nth sample based on decimation factor
return input
.asMap()
.entries
.where((e) => e.key % decimationFactor == 0)
.map((e) => e.value)
.toList();
}