How would you implement the following in C or C with 6 and 1

How would you implement the following in C or C++ with 6 and 12 data points?

Source code would be very helpful.

Table 2. Sign definition of sensor raw measurements

Yb up

Accelerometer (signed integer)                                      
Stationary position Ax Ay Az
Zb down 0 0 +1 g
Zb up 0 0 -1 g
Yb down 0 +1 g 0

Yb up

0 -1 g 0
Xb down +1 g 0 0
Xb up -1 g 0 0
Equation 1 1/ A SC A OS 1/ A SC A,, A OS m 1/ A SC A OS Z1 ACC ACC ACC AxT ACC ACC ACC 22 ACC 23 A 20 ACC ACC 32 ACC 33 Az ACC 30 where [A m] is the 3 x 3 misalignment matrix between the accelerometer sensing axes and the device body axes, A SCi (i 3x, y, z) is the sensitivity (or scale factor) and A OSi is the zero-g level (or offset). The goal of accelerometer calibration is to determine 12 parameters from ACC10 to ACC33, so that with any given raw measurements at arbitrary positions, the normalized values A Ay1 and Az1 can be obtained, resulting in: Equation 2 x1 Z1 Calibration can be performed at 6 stationary positions as shown in Table 2. Collect 5 to 10 seconds of accelerometer raw data with ODR 100 Hz at each position with known Ax1, Ay 1 and AZ1. Then apply the least square method to obtain the 12 accelerometer calibration parameters.

Solution

Below given code is used for finding least sqaure method. it is where the output would be stored into the file name given. here row nad coloun size is take as 4 and 3 which would be canged accordingly. The double *calcofcoeffs(double **data) funnction is used to calculate the co efficients

#include <stdio.h>
#include <stdlib.h>
#include <math.h>


double **datareading(char *filename);
void freeData(double **data);
double *calcofcoeffs(double **data);




int main()
{
    char filename[100];
    double **data;
    double *result;


    printf(\"Please Enter The Name Of The File You Would Like To Use:\ \");
    scanf(\"%99s\", filename);


    data = datareading(filename);
    result = calcofcoeffs(data);


    printf(\"poo\");
    printf(\"\ A = %.20lf \ \ B = %.20lf \ \ Sigma A = %.20lf \ \ Sigma B = %.20lf\", result[0], result[1], result[2], result[3]);


    freeData (data);
    free (result);


    return 0;
}


double **datareading(char *filename)
{
    FILE *userfile; //declares the file.
    double **data; //declares double array.
    int i, j; //declares loop variables.
    int nrows; //declares a variable that tracks the row number when reading in the file.
    int ncolumns; //declares and initialises the number of columns of data and means the following loop starts at the correct point.


    //allocating memory using malloc for the array to store the data from the file.
    data = (double**)malloc(3*sizeof(double*));
    for(i=0; i<3; i++)
        {
            data[i] = (double*)malloc(4*sizeof(double));
        }


    userfile = fopen(filename,\"r\");
    //initialising all the array elements to zero


    for(i=0; i<3; i++)
        {
            for(j=0; j<4; j++)
            {
                data[i][j] = 0;
            }
        }
    if (userfile==NULL) //check to see if file was found.
        {
            printf(\"File not found!.\");
            return data;
        }


        nrows=0;
        ncolumns=4;


    while (ncolumns==4 && nrows<3);
    {
        ncolumns = fscanf(userfile, \"%lf %lf %lf %lf\ \", &data[nrows][0], &data[nrows][1], &data[nrows][2], &data[nrows][3]);
        nrows++;
    }


    fclose(userfile);


    printf(\"File read\ \");
    return data;
}


void freeData(double **data)
{
    int i;
    for (i=0; i<4; i++)
    {
        free(data[i]);
    }


    free (data);


    return;
}


double *calcofcoeffs(double **data)
{
    //declaring and initialising the variables used for summations
    int i;
    double x;
    double y;
    double xy;
    double xx;
    double one;
    double sigmai2;


    //declaring variables to be given as final results.
    double A;
    double B;
    double sigmaA;
    double sigmaB;


    //declaring a pointer to be used in int main to display final results.
    double *result;
    result = (double*)malloc(4*sizeof(double));


    i=0;
    x=0;
    y=0;
    xy=0;
    xx=0;
    one=0;


    //a while loop that reads through the data to calculate the summations
        while(i<4 && data[i][3]!=0)
        {


                    sigmai2 = data[i][3]*data[i][3];//making a more simple shorthand for calculation


            // summations used in working out coeffs A and B.
            y+=(data[i][1]/sigmai2);
            xx+=((data[i][0]*data[i][0])/sigmai2);
            x+=(data[i][0]/sigmai2);
            xy+=((data[i][0]*data[i][1])/sigmai2);
            one+=(1/sigmai2);


            i++;
        }
    //working out coeffs A and B.
    A = ((y*xx)-(x*xy))/((one*xx)-(x*x));
    B = ((one*xy)-(x*y))/((one*xx)-(x*x));


    //working out errors in coeffs.
    sigmaA = sqrt((xx)/((one*xx)-(x*x)));
    sigmaB = sqrt((one)/((one*xx)-(x*x)));


    //output the values required.
    result[0] = A;
    result[1] = B;
    result[2] = sigmaA;
    result[3] = sigmaB;


    return result;
}

How would you implement the following in C or C++ with 6 and 12 data points? Source code would be very helpful. Table 2. Sign definition of sensor raw measureme
How would you implement the following in C or C++ with 6 and 12 data points? Source code would be very helpful. Table 2. Sign definition of sensor raw measureme
How would you implement the following in C or C++ with 6 and 12 data points? Source code would be very helpful. Table 2. Sign definition of sensor raw measureme
How would you implement the following in C or C++ with 6 and 12 data points? Source code would be very helpful. Table 2. Sign definition of sensor raw measureme

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site