OpenCores
URL https://opencores.org/ocsvn/yac/yac/trunk

Subversion Repositories yac

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /yac/trunk/c_octave
    from Rev 2 to Rev 3
    Reverse comparison

Rev 2 → Rev 3

/cordic_iterative.c
59,7 → 59,11
#include "mex.h"
 
/* enable debug output */
<<<<<<< HEAD
#define PRINT_DEBUG 0
=======
#define PRINT_DEBUG 0
>>>>>>> initial commit
 
 
/* #define CORDIC_ROUNDING 0.5 */
80,6 → 84,24
 
 
 
<<<<<<< HEAD
=======
 
long long int ov_check( long long int * value, long long int length )
{
long long int mask = (1<<length)-1;
long long int result = 0;
long long int min = -((long long int)1<<length);
long long int max = ((long long int)1<<length);
if( *value > max || *value < min )
result = *value;
/* *value &= mask; */
return result;
}
 
 
 
>>>>>>> initial commit
void cordic_int( long long int x_i,
long long int y_i,
long long int a_i,
102,8 → 124,12
long long int *y,
long long int *a,
int mode,
<<<<<<< HEAD
int A_WIDTH,
int XY_WIDTH );
=======
int A_WIDTH );
>>>>>>> initial commit
void cordic_int_rm_gain( long long int *x,
long long int *y,
int mode,
232,7 → 258,11
long long int a;
long long int s;
int ov;
<<<<<<< HEAD
int it = 0;
=======
int it;
>>>>>>> initial commit
 
 
242,6 → 272,7
cordic_int_dbg( x_i, y_i, a_i, mode, 0, "input" );
 
<<<<<<< HEAD
if( !cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH, XY_WIDTH ) )
{
 
249,7 → 280,15
 
cordic_int_rm_gain( &x_i, &y_i, mode, RM_GAIN );
}
=======
cordic_int_init( &x_i, &y_i, &a_i, mode, A_WIDTH );
 
it = cordic_int_rotate( &x_i, &y_i, &a_i, mode, A_WIDTH );
 
cordic_int_rm_gain( &x_i, &y_i, mode, RM_GAIN );
 
>>>>>>> initial commit
 
*x_o = x_i;
*y_o = y_i;
*a_o = a_i;
267,8 → 306,12
long long int *y,
long long int *a,
int mode,
<<<<<<< HEAD
int A_WIDTH,
int XY_WIDTH )
=======
int A_WIDTH )
>>>>>>> initial commit
{
int already_done = 0;
 
275,6 → 318,7
 
long long int PI = ( long long int )( M_PI * pow( 2, A_WIDTH-1 ) + 0.5 );
long long int PI_H = (long long int)( M_PI * pow( 2, A_WIDTH-2 ) + 0.5 );
<<<<<<< HEAD
long long int XY_MAX = pow( 2, XY_WIDTH-1 )-1;
281,6 → 325,11
cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
 
 
=======
cordic_int_dbg( *x, *y, *a, mode, 0, "before init" );
>>>>>>> initial commit
/* Circular rotation mode */
if( 0 == ( mode & C_FLAG_VEC_ROT ) &&
C_MODE_CIR == ( mode & C_MODE_MSK ) )
315,6 → 364,7
else if ( 0 != ( mode & C_FLAG_VEC_ROT ) &&
C_MODE_CIR == ( mode & C_MODE_MSK ) )
{
<<<<<<< HEAD
 
if( *x == 0 && *y == 0 )
{
384,23 → 434,44
#endif
}
else if( *x < 0 && *y >= 0 )
=======
if( *x < 0 && *y > 0 )
>>>>>>> initial commit
{
*x = -*x;
*y = -*y;
*a = PI;
#if PRINT_DEBUG > 0
<<<<<<< HEAD
PRINT("pre-rotation from second to the fourth quadrant\n" );
#endif
}
else if( *x < 0 && *y < 0 )
=======
PRINT("align from second quadrand\n" );
#endif
}
else if( *x < 0 && *y < 0 )
>>>>>>> initial commit
{
*x = -*x;
*y = -*y;
*a = -PI;
#if PRINT_DEBUG > 0
<<<<<<< HEAD
PRINT("pre-rotation from third to first quadrand\n" );
#endif
}
=======
PRINT("align from third quadrand\n" );
#endif
}
else if( *x < 0 && *y == 0 )
{
*a = PI;
already_done = 1;
}
>>>>>>> initial commit
else
*a = 0;
}
417,7 → 488,11
}
 
