How to remove the gravity from accelerometer

Hey, @jremington thank you for the tip and disponibility. I just founded your code today during my researches. Anyway and unfortunately I am a rookie on this kind of task. I am quite a rookie also about C language. Can you teach me how your code could be adapted to the LSM6DS3 sensor? What do I have to change and above all why? I'm sorry if this request could be space off.
I am very confused about the way of reasoning. I found Mahony as Madgcwick as also Kalman.
This is not what I want I guess:

#include "Arduino_LSM6DS3.h"
#include "MadgwickAHRS.h"

// initialize a Madgwick filter:
Madgwick filter;
// sensor's sample rate is fixed at 104 Hz:
const float sensorRate = 104.00;

void setup() {
  Serial.begin(9600);
  // attempt to start the IMU:
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU");
    // stop here if you can't access the IMU:
    while (true);
  }
  // start the filter to run at the sample rate:
  filter.begin(sensorRate);
}

void loop() {
  // values for acceleration and rotation:
  float xAcc, yAcc, zAcc;
  float xGyro, yGyro, zGyro;

  // values for orientation:
  float roll, pitch, heading;
  // check if the IMU is ready to read:
  if (IMU.accelerationAvailable() &&
      IMU.gyroscopeAvailable()) {
    // read accelerometer &and gyrometer:
    IMU.readAcceleration(xAcc, yAcc, zAcc);
    IMU.readGyroscope(xGyro, yGyro, zGyro);

    // update the filter, which computes orientation:
    filter.updateIMU(xGyro, yGyro, zGyro, xAcc, yAcc, zAcc);

    // print the heading, pitch and roll
    roll = filter.getRoll();
    pitch = filter.getPitch();
    heading = filter.getYaw();
//      Serial.print(xAcc);
//  Serial.print(',');
//  Serial.print(yAcc);
//  Serial.print(',');
//  Serial.print(zAcc);
//  Serial.println(',');
//  Serial.print(xGyro);
//  Serial.print(',');
//  Serial.print(yGyro);
//  Serial.print(',');
//  Serial.print(zGyro);
//  Serial.println(',');
 
    Serial.print(heading);
    Serial.print(',');
    Serial.print(pitch);
    Serial.print(',');
    Serial.println(roll);
  }
}