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

Subversion Repositories yac

[/] [yac/] [trunk/] [c_octave/] [cordic_iterative_test.m] - Diff between revs 2 and 3

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

Rev 2 Rev 3
Line 18... Line 18...
%%%%        and to generate stimulus data for RTL simulation.           %%%%
%%%%        and to generate stimulus data for RTL simulation.           %%%%
%%%%        This created data is used to ensure, that the C             %%%%
%%%%        This created data is used to ensure, that the C             %%%%
%%%%        implementation behaves the same than the VHDL               %%%%
%%%%        implementation behaves the same than the VHDL               %%%%
%%%%        implementation.                                             %%%%
%%%%        implementation.                                             %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
 
<<<<<<< HEAD
%%%%        Three tests are implemented:                                %%%%
%%%%        Three tests are implemented:                                %%%%
%%%%          - Random test values                                      %%%%
%%%%          - Random test values                                      %%%%
%%%%          - Linear increasing values                                %%%%
%%%%          - Linear increasing values                                %%%%
%%%%          - Limit values                                            %%%%
%%%%          - Limit values                                            %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%        Please do  'mex cordic_iterative.c' to create               %%%%
%%%%        Please do  'mex cordic_iterative.c' to create               %%%%
%%%%        the cordic_iterative.mex.                                   %%%%
%%%%        the cordic_iterative.mex.                                   %%%%
 
=======
 
>>>>>>> initial commit
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%%                                                                  %%%%%
%%%%%                                                                  %%%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%  TODO                                                              %%%%
%%%%  TODO                                                              %%%%
 
<<<<<<< HEAD
%%%%        The linear test is not complete                             %%%%
%%%%        The linear test is not complete                             %%%%
 
=======
 
%%%%        Some documentation and function description                 %%%%
 
>>>>>>> initial commit
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Line 57... Line 64...
%%%% You should have received a copy of the GNU Lesser General Public   %%%%
%%%% You should have received a copy of the GNU Lesser General Public   %%%%
%%%% License along with this library. If not, download it from          %%%%
%%%% License along with this library. If not, download it from          %%%%
%%%% http://www.gnu.org/licenses/lgpl                                   %%%%
%%%% http://www.gnu.org/licenses/lgpl                                   %%%%
%%%%                                                                    %%%%
%%%%                                                                    %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
<<<<<<< HEAD
function cordic_iterative_test( )
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
% global flags/values, they are static
% 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
 
 
Line 93... Line 117...
% Number of tests, which are run
% Number of tests, which are run
N_TESTS    = 10000;
N_TESTS    = 10000;
 
 
% open test file
% open test file
tb_fid = fopen( './tb_data.txt', 'w' );
tb_fid = fopen( './tb_data.txt', 'w' );
 
<<<<<<< HEAD
%tb_fid = 0;
%tb_fid = 0;
 
 
 
 
 
 
 
 
Line 169... Line 194...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    0,  0, ...
    'Limit Value Test' );
    'Limit Value Test' );
 
=======
 
 
 
% run test, which uses random values
 
run_random_test( N_TESTS, tb_fid );
 
 
 
% close file
 
fclose( tb_fid );
 
 
 
>>>>>>> initial commit
 
 
end
end
 
 
 
 
 
 
 
<<<<<<< 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 )
%
%
Line 229... Line 264...
%
%
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 )
 
 
 
data_a = -1 + 2 .* rand( 1, N_TESTS );
 
data_b = -1 + 2 .* rand( 1, N_TESTS );
 
 
 
>>>>>>> initial commit
% 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
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;
 
>>>>>>> initial commit
 
 
 
 
 
 
[ ~, ~, 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
[ ~, ~, 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 );
Line 301... Line 348...
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
 
 
 
=======
 
[ ~, ~, 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 )
function [sinh_res, cosh_res, sinh_err, cosh_err, it ]= csinhcosh( th, fid )
Line 465... Line 536...
write_tb( fid, xi, yi, ai, rx, ry, rdiv, mode )
write_tb( fid, xi, yi, ai, rx, ry, rdiv, mode )
 
 
end
end
 
 
 
 
 
<<<<<<< HEAD
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
Line 510... Line 582...
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
%
%
 
 
 
=======
 
 
 
 
 
 
 
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 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
 
mode = C_MODE_CIRC;
 
 
 
=======
 
 
 
 
mode = C_MODE_CIRC;
mode = C_MODE_CIRC;
 
 
 
 
 
% cordic version
 
>>>>>>> initial commit
[ rcos rsin ra, it ] = cordic_iterative( ...
[ rcos rsin ra, it ] = cordic_iterative( ...
                                  xi,          ...
                                  xi,          ...
                                  yi,          ...
                                  yi,          ...
                                  ai,          ...
                                  ai,          ...
                                  mode,        ...
                                  mode,        ...
Line 546... Line 633...
end
end
 
 
 
 
 
 
 
 
 
<<<<<<< HEAD
 
 
 
=======
 
>>>>>>> initial commit
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
 
 
Line 572... Line 662...
                                  mode,        ...
                                  mode,        ...
                                  XY_WIDTH,    ...
                                  XY_WIDTH,    ...
                                  ANGLEWIDTH,  ...
                                  ANGLEWIDTH,  ...
                                  GUARDBITS,   ...
                                  GUARDBITS,   ...
                                  RM_GAIN );
                                  RM_GAIN );
 
<<<<<<< HEAD
% 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 );
 
 
 
=======
 
% matlab version
 
[m_th, m_r ] = cart2pol( x, y );
 
>>>>>>> initial commit
 
 
% 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
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
 
 
 
=======
 
>>>>>>> initial commit
% 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
 
 

powered by: WebSVN 2.1.0

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