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

Subversion Repositories yac

[/] [yac/] [trunk/] [c_octave/] [cordic_iterative_test.m] - Diff between revs 4 and 7

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 4 Rev 7
Line 97... Line 97...
% through the whole script and defined below
% 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
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
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
 
 
%
cordic_iterative_setup
% flags: they are also define in cordic_iterative.c and
 
%        cordic_iterative_pkg.vhd
 
C_FLAG_VEC_ROT  = 2^3;
 
C_FLAG_ATAN_3   = 2^2;
 
C_MODE_CIRC     = 0;
 
C_MODE_LIN      = 1;
 
C_MODE_HYP      = 2;
 
 
 
% initialize the random-generator's seed
 
rand('seed', 1633);
 
 
 
 
 
% cordic setup:
% open output file
% this must fit to the testbench
tb_fid = fopen( TB_FILE, 'w' );
XY_WIDTH   = 25;
 
ANGLEWIDTH = 25;
 
GUARDBITS  = 2;
 
RM_GAIN    = 5;
 
 
 
 
% Number of tests, which are run
 
N_TESTS    = 10000;
 
 
% Number of tests, which are run
<<<<<<< HEAD
N_TESTS    = 10000;
% open test file
 
tb_fid = fopen( './tb_data.txt', 'w' );
% open test file
 
tb_fid = fopen( './tb_data.txt', 'w' );
 
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
%tb_fid = 0;
%tb_fid = 0;
 
 
 
 
 
 
 
 
 
 
%
%
% run test, which uses random values
% run test, which uses random values
run_random_test( N_TESTS, tb_fid );
run_random_test( N_TESTS, tb_fid );
%
%
% run tests, which test limits
% run tests, which test limits
run_limit_test( tb_fid );
run_limit_test( tb_fid );
%
%
% run linear value test
% run linear value test
run_linear_test( 1000, tb_fid );
run_linear_test( 1000, tb_fid );
 
 
% close file
% close file
if tb_fid > 0
if tb_fid > 0
    fclose( tb_fid );
    fclose( tb_fid );
end
end
 
 
end
end
 
 
 
 
 
 
 
 
function run_limit_test( tb_fid )
function run_limit_test( tb_fid )
%RUN_LIMIT_TEST Test the range limit
%RUN_LIMIT_TEST Test the range limit
%
%
% run_limit_test( fid )
% run_limit_test( fid )
%
%
% This function is used to generate a test pattern
% This function is used to generate a test pattern
% with values, which are at the range limit.
% with values, which are at the range limit.
% This values are then processed by the fixed-point YAC
% This values are then processed by the fixed-point YAC
% implementation. All input and outputs are logged into
% implementation. All input and outputs are logged into
% a testbench pattern file.
% a testbench pattern file.
%
%
% The argument fid is the file-descriptor of the testbench pattern
% The argument fid is the file-descriptor of the testbench pattern
% file.
% file.
%
%
 
 
 
 
data_a = [ 0 1 0 1 -1  0 -1  1 -1 ];
 
data_b = [ 0 0 1 1  0 -1 -1 -1  1 ];
 
 
 
data_c = [ 0 0 0 0  0  0  0  0  0 ...
 
           1 1 1 1  1  1  1  1  1 ...
 
           -1 -1 -1 -1 -1 -1 -1 -1 -1 ];
 
 
 
data_d = data_a * pi;
 
 
 
data_a_div = [ 0.5 ,1 -0.5, -1, -0.5, -1 ];
data_a = [ 0 1 0 1 -1  0 -1  1 -1 ];
data_b_div = [ 1   ,1,  1,   1,   -1, -1 ];
data_b = [ 0 0 1 1  0 -1 -1 -1  1 ];
 
 
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
data_c = [ 0 0 0 0  0  0  0  0  0 ...
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
           1 1 1 1  1  1  1  1  1 ...
[ ~, ~, x_err, y_err, it_3 ]        = crot( [ data_a, data_a, data_a], ...
           -1 -1 -1 -1 -1 -1 -1 -1 -1 ];
                                            [ data_b, data_b, data_b], ...
 
                                              data_c, tb_fid );
data_d = data_a * pi;
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
 
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
data_a_div = [ 0.5 ,1 -0.5, -1, -0.5, -1 ];
 
data_b_div = [ 1   ,1,  1,   1,   -1, -1 ];
 
 
 
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
 
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
 
[ ~, ~, x_err, y_err, it_3 ]        = crot( [ data_a, data_a, data_a], ...
 
                                            [ data_b, data_b, data_b], ...
 
                                              data_c, tb_fid );
 
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
 
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
 
 
print_result_info(    ...
print_result_info(    ...
    atan_err,   it_1, ...
    atan_err,   it_1, ...
    abs_err,    it_1, ...
    abs_err,    it_1, ...
    sin_err,    it_2, ...
    sin_err,    it_2, ...
    cos_err,    it_2, ...
    cos_err,    it_2, ...
    x_err,      it_3, ...
    x_err,      it_3, ...
    y_err,      it_3, ...
    y_err,      it_3, ...
    div_err,    it_4, ...
    div_err,    it_4, ...
    mul_err,    it_5, ...
    mul_err,    it_5, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    'Limit Value Test' );
    'Limit Value Test' );
=======
=======
=======
=======
%tb_fid = 0;
%tb_fid = 0;
 
 
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
 
 
 
 
 
=======
 
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper
 
 
%
%
% run test, which uses random values
% run test, which uses random values
run_random_test( N_TESTS, tb_fid );
run_random_test( N_TESTS, tb_fid );
%
%
% run tests, which test limits
% run tests, which test limits
run_limit_test( tb_fid );
run_limit_test( tb_fid );
%
%
% run linear value test
% run linear value test
run_linear_test( 1000, tb_fid );
run_linear_test( 1000, tb_fid );
 
 
% close file
% close file
if tb_fid > 0
if tb_fid > 0
    fclose( tb_fid );
    fclose( tb_fid );
