You are here: Forum Home → ANT Developers Forums → ANT+ FIT Forum Has Moved → Thread
private float[] AdjustSensorData(int[] rawData, CalibrationParameters calParams)
{
float[] calibratedValues = new float[rawData.Length];
float[] rotatedValues = new float[rawData.Length];
//Apply the calibration parameters
for (int i = 0; i < rawData.Length; i++)
{
calibratedValues[i] = (float)rawData[i];
calibratedValues[i] -= calParams.LevelShift;
calibratedValues[i] -= calParams.ChannelOffset[i];
calibratedValues[i] *= calParams.CalFactor;
calibratedValues[i] /= calParams.CalDivisor;
}
// Apply the rotation matrix
// [Rotation] * [XYZ]
rotatedValues[0] = (calParams.RotationMatrix[0, 0] * calibratedValues[0])
+ (calParams.RotationMatrix[0, 1] * calibratedValues[1])
+ (calParams.RotationMatrix[0, 2] * calibratedValues[2]);
rotatedValues[1] = (calParams.RotationMatrix[1, 0] * calibratedValues[0])
+ (calParams.RotationMatrix[1, 1] * calibratedValues[1])
+ (calParams.RotationMatrix[1, 2] * calibratedValues[2]);
rotatedValues[2] = (calParams.RotationMatrix[2, 0] * calibratedValues[0])
+ (calParams.RotationMatrix[2, 1] * calibratedValues[1])
+ (calParams.RotationMatrix[2, 2] * calibratedValues[2]);
return rotatedValues;
}