countStsCyclesChest method
List<Cycle>
countStsCyclesChest({
- required List<
SensorEvent> accData, - required List<
SensorEvent> gyroData, - required double accActualRate,
- required double gyroActualRate,
Detects sit-to-stand cycles for chest sensor placement.
accData - List of accelerometer events.
gyroData - List of gyroscope events.
accActualRate - Actual accelerometer sampling rate.
gyroActualRate - Actual gyroscope sampling rate.
Returns a list of detected Cycles.
Implementation
List<Cycle> countStsCyclesChest({
required List<SensorEvent> accData,
required List<SensorEvent> gyroData,
required double accActualRate,
required double gyroActualRate,
}) {
const double windowSize = 30;
const double minPeakDistanceSec = 0.3;
const double minCycleDuration = 0.3;
// 1. Smooth signals
final accDataWithoutGravity = accData.map((e) => SensorEvent(e.x, e.y - 9.81,e.z, e.timestamp)).toList();
final filteredAcc = smoothingFilter(accDataWithoutGravity, windowSize);
movingAverageFilteredData = filteredAcc;
final accY = filteredAcc.map((e) => e.y).toList();
final timestamps = filteredAcc.map((e) => e.timestamp).toList();
final minY = accY.reduce(min);
final maxY = accY.reduce(max);
final range = maxY - minY;
final peakThreshold = minY + range * 0.6;
final troughThreshold = maxY - range * 0.75;
if (kDebugMode) {
print('peakThreshold:$peakThreshold, troughThreshold: $troughThreshold');
}
// 2. Detect peaks and troughs
final peaks = detectPeaks(accY, timestamps, peakThreshold, minPeakDistanceSec);
final troughs = detectTroughs(accY, timestamps, troughThreshold, minPeakDistanceSec / 2);
if (kDebugMode) {
print('[StsProcessor] peaks.length: ${peaks.length}, troughs.length: ${troughs.length}');
}
// 3. Detect cycles
final cycles = detectCycles(
peaks: peaks,
troughs: troughs,
filteredAcc: filteredAcc,
timestamps: timestamps,
minCycleDuration: minCycleDuration,
);
return cycles;
}