cordic_int_dbg( *x, *y, *a, mode, 0, "after init" );
<<<<<<< HEAD
return already_done;
=======
>>>>>>> initial commit
}
 
 
534,7 → 609,11
/* abort condition */
if( ( mode & C_FLAG_VEC_ROT ) == 0 &&
<<<<<<< HEAD
( *a == 0 /* || *a == -1 */ ) )
=======
( *a == 0 || *a == -1 ) )
>>>>>>> initial commit
break;
if( ( mode & C_FLAG_VEC_ROT ) == 0 &&
( *a == alst ) )
541,7 → 620,11
break;
if( ( mode & C_FLAG_VEC_ROT ) != 0 &&
<<<<<<< HEAD
( *y == 0 /*|| *y == -1 */ ) )
=======
( *y == 0 || *y == -1 ) )
>>>>>>> initial commit
break;
if( ( mode & C_FLAG_VEC_ROT ) != 0 &&
( *y == ylst ) )
/cordic_iterative_code.m
68,8 → 68,11
% TODO: calculate these values
K0 = 0.607252935009;
K1 = 0.207497067763;
<<<<<<< HEAD
%prod( sqrt( 1-2.^(-2 .* [ 1 : 100000 ] ) ) )
 
=======
>>>>>>> initial commit
 
signs = get_rm_gain_shifts( K0, 30 );
print_rm_gain_code( fid, signs, K0, 1, 1, 0 );
84,7 → 87,11
print_rm_gain_code( fid, signs, K1, 1, 0, 1 );
 
MAX_A_WIDTH = 32;
<<<<<<< HEAD
print_angular_lut( fid, MAX_A_WIDTH );
=======
print_angular_lut( fid, MAX_A_WIDTH )
>>>>>>> initial commit
 
 
fclose( fid );
195,7 → 202,11
end
for y = 1 : length( tmp2 )
<<<<<<< HEAD
fprintf( fid, '%c ( x >> %d ) ', tmp2{ y }, index( y ) );
=======
fprintf( fid, '%c ( x >> %d ) ', tmp2{ y }, index( y ) )
>>>>>>> initial commit
end
fprintf( fid, '; break; /* error: %.10f */ \n', err );
else
/cordic_iterative_test.m
20,6 → 20,7
%%%% implementation behaves the same than the VHDL %%%%
%%%% implementation. %%%%
%%%% %%%%
<<<<<<< HEAD
%%%% Three tests are implemented: %%%%
%%%% - Random test values %%%%
%%%% - Linear increasing values %%%%
28,11 → 29,17
%%%% %%%%
%%%% Please do 'mex cordic_iterative.c' to create %%%%
%%%% the cordic_iterative.mex. %%%%
=======
>>>>>>> initial commit
%%%% %%%%
%%%%% %%%%%
%%%% %%%%
%%%% TODO %%%%
<<<<<<< HEAD
%%%% The linear test is not complete %%%%
=======
%%%% Some documentation and function description %%%%
>>>>>>> initial commit
%%%% %%%%
%%%% %%%%
%%%% %%%%
59,10 → 66,27
%%%% http://www.gnu.org/licenses/lgpl %%%%
%%%% %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
<<<<<<< HEAD
function cordic_iterative_test( )
 
 
 
=======
 
 
 
function cordic_iterative_test( )
%
%
% Please do 'mex cordic_iterative.c' to create
% the cordic_iterative.mex
%
%
%
%
 
 
>>>>>>> initial commit
% global flags/values, they are static
% through the whole script and defined below
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
95,6 → 119,7
 
% open test file
tb_fid = fopen( './tb_data.txt', 'w' );
<<<<<<< HEAD
%tb_fid = 0;
 
 
171,11 → 196,21
0, 0, ...
0, 0, ...
'Limit Value Test' );
=======
 
% run test, which uses random values
run_random_test( N_TESTS, tb_fid );
 
% close file
fclose( tb_fid );
 
>>>>>>> initial commit
 
end
 
 
 
<<<<<<< HEAD
function run_linear_test( N_TESTS, tb_fid )
%RUN_LINEAR_TEST Generates a linear test pattern
%
231,6 → 266,13
data_b = -1 + 2 .* rand( 1, N_TESTS );
data_c = -1 + 2 .* rand( 1, N_TESTS );
data_d = -pi + 2*pi .* rand( 1, N_TESTS );
=======
function run_random_test( N_TESTS, tb_fid )
 
data_a = -1 + 2 .* rand( 1, N_TESTS );
data_b = -1 + 2 .* rand( 1, N_TESTS );
 
>>>>>>> initial commit
% adapat data for division
data_a_div = data_a;
data_b_div = data_b;
239,11 → 281,16
data_b_div( swap_div ) = data_a( swap_div );
 
data_a_h = ones( size( data_a ) );
<<<<<<< HEAD
data_b_h = data_b .* 0.80694; %0.78;
=======
data_b_h = data_b .* 0.78;
>>>>>>> initial commit
 
 
 
