# Linear Acceleration Without Gravity

Hello,

I am trying to get the user-generated acceleration, which is the linear acceleration without the gravity reading. Is there something in the library that returns that result, similar to Apple's `<span>CMDeviceMotion</span>` object that contains that info (https://developer.apple.com/documentation/coremotion/getting_processed_device-motion_data)? If not, is there a calculation I can do with the accessible sensor outputs?

Andy

Hi @[email protected]

Thank you for the response. I understand the way accelerometer readings are handled by the SDK. My question was more about how to eliminate the acceleration due to gravity from the accelerometer reading. For example, to do this when the device is lying flat on a table, we simply have to add 1 to the z component of the acceleration vector, resulting in an acceleration vector of [0,0,0]. However, when the device is lying at an angle, that acceleration due to gravity acts on multiple axes of the device, and the math to subtract gravity from the accelerometer reading becomes more difficult.

I have spent some time looking into this and came up with a solution using the rotation and acceleration readings returned from the SDK.

Referencing the links below, I put wrote a function in Swift that works close enough to what I was aiming for. When the device is at rest, the acceleration vector's values are within 0.05. You have to enable the rotation and
accelerometer sensors of the device, and then use the two reading as inputs for this function, and the output is the acceleration due to the user's movements:

```func userAcceleration(rawAcceleration: Vector, rotation: Quaternion) -> Vector {
let gravityVectorInWorldCoordinates = Vector(0, 0, 1)
let accelerationInWorldCoordinated = rotation.act(rawAcceleration)
return accelerationInWorldCoordinated - gravityVectorInWorldCoordinates
}```

In my opinion, userAcceleration is a useful property to have accessible to developers, so they don't have to read up on Quaternions. Perhaps Bose could include it in a future release of their SDK.

References:
https://stackoverflow.com/questions/18252692/gravity-compensation-in-accelerometer-data
https://developer.apple.com/documentation/accelerate/simd/working_with_quaternions

• @andynovak12
Thanks for your question.   Here's a link to the accelerometer sensor documentation:
https://developer.bose.com/docs/ios-wearable-sdk/4.0.11/sensors-and-coordinate-system.html

This explains how we handle the accelerometer.

### Accelerometer

• Measures acceleration minus the force of gravity
• Provides 3-dimensional vector values
• Unit: g = 9.81 ms-2

#### Example

If the device lying flat on a table, the accelerometer reading would be approximately (0, 0, -1). This is the acceleration of the device minus the force of gravity along the Z-axis: (0, 0, 0) - (0, 0, 1) = (0, 0, -1).

I hope that helps.

@[email protected]

• @andynovak12

Fantastic work here!   I'll be happy to forward your comments here to our team and submit them as a potential feature request for a future SDK.

@[email protected]