/// <summary> /// Transform the specified input. /// </summary> /// <returns>The transform.</returns> /// <param name="input">Input.</param> public List <SensorReading> Transform(IEnumerable <ICsvWritable> input) { const decimal alpha = 0.8M; List <SensorReading> output = new List <SensorReading>(); foreach (SensorReading reading in input) { decimal xAccel = reading.AccelX, yAccel = reading.AccelY, zAccel = reading.AccelZ; GRAVITY[ACCEL_X] = alpha * GRAVITY[ACCEL_X] + (1 - alpha) * xAccel; GRAVITY[ACCEL_Y] = alpha * GRAVITY[ACCEL_Y] + (1 - alpha) * yAccel; GRAVITY[ACCEL_Z] = alpha * GRAVITY[ACCEL_Z] + (1 - alpha) * zAccel; decimal newAccelX = (xAccel - GRAVITY[ACCEL_X]), newAccelY = (yAccel - GRAVITY[ACCEL_Y]), newAccelZ = (zAccel - GRAVITY[ACCEL_Z]); SensorReading newReading = new SensorReading(reading); newReading.SetAccelVector(newAccelX, newAccelY, newAccelZ); output.Add(newReading); } return(output); }
/// <summary> /// Transform the specified input. /// </summary> /// <returns>The transform.</returns> /// <param name="input">Input.</param> public List <SensorReading> Transform(IEnumerable <ICsvWritable> input) { var emaAzimuth = new ExponentialMovingAverage(); var emaPitch = new ExponentialMovingAverage(); var emaRoll = new ExponentialMovingAverage(); var emaAccelX = new ExponentialMovingAverage(); var emaAccelY = new ExponentialMovingAverage(); var emaAccelZ = new ExponentialMovingAverage(); var output = new List <SensorReading>(); foreach (SensorReading reading in input) { var newReading = new SensorReading(reading); newReading.SetGyroVector(emaAzimuth.GetAverage(reading.Azimuth), emaPitch.GetAverage(reading.Pitch), emaRoll.GetAverage(reading.Roll)); newReading.SetAccelVector(emaAccelX.GetAverage(reading.AccelX), emaAccelY.GetAverage(reading.AccelY), emaAccelZ.GetAverage(reading.AccelZ)); output.Add(newReading); } return(output); }