[ ~, ~, atan_err, abs_err, it_1 ] = ccart2pol( data_a, data_b, tb_fid );
<<<<<<< HEAD
[ ~, ~, sin_err, cos_err, it_2 ] = cpol2cart( data_d, data_b, tb_fid );
[ ~, ~, x_err, y_err, it_3 ] = crot( data_a, data_b, data_c, tb_fid );
[ ~, div_err, it_4 ] = cdiv( data_a_div, data_b_div, tb_fid );
303,10 → 350,34
 
end
 
=======
[ ~, ~, sin_err, cos_err, it_2 ] = cpol2cart( data_a, data_b, tb_fid );
[ ~, div_err, it_3 ] = cdiv( data_a_div, data_b_div, tb_fid );
[ ~, mul_err, it_4 ] = cmul( data_a, data_b, tb_fid );
[ ~, ~, atanh_err, sqrt_err, it_5 ] = catanh( data_a_h, data_b_h, tb_fid );
[ ~, ~, sinh_err, cosh_err, it_6 ] = csinhcosh( data_a, tb_fid );
 
fprintf( ' ___________________________________________________________________\n' );
fprintf( ' Random Value Test \n' );
fprintf( ' -----+-------------------+--------------------+-------------------\n' );
fprintf( ' | max error | mean error | max iterations \n' );
fprintf( ' atan | % .14f | % .14f | %.5f \n', max( atan_err ), mean( atan_err ), max( it_1 ) );
fprintf( ' abs | % .14f | % .14f | %.5f \n', max( abs_err ), mean( abs_err ), max( it_1 ) );
fprintf( ' sin | % .14f | % .14f | %.5f \n', max( sin_err ), mean( sin_err ), max( it_2 ) );
fprintf( ' cos | % .14f | % .14f | %.5f \n', max( cos_err ), mean( cos_err ), max( it_2 ) );
fprintf( ' div | % .14f | % .14f | %.5f \n', max( div_err ), mean( div_err ), max( it_3 ) );
fprintf( ' mul | % .14f | % .14f | %.5f \n', max( mul_err ), mean( mul_err ), mean( it_4 ) );
fprintf( ' atanh| % .14f | % .14f | %.5f \n', max( atanh_err), mean( atanh_err ), mean( it_5 ) );
fprintf( ' sinh | % .14f | % .14f | %.5f \n', max( sinh_err ), mean( sinh_err ), mean( it_6 ) );
fprintf( ' cosh | % .14f | % .14f | %.5f \n', max( cosh_err ), mean( cosh_err ), mean( it_6 ) );
 
 
end
>>>>>>> initial commit
 
 
 
 
function [sinh_res, cosh_res, sinh_err, cosh_err, it ]= csinhcosh( th, fid )
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
467,6 → 538,7
end
 
 
<<<<<<< HEAD
function [x_res, y_res, x_err, y_err, it ] = crot( x, y, th, fid )
%
% does a multiplication with exp( th * i )
512,6 → 584,12
% does the Matlab equivalent pol2cart
%
 
=======
 
 
 
function [sin_res, cos_res, sin_err, cos_err, it ]= cpol2cart( th, r, fid )
>>>>>>> initial commit
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
519,8 → 597,17
yi = zeros( 1, length( th ) );
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
 
<<<<<<< HEAD
mode = C_MODE_CIRC;
 
=======
 
 
mode = C_MODE_CIRC;
 
 
% cordic version
>>>>>>> initial commit
[ rcos rsin ra, it ] = cordic_iterative( ...
xi, ...
yi, ...
548,7 → 635,10
 
 
 
<<<<<<< HEAD
 
=======
>>>>>>> initial commit
function [atan_res, abs_res, atan_err, abs_err, it ] = ccart2pol( x, y, fid )
 
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
574,10 → 664,15
ANGLEWIDTH, ...
GUARDBITS, ...
RM_GAIN );
<<<<<<< HEAD
% matlab version:
m_th = atan2( y, x );
m_r = sqrt( x.^2 + y.^2 );
 
=======
% matlab version
[m_th, m_r ] = cart2pol( x, y );
>>>>>>> initial commit
 
% comparison
atan_res = ra ./ 2^( (ANGLEWIDTH)-1);
585,8 → 680,11
atan_err = abs( m_th - atan_res );
abs_err = abs( m_r - abs_res );
 
<<<<<<< HEAD
% TODO: ATAN oder ATAN2 atan( 0 / x ) != atan2( 0, x )!!!!
 
=======
>>>>>>> initial commit
% write TB data
write_tb( fid, xi, yi, ai, rx, ry, ra, mode )
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.