Help on Durection Cosine Matrix

Hi,
I'm working on bno055 9-axis sensor of adafruit to achieve this aim: wearing it a the level of the thigh it has, by means of thresholds recognizes when the leg is forward and when the leg is backward during a gait cycle. I started measuring the only acelleration, taking in consideration the literature. Right now I would like to have the same behavior considering the angle made from the leg. I bought this sensor to access to that yaw driftless. It works, but when I change direction of walking, the sensor is still fixed to the earth frame obviously. Later I point to quaternion to have more accuracy. I was looking that more people were in difficulty and I don't see a clarification of doubts. I need to express the orientation of the sensor with respect to a world (W) frame fixed on its base segment. I found days ago this topics in the forum. I would like to tag the sir Jremington. You are experienced about it I guess. Can you point me to the way to solve my problem?
@jremington

You have assumed that the BNO055 or similar orientation sensor is the best way to measure what you want to measure.

I don't think it is, and suggest to look for a simpler and better method. Sorry.

Are you trying to measure gait with regards to Parkinson's???

Nope, I am trying to detect the events only

What, in your opinion, is the best method to measure movement of limbs of the body?

That would be the method that meets the design requirements and that the investigator is capable of implementing.