end
end
 
 
end
end
 
 
 
 
 
 
 
 
function run_limit_test( tb_fid )
function run_limit_test( tb_fid )
%RUN_LIMIT_TEST Test the range limit
%RUN_LIMIT_TEST Test the range limit
%
%
% run_limit_test( fid )
% run_limit_test( fid )
%
%
% This function is used to generate a test pattern
% This function is used to generate a test pattern
% with values, which are at the range limit.
% with values, which are at the range limit.
% This values are then processed by the fixed-point YAC
% This values are then processed by the fixed-point YAC
% implementation. All input and outputs are logged into
% implementation. All input and outputs are logged into
% a testbench pattern file.
% a testbench pattern file.
%
%
% The argument fid is the file-descriptor of the testbench pattern
% The argument fid is the file-descriptor of the testbench pattern
% file.
% file.
%
%
 
 
 
 
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> initial commit
>>>>>>> initial commit
 
 
end
end
 
 
 
 
 
 
<<<<<<< HEAD
<<<<<<< HEAD
function run_linear_test( N_TESTS, tb_fid )
function run_linear_test( N_TESTS, tb_fid )
%RUN_LINEAR_TEST Generates a linear test pattern
%RUN_LINEAR_TEST Generates a linear test pattern
%
%
% run_linear_test( N, fid )
% run_linear_test( N, fid )
%
%
% This function is used to generate linear increasing test
% This function is used to generate linear increasing test
% values.
% values.
% These values are then processed by the fixed-point YAC
% These values are then processed by the fixed-point YAC
% implementation. All input and outputs are logged into
% implementation. All input and outputs are logged into
% a testbench pattern file. In addition, the result is plotted.
% a testbench pattern file. In addition, the result is plotted.
%
%
% NOTE: only the hyperbolic functions are processed at the moment.
% NOTE: only the hyperbolic functions are processed at the moment.
% This function needs to be extended in future.
% This function needs to be extended in future.
%
%
%
%
% The argument fid is the file-descriptor of the testbench pattern
% The argument fid is the file-descriptor of the testbench pattern
% file. The argument N defines the number of values, which are processed.
% file. The argument N defines the number of values, which are processed.
%
%
%
%
 
 
data_a_h = ones( 1, N_TESTS );
data_a_h = ones( 1, N_TESTS );
data_b_h = linspace( -1, 1, N_TESTS ) * 0.78;
data_b_h = linspace( -1, 1, N_TESTS ) * 0.78;
data_c_h = linspace( -1, 1, N_TESTS );
data_c_h = linspace( -1, 1, N_TESTS );
[ atanh_res, sqrt_res, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
[ atanh_res, sqrt_res, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
[ sinh_res, cosh_res, sinh_err, cosh_err, it_7 ]   = csinhcosh( data_c_h, tb_fid );
[ sinh_res, cosh_res, sinh_err, cosh_err, it_7 ]   = csinhcosh( data_c_h, tb_fid );
 
 
=======
=======
data_a = [ 0 1 0 1 -1  0 -1  1 -1 ];
data_a = [ 0 1 0 1 -1  0 -1  1 -1 ];
data_b = [ 0 0 1 1  0 -1 -1 -1  1 ];
data_b = [ 0 0 1 1  0 -1 -1 -1  1 ];
 
 
data_c = [ 0 0 0 0  0  0  0  0  0 ...
data_c = [ 0 0 0 0  0  0  0  0  0 ...
           1 1 1 1  1  1  1  1  1 ...
           1 1 1 1  1  1  1  1  1 ...
           -1 -1 -1 -1 -1 -1 -1 -1 -1 ];
           -1 -1 -1 -1 -1 -1 -1 -1 -1 ];
 
 
data_d = data_a * pi;
data_d = data_a * pi;
 
 
data_a_div = [ 0.5 ,1 -0.5, -1, -0.5, -1 ];
data_a_div = [ 0.5 ,1 -0.5, -1, -0.5, -1 ];
data_b_div = [ 1   ,1,  1,   1,   -1, -1 ];
data_b_div = [ 1   ,1,  1,   1,   -1, -1 ];
 
 
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
[ ~, ~, x_err, y_err, it_3 ]        = crot( [ data_a, data_a, data_a], ...
[ ~, ~, x_err, y_err, it_3 ]        = crot( [ data_a, data_a, data_a], ...
                                            [ data_b, data_b, data_b], ...
                                            [ data_b, data_b, data_b], ...
                                              data_c, tb_fid );
                                              data_c, tb_fid );
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
 
 
print_result_info(    ...
print_result(    ...
    atan_err,   it_1, ...
    atan_err,   it_1, ...
    abs_err,    it_1, ...
    abs_err,    it_1, ...
    sin_err,    it_2, ...
    sin_err,    it_2, ...
    cos_err,    it_2, ...
    cos_err,    it_2, ...
    x_err,      it_3, ...
    x_err,      it_3, ...
    y_err,      it_3, ...
    y_err,      it_3, ...
    div_err,    it_4, ...
    div_err,    it_4, ...
    mul_err,    it_5, ...
    mul_err,    it_5, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    'Limit Value Test' );
    'Limit Value Test' );
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
figure; plot( data_b_h, atanh_res ); title( 'atanh' );
figure; plot( data_b_h, atanh_res ); title( 'atanh' );
figure; plot( data_b_h, atanh_err ); title( 'atanh-error' );
figure; plot( data_b_h, atanh_err ); title( 'atanh-error' );
figure; plot( data_c_h, sinh_res, data_c_h, cosh_res ); title( 'sinh and cosh' );
figure; plot( data_c_h, sinh_res, data_c_h, cosh_res ); title( 'sinh and cosh' );
figure; plot( data_c_h, sinh_err, data_c_h, cosh_err ); title( 'sinh and cosh errors' );
figure; plot( data_c_h, sinh_err, data_c_h, cosh_err ); title( 'sinh and cosh errors' );
end
end
 
 
 
 
 
 
<<<<<<< HEAD
<<<<<<< HEAD
function run_random_test( N_TESTS, tb_fid )
function run_random_test( N_TESTS, tb_fid )
%RUN_RANDOM_TEST Generates a random test pattern
%RUN_RANDOM_TEST Generates a random test pattern
%
%
% run_random_test( N, fid )
% run_random_test( N, fid )
%
%
% This function is used to generate random test
% This function is used to generate random test
% values (uniform distributed).
% values (uniform distributed).
% These values are then processed by the fixed-point YAC
% These values are then processed by the fixed-point YAC
% implementation. All input and outputs are logged into
% implementation. All input and outputs are logged into
% a testbench pattern file.
% a testbench pattern file.
=======
=======
function run_linear_test( N_TESTS, tb_fid )
function run_linear_test( N_TESTS, tb_fid )
%RUN_LINEAR_TEST Generates a linear test pattern
%RUN_LINEAR_TEST Generates a linear test pattern
%
%
% run_linear_test( N, fid )
% run_linear_test( N, fid )
%
%
% This function is used to generate linear increasing test
% This function is used to generate linear increasing test
% values.
% values.
% These values are then processed by the fixed-point YAC
% These values are then processed by the fixed-point YAC
% implementation. All input and outputs are logged into
% implementation. All input and outputs are logged into
% a testbench pattern file. In addition, the result is plotted.
% a testbench pattern file. In addition, the result is plotted.
%
%
% NOTE: only the hyperbolic functions are processed at the moment.
% NOTE: only the hyperbolic functions are processed at the moment.
% This function needs to be extended in future.
% This function needs to be extended in future.
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
%
%
%
%
% The argument fid is the file-descriptor of the testbench pattern
% The argument fid is the file-descriptor of the testbench pattern
% file. The argument N defines the number of values, which are processed.
% file. The argument N defines the number of values, which are processed.
%
%
%
%
<<<<<<< HEAD
<<<<<<< HEAD
data_a = -1 + 2 .* rand( 1, N_TESTS );
data_a = -1 + 2 .* rand( 1, N_TESTS );
data_b = -1 + 2 .* rand( 1, N_TESTS );
data_b = -1 + 2 .* rand( 1, N_TESTS );
data_c = -1 + 2 .* rand( 1, N_TESTS );
data_c = -1 + 2 .* rand( 1, N_TESTS );
data_d = -pi + 2*pi .* rand( 1, N_TESTS );
data_d = -pi + 2*pi .* rand( 1, N_TESTS );
=======
=======
function run_random_test( N_TESTS, tb_fid )
function run_random_test( N_TESTS, tb_fid )
=======
=======
 
 
data_a_h = ones( 1, N_TESTS );
data_a_h = ones( 1, N_TESTS );
data_b_h = linspace( -1, 1, N_TESTS ) * 0.78;
data_b_h = linspace( -1, 1, N_TESTS ) * 0.78;
data_c_h = linspace( -1, 1, N_TESTS );
data_c_h = linspace( -1, 1, N_TESTS );
[ atanh_res, sqrt_res, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
[ atanh_res, sqrt_res, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
[ sinh_res, cosh_res, sinh_err, cosh_err, it_7 ]   = csinhcosh( data_c_h, tb_fid );
[ sinh_res, cosh_res, sinh_err, cosh_err, it_7 ]   = csinhcosh( data_c_h, tb_fid );
 
 
 
 
figure; plot( data_b_h, atanh_res ); title( 'atanh' );
figure; plot( data_b_h, atanh_res ); title( 'atanh' );
figure; plot( data_b_h, atanh_err ); title( 'atanh-error' );
figure; plot( data_b_h, atanh_err ); title( 'atanh-error' );
figure; plot( data_c_h, sinh_res, data_c_h, cosh_res ); title( 'sinh and cosh' );
figure; plot( data_c_h, sinh_res, data_c_h, cosh_res ); title( 'sinh and cosh' );
figure; plot( data_c_h, sinh_err, data_c_h, cosh_err ); title( 'sinh and cosh errors' );
figure; plot( data_c_h, sinh_err, data_c_h, cosh_err ); title( 'sinh and cosh errors' );
 
 
 
 
end
end
 
 
 
 
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
function run_random_test( N_TESTS, tb_fid )
function run_random_test( N_TESTS, tb_fid )
%RUN_RANDOM_TEST Generates a random test pattern
%RUN_RANDOM_TEST Generates a random test pattern
%
%
% run_random_test( N, fid )
% run_random_test( N, fid )
%
%
% This function is used to generate random test
% This function is used to generate random test
% values (uniform distributed).
% values (uniform distributed).
% These values are then processed by the fixed-point YAC
% These values are then processed by the fixed-point YAC
% implementation. All input and outputs are logged into
% implementation. All input and outputs are logged into
% a testbench pattern file.
% a testbench pattern file.
%
%
%
%
% The argument fid is the file-descriptor of the testbench pattern
% The argument fid is the file-descriptor of the testbench pattern
% file. The argument N defines the number of values, which are processed.
% file. The argument N defines the number of values, which are processed.
%
%
%
%
data_a = -1 + 2 .* rand( 1, N_TESTS );
data_a = -1 + 2 .* rand( 1, N_TESTS );
data_b = -1 + 2 .* rand( 1, N_TESTS );
data_b = -1 + 2 .* rand( 1, N_TESTS );
<<<<<<< HEAD
<<<<<<< HEAD
 
 
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
data_c = -1 + 2 .* rand( 1, N_TESTS );
data_c = -1 + 2 .* rand( 1, N_TESTS );
data_d = -pi + 2*pi .* rand( 1, N_TESTS );
data_d = -pi + 2*pi .* rand( 1, N_TESTS );
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
% adapat data for division
% adapat data for division
data_a_div = data_a;
data_a_div = data_a;
data_b_div = data_b;
data_b_div = data_b;
swap_div   = ( data_b ./ data_a ) >= 2 | ( data_b ./ data_a ) < -2 ;
swap_div   = ( data_b ./ data_a ) >= 2 | ( data_b ./ data_a ) < -2 ;
data_a_div( swap_div ) = data_b( swap_div );
data_a_div( swap_div ) = data_b( swap_div );
data_b_div( swap_div ) = data_a( swap_div );
data_b_div( swap_div ) = data_a( swap_div );
 
 
data_a_h   = ones( size( data_a ) );
data_a_h   = ones( size( data_a ) );
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
data_b_h   = data_b .* 0.80694; %0.78;
data_b_h   = data_b .* 0.80694; %0.78;
=======
=======
data_b_h   = data_b .* 0.78;
data_b_h   = data_b .* 0.78;
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
data_b_h   = data_b .* 0.80694; %0.78;
data_b_h   = data_b .* 0.80694; %0.78;
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
 
 
 
 
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
[ ~, ~, 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 );
[ ~, ~, 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 );
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
[ ~, ~, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
[ ~, ~, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
[ ~, ~, sinh_err, cosh_err, it_7 ]  = csinhcosh( data_a, tb_fid );
[ ~, ~, sinh_err, cosh_err, it_7 ]  = csinhcosh( data_a, tb_fid );
 
 
 
 
 
print_result_header( 'Random Test Result' );
 
print_result2( 'atan', it_1, atan_err, data_a, data_b );
 
print_result2( 'abs ', it_1, abs_err,  data_a, data_b );
 
print_result2( 'sin ', it_2, sin_err,  data_a, data_b );
 
print_result2( 'cos ', it_2, cos_err,  data_a, data_b );
 
 
 
 
 
 
print_result_info(  atan_err,   it_1, ...
print_result(  atan_err,   it_1, ...
                    abs_err,    it_1, ...
                    abs_err,    it_1, ...
                    sin_err,    it_2, ...
                    sin_err,    it_2, ...
                    cos_err,    it_2, ...
                    cos_err,    it_2, ...
                    x_err,      it_3, ...
                    x_err,      it_3, ...
                    y_err,      it_3, ...
                    y_err,      it_3, ...
Line 451... Line 449...
                    mul_err,    it_5, ...
                    mul_err,    it_5, ...
                    atanh_err,  it_6, ...
                    atanh_err,  it_6, ...
                    sqrt_err,   it_6, ...
                    sqrt_err,   it_6, ...
                    sinh_err,   it_7, ...
                    sinh_err,   it_7, ...
                    cosh_err,   it_7, ...
                    cosh_err,   it_7, ...
                    'Random Value Test' );
               'Random Value Test' );
 
 
 
 
end
end
 
 
 
function print_result_header( title )
 
 printf( ' ___________________________________________________________________\n' );
 
 fprintf( '                  %s\n', title);
 
 fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
 
end
 
 
 
function print_result2( msg, it, err, a, b )
 
 
 
[ verr, ierr ] = max( err );
 
fprintf( '%s |  %.14f  | (%.14f %.14f) | %.14f  | %.5f \n', msg, verr, a( ierr ), b( ierr ), mean( err ), max( it ) )
 
 
 
end
 
 
function print_result_info( ...
 
 
function print_result( ...
    atan_err,   atan_it,    ...
    atan_err,   atan_it,    ...
    abs_err,    abs_it,     ...
    abs_err,    abs_it,     ...
    sin_err,    sin_it,     ...
    sin_err,    sin_it,     ...
    cos_err,    cos_it,     ...
    cos_err,    cos_it,     ...
    x_err,      x_it,       ...
    x_err,      x_it,       ...
Line 470... Line 481...
    mul_err,    mul_it,     ...
    mul_err,    mul_it,     ...
    atanh_err,  atanh_it,   ...
    atanh_err,  atanh_it,   ...
    sqrt_err,   sqrt_it,    ...
    sqrt_err,   sqrt_it,    ...
    sinh_err,   sinh_it,    ...
    sinh_err,   sinh_it,    ...
    cosh_err,   cosh_it,    ...
    cosh_err,   cosh_it,    ...
    title )
    title )
<<<<<<< HEAD
<<<<<<< HEAD
 
 
fprintf( ' ___________________________________________________________________\n' );
fprintf( ' ___________________________________________________________________\n' );
fprintf( '                  %s\n', title);
fprintf( '                  %s\n', title);
fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
fprintf( '      |     max error     |   mean error       |  max iterations  \n'   );
fprintf( '      |     max error     |   mean error       |  max iterations  \n'   );
fprintf( ' atan | % .14f | % .14f  | %.5f \n', max( atan_err  ), mean( atan_err  ), max( atan_it   ) );
fprintf( ' atan | % .14f | % .14f  | %.5f \n', max( atan_err  ), mean( atan_err  ), max( atan_it   ) );
fprintf( ' abs  | % .14f | % .14f  | %.5f \n', max( abs_err   ), mean( abs_err   ), max( abs_it    ) );
fprintf( ' abs  | % .14f | % .14f  | %.5f \n', max( abs_err   ), mean( abs_err   ), max( abs_it    ) );
fprintf( ' sin  | % .14f | % .14f  | %.5f \n', max( sin_err   ), mean( sin_err   ), max( sin_it    ) );
fprintf( ' sin  | % .14f | % .14f  | %.5f \n', max( sin_err   ), mean( sin_err   ), max( sin_it    ) );
fprintf( ' cos  | % .14f | % .14f  | %.5f \n', max( cos_err   ), mean( cos_err   ), max( cos_it    ) );
fprintf( ' cos  | % .14f | % .14f  | %.5f \n', max( cos_err   ), mean( cos_err   ), max( cos_it    ) );
fprintf( ' x    | % .14f | % .14f  | %.5f \n', max( x_err     ), mean( x_err     ), max( x_it      ) );
fprintf( ' x    | % .14f | % .14f  | %.5f \n', max( x_err     ), mean( x_err     ), max( x_it      ) );
fprintf( ' y    | % .14f | % .14f  | %.5f \n', max( y_err     ), mean( y_err     ), max( y_it      ) );
fprintf( ' y    | % .14f | % .14f  | %.5f \n', max( y_err     ), mean( y_err     ), max( y_it      ) );
fprintf( ' div  | % .14f | % .14f  | %.5f \n', max( div_err   ), mean( div_err   ), max( div_it    ) );
fprintf( ' div  | % .14f | % .14f  | %.5f \n', max( div_err   ), mean( div_err   ), max( div_it    ) );
fprintf( ' mul  | % .14f | % .14f  | %.5f \n', max( mul_err   ), mean( mul_err   ), max( mul_it    ) );
fprintf( ' mul  | % .14f | % .14f  | %.5f \n', max( mul_err   ), mean( mul_err   ), max( mul_it    ) );
fprintf( ' atanh| % .14f | % .14f  | %.5f \n', max( atanh_err ), mean( atanh_err ), max( atanh_it  ) );
fprintf( ' atanh| % .14f | % .14f  | %.5f \n', max( atanh_err ), mean( atanh_err ), max( atanh_it  ) );
fprintf( ' sqrt | % .14f | % .14f  | %.5f \n', max( sqrt_err  ), mean( sqrt_err  ), max( sqrt_it   ) );
fprintf( ' sqrt | % .14f | % .14f  | %.5f \n', max( sqrt_err  ), mean( sqrt_err  ), max( sqrt_it   ) );
fprintf( ' sinh | % .14f | % .14f  | %.5f \n', max( sinh_err  ), mean( sinh_err  ), max( sinh_it   ) );
fprintf( ' sinh | % .14f | % .14f  | %.5f \n', max( sinh_err  ), mean( sinh_err  ), max( sinh_it   ) );
fprintf( ' cosh | % .14f | % .14f  | %.5f \n', max( cosh_err  ), mean( cosh_err  ), max( cosh_it   ) );
fprintf( ' cosh | % .14f | % .14f  | %.5f \n', max( cosh_err  ), mean( cosh_err  ), max( cosh_it   ) );
 
 
end
 
 
=======
=======
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_a, data_b, tb_fid );
[ ~, ~, 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 );
[ ~, div_err, it_3 ]                = cdiv( data_a_div, data_b_div, tb_fid );
[ ~, mul_err, it_4 ]                = cmul( data_a, data_b, 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 );
[ ~, ~, 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 );
[ ~, ~, sinh_err, cosh_err, it_6 ]  = csinhcosh( data_a, tb_fid );
=======
=======
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
fprintf( ' ___________________________________________________________________\n' );
fprintf( ' ___________________________________________________________________\n' );
fprintf( '                  %s\n', title);
fprintf( '                  %s\n', title);
fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
fprintf( '      |     max error     |   mean error       |  max iterations  \n'   );
fprintf( '      |     max error     |   mean error       |  max iterations  \n'   );
fprintf( ' atan | % .14f | % .14f  | %.5f \n', max( atan_err  ), mean( atan_err  ), max( atan_it   ) );
fprintf( ' atan | % .14f | % .14f  | %.5f \n', max( atan_err  ), mean( atan_err  ), max( atan_it   ) );
fprintf( ' abs  | % .14f | % .14f  | %.5f \n', max( abs_err   ), mean( abs_err   ), max( abs_it    ) );
fprintf( ' abs  | % .14f | % .14f  | %.5f \n', max( abs_err   ), mean( abs_err   ), max( abs_it    ) );
fprintf( ' sin  | % .14f | % .14f  | %.5f \n', max( sin_err   ), mean( sin_err   ), max( sin_it    ) );
fprintf( ' sin  | % .14f | % .14f  | %.5f \n', max( sin_err   ), mean( sin_err   ), max( sin_it    ) );
fprintf( ' cos  | % .14f | % .14f  | %.5f \n', max( cos_err   ), mean( cos_err   ), max( cos_it    ) );
fprintf( ' cos  | % .14f | % .14f  | %.5f \n', max( cos_err   ), mean( cos_err   ), max( cos_it    ) );
fprintf( ' x    | % .14f | % .14f  | %.5f \n', max( x_err     ), mean( x_err     ), max( x_it      ) );
fprintf( ' x    | % .14f | % .14f  | %.5f \n', max( x_err     ), mean( x_err     ), max( x_it      ) );
fprintf( ' y    | % .14f | % .14f  | %.5f \n', max( y_err     ), mean( y_err     ), max( y_it      ) );
fprintf( ' y    | % .14f | % .14f  | %.5f \n', max( y_err     ), mean( y_err     ), max( y_it      ) );
fprintf( ' div  | % .14f | % .14f  | %.5f \n', max( div_err   ), mean( div_err   ), max( div_it    ) );
fprintf( ' div  | % .14f | % .14f  | %.5f \n', max( div_err   ), mean( div_err   ), max( div_it    ) );
fprintf( ' mul  | % .14f | % .14f  | %.5f \n', max( mul_err   ), mean( mul_err   ), max( mul_it    ) );
fprintf( ' mul  | % .14f | % .14f  | %.5f \n', max( mul_err   ), mean( mul_err   ), max( mul_it    ) );
fprintf( ' atanh| % .14f | % .14f  | %.5f \n', max( atanh_err ), mean( atanh_err ), max( atanh_it  ) );
fprintf( ' atanh| % .14f | % .14f  | %.5f \n', max( atanh_err ), mean( atanh_err ), max( atanh_it  ) );
fprintf( ' sqrt | % .14f | % .14f  | %.5f \n', max( sqrt_err  ), mean( sqrt_err  ), max( sqrt_it   ) );
fprintf( ' sqrt | % .14f | % .14f  | %.5f \n', max( sqrt_err  ), mean( sqrt_err  ), max( sqrt_it   ) );
fprintf( ' sinh | % .14f | % .14f  | %.5f \n', max( sinh_err  ), mean( sinh_err  ), max( sinh_it   ) );
fprintf( ' sinh | % .14f | % .14f  | %.5f \n', max( sinh_err  ), mean( sinh_err  ), max( sinh_it   ) );
fprintf( ' cosh | % .14f | % .14f  | %.5f \n', max( cosh_err  ), mean( cosh_err  ), max( cosh_it   ) );
fprintf( ' cosh | % .14f | % .14f  | %.5f \n', max( cosh_err  ), mean( cosh_err  ), max( cosh_it   ) );
 
 
 
end
end
>>>>>>> initial commit
>>>>>>> initial commit
 
 
 
 
 
end
 
 
 
 
 
 
function [sinh_res, cosh_res, sinh_err, cosh_err, it ]= csinhcosh( th, fid )
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 C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
xi = repmat( (2^(XY_WIDTH-1)-1), size( th ) );
xi = repmat( (2^(XY_WIDTH-1)-1), size( th ) );
yi = zeros( 1, length( th ) );
yi = zeros( 1, length( th ) );
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
 
 
 
 
 
 
mode = C_MODE_HYP;
mode = C_MODE_HYP;
 
 
 
 
% cordic version
% cordic version
[ rcosh rsinh ra, it ] = cordic_iterative( ...
[ rcosh rsinh ra, it ] = cordic_iterative( ...
                                           xi,          ...
                                           xi,          ...
                                           yi,          ...
                                           yi,          ...
                                           ai,          ...
                                           ai,          ...
                                           mode,        ...
                                           mode,        ...
                                           XY_WIDTH,    ...
                                           XY_WIDTH,    ...
                                           ANGLEWIDTH,  ...
                                           ANGLEWIDTH,  ...
                                           GUARDBITS,   ...
                                           GUARDBITS,   ...
                                           RM_GAIN );
                                           RM_GAIN );
 
 
 
 
 
 
cosh_res = rcosh  ./ (   2^(XY_WIDTH-1)-1 );
cosh_res = rcosh  ./ (   2^(XY_WIDTH-1)-1 );
sinh_res = rsinh  ./ (   2^(XY_WIDTH-1)-1 );
sinh_res = rsinh  ./ (   2^(XY_WIDTH-1)-1 );
cosh_m = cosh( th );
cosh_m = cosh( th );
sinh_m = sinh( th );
sinh_m = sinh( th );
sinh_err = abs(sinh_res - sinh_m );
sinh_err = abs(sinh_res - sinh_m );
cosh_err = abs(cosh_res - cosh_m );
cosh_err = abs(cosh_res - cosh_m );
 
 
 
 
% write TB data
% write TB data
write_tb( fid, xi, yi, ai, rcosh, rsinh, ra, mode );
write_tb( fid, xi, yi, ai, rcosh, rsinh, ra, mode );
 
 
 
 
end
end
 
 
 
 
 
 
 
 
 
 
function [atan_res, abs_res, atan_err, abs_err, it ]  = catanh( x, y, fid )
function [atan_res, abs_res, atan_err, abs_err, it ]  = catanh( x, y, fid )
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
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
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
if( size( x ) ~= size( y ) )
if( size( x ) ~= size( y ) )
    error( 'size error' )
    error( 'size error' )
end
end
ai = zeros( size( x ) );
ai = zeros( size( x ) );
xi = round( x * (2^(XY_WIDTH-1)-1) );
xi = round( x * (2^(XY_WIDTH-1)-1) );
yi = round( y * (2^(XY_WIDTH-1)-1) );
yi = round( y * (2^(XY_WIDTH-1)-1) );
 
 
 
 
mode = C_FLAG_VEC_ROT + C_MODE_HYP;
mode = C_FLAG_VEC_ROT + C_MODE_HYP;
 
 
 
 
% cordic version
% cordic version
[ rx, ry, ra, it ] = cordic_iterative( xi,          ...
[ rx, ry, ra, it ] = cordic_iterative( xi,          ...
                                  yi,          ...
                                  yi,          ...
                                  ai,          ...
                                  ai,          ...
                                  mode,        ...
                                  mode,        ...
                                  XY_WIDTH,    ...
                                  XY_WIDTH,    ...
                                  ANGLEWIDTH,  ...
                                  ANGLEWIDTH,  ...
                                  GUARDBITS,   ...
                                  GUARDBITS,   ...
                                  RM_GAIN );
                                  RM_GAIN );
% matlab version
% matlab version
m_th = atanh( y ./ x );
m_th = atanh( y ./ x );
m_r  = sqrt( x.^2 - y.^2 );
m_r  = sqrt( x.^2 - y.^2 );
 
 
% comparison
% comparison
atan_res = ra ./ 2^( (ANGLEWIDTH)-1);
atan_res = ra ./ 2^( (ANGLEWIDTH)-1);
abs_res  = rx ./ ( 2^(XY_WIDTH-1) -1 );
abs_res  = rx ./ ( 2^(XY_WIDTH-1) -1 );
atan_err = abs( m_th - atan_res );
atan_err = abs( m_th - atan_res );
abs_err  = abs( m_r  -  abs_res );
abs_err  = abs( m_r  -  abs_res );
 
 
% write TB data
% write TB data
write_tb( fid, xi, yi, ai, rx, ry, ra, mode );
write_tb( fid, xi, yi, ai, rx, ry, ra, mode );
 
 
 
 
end
end
 
 
 
 
 
 
 
 
 
 
function [mul_res, mul_err, it ] = cmul( x, y, fid )
function [mul_res, mul_err, it ] = cmul( x, y, fid )
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
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
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
if( size( x ) ~= size( y ) )
if( size( x ) ~= size( y ) )
    error( 'size error' )
    error( 'size error' )
end
end
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
ai = round( y * ( 2^(XY_WIDTH-1) -1 ) );
ai = round( y * ( 2^(XY_WIDTH-1) -1 ) );
yi = zeros( size( x ) );
yi = zeros( size( x ) );
 
 
 
 
mode = C_MODE_LIN;
mode = C_MODE_LIN;
 
 
% cordic version
% cordic version
[ rx, rmul, ra, it ] = cordic_iterative( xi,          ...
[ rx, rmul, ra, it ] = cordic_iterative( xi,          ...
                                        yi,          ...
                                        yi,          ...
                                        ai,          ...
                                        ai,          ...
                                        mode,        ...
                                        mode,        ...
                                        XY_WIDTH,    ...
                                        XY_WIDTH,    ...
                                        ANGLEWIDTH,  ...
                                        ANGLEWIDTH,  ...
                                        GUARDBITS,   ...
                                        GUARDBITS,   ...
                                        RM_GAIN );
                                        RM_GAIN );
 
 
 
 
mul_res  = rmul ./ (2^(ANGLEWIDTH-1)-1);
mul_res  = rmul ./ (2^(ANGLEWIDTH-1)-1);
mul_err  = abs( y.*x -  mul_res );
mul_err  = abs( y.*x -  mul_res );
 
 
% write TB data
% write TB data
write_tb( fid, xi, yi, ai, rx, rmul, ra, mode )
write_tb( fid, xi, yi, ai, rx, rmul, ra, mode )
 
 
 
 
end
end
 
 
 
 
 
 
 
 
 
 
function [div_res, div_err, it ] = cdiv( x, y, fid )
function [div_res, div_err, it ] = cdiv( x, y, fid )
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
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
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
if( size( x ) ~= size( y ) )
if( size( x ) ~= size( y ) )
    error( 'size error' )
    error( 'size error' )
end
end
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
yi = round( y * ( 2^(XY_WIDTH-1) -1 ) );
yi = round( y * ( 2^(XY_WIDTH-1) -1 ) );
ai = zeros( size( x ) );
ai = zeros( size( x ) );
 
 
 
 
mode = C_FLAG_VEC_ROT + C_MODE_LIN;
mode = C_FLAG_VEC_ROT + C_MODE_LIN;
 
 
% cordic version
% cordic version
[ rx, ry, rdiv, it ] = cordic_iterative( xi,          ...
[ rx, ry, rdiv, it ] = cordic_iterative( xi,          ...
                                  yi,          ...
                                  yi,          ...
                                  ai,          ...
                                  ai,          ...
                                  mode,        ...
                                  mode,        ...
                                  XY_WIDTH,    ...
                                  XY_WIDTH,    ...
                                  ANGLEWIDTH,  ...
                                  ANGLEWIDTH,  ...
                                  GUARDBITS,   ...
                                  GUARDBITS,   ...
                                  RM_GAIN );
                                  RM_GAIN );
 
 
 
 
div_res  = rdiv ./ (2^(ANGLEWIDTH-1)-1);
div_res  = rdiv ./ (2^(ANGLEWIDTH-1)-1);
div_err  = abs( y./x -  div_res );
div_err  = abs( y./x -  div_res );
 
 
% write TB data
% write TB data
write_tb( fid, xi, yi, ai, rx, ry, rdiv, mode )
write_tb( fid, xi, yi, ai, rx, ry, rdiv, mode )
 
 
end
end
 
 
 
 
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
function [x_res, y_res, x_err, y_err, it ] = crot( x, y, th, fid )
function [x_res, y_res, x_err, y_err, it ] = crot( x, y, th, fid )
%
%
% does a multiplication with exp( th * i )
% does a multiplication with exp( th * i )
% and therefore, a rotation of the complex input value x + yi where th
% and therefore, a rotation of the complex input value x + yi where th
% defines the rotation angle
% defines the rotation angle
%
%
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
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
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
yi = round( y * ( 2^(XY_WIDTH-1) -1 ) );
yi = round( y * ( 2^(XY_WIDTH-1) -1 ) );
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
 
 
mode = C_MODE_CIRC;
mode = C_MODE_CIRC;
 
 
[ rx ry ra, it ] = cordic_iterative( ...
[ rx ry ra, it ] = cordic_iterative( ...
                                  xi,          ...
                                  xi,          ...
                                  yi,          ...
                                  yi,          ...
                                  ai,          ...
                                  ai,          ...
                                  mode,        ...
                                  mode,        ...
                                  XY_WIDTH,    ...
                                  XY_WIDTH,    ...
                                  ANGLEWIDTH,  ...
                                  ANGLEWIDTH,  ...
                                  GUARDBITS,   ...
                                  GUARDBITS,   ...
                                  RM_GAIN );
                                  RM_GAIN );
 
 
tmp = ( x + 1i * y ) .* exp( i * th );
tmp = ( x + 1i * y ) .* exp( i * th );
 
 
x_res = rx  ./ (   2^(XY_WIDTH-1)-1 );
x_res = rx  ./ (   2^(XY_WIDTH-1)-1 );
y_res = ry  ./ (   2^(XY_WIDTH-1)-1 );
y_res = ry  ./ (   2^(XY_WIDTH-1)-1 );
 
 
y_err = abs(x_res - real(tmp) );
y_err = abs(x_res - real(tmp) );
x_err = abs(y_res - imag(tmp) );
x_err = abs(y_res - imag(tmp) );
 
 
% write TB data
% write TB data
write_tb( fid, xi, yi, ai, rx, ry, ra, mode )
write_tb( fid, xi, yi, ai, rx, ry, ra, mode )
 
 
 
 
end
end
 
 
 
 
function [sin_res, cos_res, sin_err, cos_err, it ]= cpol2cart( th, r, fid )
function [sin_res, cos_res, sin_err, cos_err, it ]= cpol2cart( th, r, fid )
%
%
% does the Matlab equivalent pol2cart
% does the Matlab equivalent pol2cart
%
%
 
 
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
 
 
 
 
 
 
function [sin_res, cos_res, sin_err, cos_err, it ]= cpol2cart( th, r, fid )
function [sin_res, cos_res, sin_err, cos_err, it ]= cpol2cart( th, r, fid )
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
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
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
xi = r .* (2^(XY_WIDTH-1)-1);
xi = r .* (2^(XY_WIDTH-1)-1);
yi = zeros( 1, length( th ) );
yi = zeros( 1, length( th ) );
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
 
 
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
mode = C_MODE_CIRC;
mode = C_MODE_CIRC;
 
 
=======
=======
 
 
 
 
mode = C_MODE_CIRC;
mode = C_MODE_CIRC;
 
 
 
 
% cordic version
% cordic version
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
mode = C_MODE_CIRC;
mode = C_MODE_CIRC;
 
 
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
[ rcos rsin ra, it ] = cordic_iterative( ...
[ rcos rsin ra, it ] = cordic_iterative( ...
                                  xi,          ...
                                  xi,          ...
                                  yi,          ...
                                  yi,          ...
                                  ai,          ...
                                  ai,          ...
                                  mode,        ...
                                  mode,        ...
                                  XY_WIDTH,    ...
                                  XY_WIDTH,    ...
                                  ANGLEWIDTH,  ...
                                  ANGLEWIDTH,  ...
                                  GUARDBITS,   ...
                                  GUARDBITS,   ...
                                  RM_GAIN );
                                  RM_GAIN );
 
 
 
 
 
 
cos_res = rcos  ./ (   2^(XY_WIDTH-1)-1 );
cos_res = rcos  ./ (   2^(XY_WIDTH-1)-1 );
sin_res = rsin  ./ (   2^(XY_WIDTH-1)-1 );
sin_res = rsin  ./ (   2^(XY_WIDTH-1)-1 );
[ cos_m, sin_m ] = pol2cart( th, r );
[ cos_m, sin_m ] = pol2cart( th, r );
sin_err = abs(sin_res - sin_m );
sin_err = abs(sin_res - sin_m );
cos_err = abs(cos_res - cos_m );
cos_err = abs(cos_res - cos_m );
 
 
% write TB data
% write TB data
write_tb( fid, xi, yi, ai, rcos, rsin, ra, mode )
write_tb( fid, xi, yi, ai, rcos, rsin, ra, mode )
 
 
 
 
end
end
 
 
 
 
 
 
 
 
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
 
 
=======
=======
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
 
 
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
function [atan_res, abs_res, atan_err, abs_err, it ]  = ccart2pol( x, y, fid )
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
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
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
 
 
if( size( x ) ~= size( y ) )
if( size( x ) ~= size( y ) )
    error( 'size error' )
    error( 'size error' )
end
end
ai = zeros( size( x ) );
ai = zeros( size( x ) );
xi = round( x * (2^(XY_WIDTH-1)-1) );
xi = round( x * (2^(XY_WIDTH-1)-1) );
yi = round( y * (2^(XY_WIDTH-1)-1) );
yi = round( y * (2^(XY_WIDTH-1)-1) );
 
 
 
 
mode = C_FLAG_VEC_ROT + C_MODE_CIRC;
mode = C_FLAG_VEC_ROT + C_MODE_CIRC;
 
 
 
 
% cordic version
% cordic version
[ rx, ry, ra, it ] = cordic_iterative( xi,          ...
[ rx, ry, ra, it ] = cordic_iterative( xi,          ...
                                  yi,          ...
                                  yi,          ...
                                  ai,          ...
                                  ai,          ...
                                  mode,        ...
                                  mode,        ...
                                  XY_WIDTH,    ...
                                  XY_WIDTH,    ...
                                  ANGLEWIDTH,  ...
                                  ANGLEWIDTH,  ...
                                  GUARDBITS,   ...
                                  GUARDBITS,   ...
                                  RM_GAIN );
                                  RM_GAIN );
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
% matlab version:
% matlab version:
m_th = atan2( y,  x );
m_th = atan2( y,  x );
m_r  = sqrt( x.^2 + y.^2 );
m_r  = sqrt( x.^2 + y.^2 );
 
 
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
% matlab version
% matlab version
[m_th, m_r ] = cart2pol( x, y );
[m_th, m_r ] = cart2pol( x, y );
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
 
 
% comparison
% comparison
atan_res = ra ./ 2^( (ANGLEWIDTH)-1);
atan_res = ra ./ 2^( (ANGLEWIDTH)-1);
abs_res  = rx ./ ( 2^(XY_WIDTH-1) -1 );
abs_res  = rx ./ ( 2^(XY_WIDTH-1) -1 );
atan_err = abs( m_th - atan_res );
atan_err = abs( m_th - atan_res );
abs_err  = abs( m_r  -  abs_res );
abs_err  = abs( m_r  -  abs_res );
 
 
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
 
 
=======
=======
>>>>>>> initial commit
>>>>>>> initial commit
=======
=======
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
 
 
>>>>>>> Updated C and RTL model as well as the documentation
>>>>>>> Updated C and RTL model as well as the documentation
% write TB data
% write TB data
write_tb( fid, xi, yi, ai, rx, ry, ra, mode )
write_tb( fid, xi, yi, ai, rx, ry, ra, mode )
 
 
end
end
 
 
 
 
 
 
 
 
 
 
function write_tb( fid, x_i, y_i, a_i, x_o, y_o, a_o, mode )
 
 
 
if fid > 0
 
    for x = 1 : length( x_i )
 
        fprintf( fid, '%ld ', fix( [ x_i(x), y_i(x), a_i(x), x_o(x), y_o(x), a_o(x), mode ] ) );
 
        fprintf( fid, '\n' );
 
    end
 
end
 
 
 
end
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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