countStsCyclesThigh method

List<Cycle> countStsCyclesThigh({
  1. required List<SensorEvent> accData,
  2. required List<SensorEvent> gyroData,
  3. required double accActualRate,
  4. required double gyroActualRate,
})

Detects sit-to-stand cycles for thigh 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> countStsCyclesThigh({
  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 filteredGyro = smoothingFilter(gyroData, windowSize);
  movingAverageFilteredData = filteredGyro;
  final gyroX = filteredGyro.map((e) => e.x).toList();
  final timestamps = filteredGyro.map((e) => e.timestamp).toList();

  final minY = gyroX.reduce(min);
  final maxY = gyroX.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(gyroX, timestamps, peakThreshold, minPeakDistanceSec);
  final troughs = detectTroughs(gyroX, 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: filteredGyro,
    timestamps: timestamps,
    minCycleDuration: minCycleDuration,
  );

  return cycles;
}