Esempio n. 1
0
double RAW_SIN(double degree){
    double radian = 0;
    int32 s, c;
    s = 0;
    c = 0;
    radian = degree * PI / 180;
    // iterate for 16 times, precision can reach 0.0000
    cordic((radian*MUL), &s, &c, 16);
    
    return s/MUL;
}
Esempio n. 2
0
void cube_calculate(double degreeX, double degreeY, double degreeZ, double scale, int16_t shiftX, int16_t shiftY, int16_t shiftZ)
{

	uint8_t i;
	double sinx, siny, sinz, cosx, cosy, cosz;
	double x,y,z,x1,y1,z1;

	cordic(degreeX, &sinx, &cosx);
	cordic(degreeY, &siny, &cosy);
	cordic(degreeZ, &sinz, &cosz);

	for (i = 0; i < AMOUNT_NODE; i++)
	{

	    x = pix[i][0];   // Base coordinate
	    y = pix[i][1];
	    z = pix[i][2];

	    x1 = x*cosz + y*sinz;       // Rotation around axis Z
	    y1 = -x*sinz + y*cosz;
	    z1 = z;

	    x = x1;                     // Rotation around axis X
	    y = y1*cosx + z1*sinx;
	    z = -y1*sinx + z1*cosx;

	    x1 = x*cosy - z*siny;       // Rotation around axis Y
	    y1 = y;
	    z1 = x*siny + z*cosy;

    	newpix[i][0] = (int16_t)round(x1 * scale);    // Scaling
    	newpix[i][1] = (int16_t)round(y1 * scale);
    	newpix[i][2] = (int16_t)round(z1 * scale);

    	newpix[i][0] += shiftX;     // Shift center coordinates
    	newpix[i][1] += shiftY;
    	newpix[i][2] += shiftZ;
	}
}
ICACHE_FLASH_ATTR void cube_calculate(int16_t _pix[VERTEX_COUNT][3], double degreeX, double degreeY, double degreeZ, double scale, int16_t shiftX, int16_t shiftY, int16_t shiftZ)
{

    uint8_t i;
    double sinx, siny, sinz, cosx, cosy, cosz;
    double x,y,z,x1,y1,z1;

    cordic(degreeX, &sinx, &cosx);
    cordic(degreeY, &siny, &cosy);
    cordic(degreeZ, &sinz, &cosz);

    for (i = 0; i < VERTEX_COUNT; i++) {

        x = pix[i][0];   // Base coordinate
        y = pix[i][1];
        z = pix[i][2];

        x1 = x*cosz + y*sinz;       // Rotation around axis Z
        y1 = -x*sinz + y*cosz;
        z1 = z;

        x = x1;                     // Rotation around axis X
        y = y1*cosx + z1*sinx;
        z = -y1*sinx + z1*cosx;

        x1 = x*cosy - z*siny;       // Rotation around axis Y
        y1 = y;
        z1 = x*siny + z*cosy;

        _pix[i][0] = (int16_t)(x1 * scale);    // Scaling
        _pix[i][1] = (int16_t)(y1 * scale);
        _pix[i][2] = (int16_t)(z1 * scale);

        _pix[i][0] += shiftX;     // Shift center coordinates
        _pix[i][1] += shiftY;
        _pix[i][2] += shiftZ;
    }
}
Esempio n. 4
0
int main(void) {

	if( ! (!(0 & 0x80000000)
			&& !(1 & 0x80000000)
			&& !(100 & 0x80000000)
			&& !!(-1 & 0x80000000)
			&& !!(-100 & 0x80000000))) {
		printf("Your system doesn't use 32 bit integers. Please run on a 32 bit machine.\n");
		return 1;
	}

	printf("cos cordic: %15lf\n\n", cos_cordic(30));
	printf("sin cordic: %15lf\n\n", sin_cordic(45));
	printf("arctan xy cordic: %15lf\n\n", arctan_x_y_cordic(3,4));
	printf("arctan cordic: %15lf\n\n", arctan_cordic(4));

	int x = 1;
	int y = 0;
	int z = 45;
	cordic(&x, &y, &z, ROTATIONAL);
	printf("normal cordic: %d, %d, %d\n", x, y, z);

	x = 1;
	y = 0;
	z = 45;
	cordic_assembly(&x, &y, &z, (int)ROTATIONAL);
	printf("assembly cordic: %d, %d, %d\n", x, y, z);

	x = 1;
	y = 0;
	z = 45;
	cordic_optimized(&x, &y, &z, ROTATIONAL);
	printf("optimized cordic: %d, %d, %d\n", x, y, z);

	printf("Inline computation Test, should be 5: %d\n", inline_test(1, 4));

	return 0;
}
Esempio n. 5
0
int main(int argc, char **argv)
{   
    FILE *fp;

    cos_sin_type s = 0; //sin output
    cos_sin_type c = 0; //cos output
    theta_type radian; //radian input

    double zs, zc; // sin and cos values calculated from math.h.

    //Error checking
    double Total_Error_Sin = 0.0;
    double Total_Error_Cos = 0.0;
    double error_sin = 0.0, error_cos = 0.0;

    fp = fopen("out.dat","w");
    // Compute sin/cos values for angles up to NUM_DEGREE
    for (int i = 1; i < NUM_DEGREE; i++) {
        radian = i*M_PI/180;
        cordic(radian, s, c);
        zs = sin((double)radian);
        zc = cos((double)radian);
        error_sin = (abs_double((double)s-zs)/zs)*100.0;
        error_cos = (abs_double((double)c-zc)/zc)*100.0;
        Total_Error_Sin = Total_Error_Sin + error_sin*error_sin;
        Total_Error_Cos = Total_Error_Cos + error_cos*error_cos;

 
        fprintf(fp, "degree=%d, radian=%f, cos=%f:%f, sin=%f:%f, cos_error=%f\%, sin_error=%f\%\n", i, (double)radian, (double)c, zc, (double)s, zs, error_cos, error_sin);
    }

    fclose(fp);
    // Print out root mean square error (RMSE) in percentage
    printf ("Overall_Error_Sin=%f\%, Overall_Error_Cos=%f\%\n", sqrt(Total_Error_Sin/(NUM_DEGREE-1)), sqrt(Total_Error_Cos/(NUM_DEGREE-1)));
    return 0;
}
Esempio n. 6
0
int main(void) {

	clock_t before_time;
	int ticks_per_second = sysconf(_SC_CLK_TCK);

	int repetitions = 1000000;

	volatile int i;
	int values[repetitions];
	int angles[repetitions];
	for (i = 0; i < repetitions; i++) {
		values[i] = rand() % 10000;
		angles[i] = rand() % HALF_PI;
	}

	int x, y, z;

	check_32_bit();

	printf("\t\tCordic Profiler: Seng440\n\n");

	// int_cordic
	before_time = get_time();
	for (i=0; i<repetitions; i++) {
		x = values[i];
		y = angles[repetitions-1-i];
		z = angles[i];
		cordic(&x, &y, &z, ROTATIONAL);
	}
	printf("\tcordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);

	// optimized cordic
	before_time = get_time();
	for (i=0; i<repetitions; i++) {
		x = values[i];
		y = angles[repetitions-1-i];
		z = angles[i];
		cordic_optimized(&x, &y, &z, ROTATIONAL);
	}
	printf("\toptimized cordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);


	// arm implementation
	before_time = get_time();
	for (i=0; i<repetitions; i++) {
		x = values[i];
		y = angles[repetitions-1-i];
		z = angles[i];
		cordic_assembly(&x, &y, &z, (int)ROTATIONAL);
	}
	printf("\tarm cordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);


	// optimized arm implementation
	before_time = get_time();
	for (i=0; i<repetitions; i++) {
		x = values[i];
		y = angles[repetitions-1-i];
		z = angles[i];
		cordic_assembly_optimized(&x, &y, &z, (int)ROTATIONAL);
	}
	printf("\toptimized arm cordic\n\ntime: %f\n\n", (double)(get_time() - before_time) / ticks_per_second);

	return 0;
}