How to find coordinates xyz with Gyros/Accelerometer

I bought gyros lsm9ds0 of FLORA (gyros/accelerometer/magnometer/tamp)
and I tried to figure how I can calculate all the data to coordinates x y z
I tried to calculatet with the accelerate and physica’s fomulas
and I got wrongs valus…
This sensor is very noisy
Mabye some one here would help me
This is the code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM9DS0.h>
#include <math.h>

//MY Additionals
/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),
   which provides a common 'type' for sensor data and some helper functions.
   To use this driver you will also need to download the Adafruit_Sensor
   library and include it in your libraries folder.

   You should also assign a unique ID to this sensor for use with
   the Adafruit Sensor API so that you can identify this particular
   sensor in any data logs, etc.  To assign a unique ID, simply
   provide an appropriate value in the constructor below (12345
   is used by default in this example).
   Connections (For default I2C)
   Connect SCL to analog 5
   Connect SDA to analog 4
   Connect VDD to 5V DC
   Connect GROUND to common ground

   2014/JULY/25  - First version (KTOWN)
/* Assign a unique base ID for this sensor */   
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(1000);  // Use I2C, ID #1000

/* Or, use Hardware SPI:
  G_SDO + XM_SDO -> tied together to SPI MISO
  then select any two pins for the two CS lines:

#define LSM9DS0_XM_CS 10
#define LSM9DS0_GYRO_CS 9

#define LSM9DS0_SCLK 13
#define LSM9DS0_MISO 12
#define LSM9DS0_MOSI 11

void configureSensor(void)
  // 1.) Set the accelerometer range
  // 2.) Set the magnetometer sensitivity

  // 3.) Setup the gyroscope

void setup(void) 
#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  Serial.println(F("LSM9DS0 9DOF Sensor Test")); Serial.println("");
  /* Initialise the sensor */
    /* There was a problem detecting the LSM9DS0 ... check your connections */
    Serial.print(F("Ooops, no LSM9DS0 detected ... Check your wiring or I2C ADDR!"));
  /* Setup the sensor gain and integration time */
  /* We're ready to go! */

  /*restart millis timer*/

    Arduino loop function, called once 'setup' is complete (your own code
    should go here)
void loop(void) 
  /* Get a new sensor event */
  float AccelX, AccelY,AccelZ;
  float DegreesX,DegreesY,DegreesZ;
  double CoordinateX,CoordinateY,CoordinateZ;
  sensors_event_t accel, mag, gyro, temp;
  lsm.getEvent(&accel, &mag, &gyro, &temp); 
  convertAcceleration (&AccelX,&AccelY,&AccelZ,accel.acceleration.x,accel.acceleration.y,accel.acceleration.z); 
  DegreesX=convertMagentic (mag.magnetic.x,accel.acceleration.x,AccelX);
  DegreesY=convertMagentic (mag.magnetic.y,accel.acceleration.y,AccelY);
  DegreesZ=convertMagentic (mag.magnetic.z,accel.acceleration.z,AccelZ);

  // print out accelleration data
  Serial.print("Accel X: "); Serial.print(AccelX); Serial.print(" ");
  Serial.print("  \tY: "); Serial.print(AccelY);       Serial.print(" ");
  Serial.print("  \tZ: "); Serial.print(AccelZ);     Serial.println("  \tm/s^2");
  // print out Degrees data
  Serial.print("Degrees X: "); Serial.print(DegreesX); Serial.print(" ");
  Serial.print("  \tY: "); Serial.print(DegreesY);       Serial.print(" ");
  Serial.print("  \tZ: "); Serial.print(DegreesZ);     Serial.println("  \tdegrees");
  //print out Coordinates data
  Serial.print("Coordinate X: "); Serial.print(CoordinateX); Serial.print(" ");
  Serial.print("  \tY: "); Serial.print(CoordinateY);       Serial.print(" ");
  Serial.print("  \tZ: "); Serial.print(CoordinateZ);     Serial.println("  \tmeter");

  // print out gyroscopic data
  /*Serial.print("Gyro  X: "); Serial.print(gyro.gyro.x); Serial.print(" ");
  Serial.print("  \tY: "); Serial.print(gyro.gyro.y);       Serial.print(" ");
  Serial.print("  \tZ: "); Serial.print(gyro.gyro.z);     Serial.println("  \tdps");
  // print out temperature data
  Serial.print("Temp: "); Serial.print(temp.temperature); Serial.println(" *C");



float previuseAccelX=0,previuseAccelY=0,previuseAccelZ=0;
double previuseTime;
double prevVelocityX=0,prevVelocityY=0,prevVelocityZ=0;
float prevCoordinateX=0,prevCoordinateY=0,prevCoordinateZ=0;
int i=1;
#define PI 3.14159265
void fixAccelaration(float *currAccel){
  if ((*currAccel>-0.07)&&(*currAccel<0.07))
void convertAcceleration(float *AccelX,float *AccelY,float *AccelZ,float currAccelX,float currAccelY,float currAccelZ){
  while (i){
  *AccelX= currAccelX-previuseAccelX;
  *AccelY= currAccelY-previuseAccelY;
  *AccelZ= currAccelZ-previuseAccelZ;
  fixAccelaration(AccelX);  fixAccelaration(AccelY);  fixAccelaration(AccelZ);

float convertMagentic(float currMagnet,float currAccelVector,float Accel){
  float param;
  currMagnet= acos(param)*180.0/PI;
  if (isnan(currMagnet)){
    if (param<0)
  return currMagnet;

void correctDegrees (float *DegreesX,float *DegreesY,float *DegreesZ){
  float uncorrDegreesX, uncorrDegreesY, uncorrDegreesZ;
  if ((uncorrDegreesY>=90)&&(uncorrDegreesY<=180))
  if ((uncorrDegreesX>=90)&&(uncorrDegreesX<=180))
  if ((uncorrDegreesY>=90)&&(uncorrDegreesY<=180))

void getCoordinate(double *currCoordinateX,double *currCoordinateY,double *currCoordinateZ,float AccelX,float AccelY,float AccelZ){
  double currentTime;
  //Calculate Z coodinate