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

Subversion Repositories yac

[/] [yac/] [trunk/] [c_octave/] [cordic_iterative_test.m] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 feddischso
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
%%%%                                                                    %%%%
3
%%%%  File           : cordic_iterative_test.m                          %%%%
4
%%%%  Project        : YAC (Yet Another CORDIC Core)                    %%%%
5
%%%%  Creation       : Feb. 2014                                        %%%%
6
%%%%  Limitations    :                                                  %%%%
7
%%%%  Platform       : Linux, Mac, Windows                              %%%%
8
%%%%  Target         : Octave, Matlab                                   %%%%
9
%%%%                                                                    %%%%
10
%%%%  Author(s):     : Christian Haettich                               %%%%
11
%%%%  Email          : feddischson@opencores.org                        %%%%
12
%%%%                                                                    %%%%
13
%%%%                                                                    %%%%
14
%%%%%                                                                  %%%%%
15
%%%%                                                                    %%%%
16
%%%%  Description                                                       %%%%
17
%%%%        Script to test/analyze the cordic C implementation          %%%%
18
%%%%        and to generate stimulus data for RTL simulation.           %%%%
19
%%%%        This created data is used to ensure, that the C             %%%%
20
%%%%        implementation behaves the same than the VHDL               %%%%
21
%%%%        implementation.                                             %%%%
22
%%%%                                                                    %%%%
23 3 feddischso
<<<<<<< HEAD
24 4 feddischso
<<<<<<< HEAD
25
=======
26
>>>>>>> Updated C and RTL model as well as the documentation
27 2 feddischso
%%%%        Three tests are implemented:                                %%%%
28
%%%%          - Random test values                                      %%%%
29
%%%%          - Linear increasing values                                %%%%
30
%%%%          - Limit values                                            %%%%
31
%%%%                                                                    %%%%
32
%%%%                                                                    %%%%
33
%%%%        Please do  'mex cordic_iterative.c' to create               %%%%
34
%%%%        the cordic_iterative.mex.                                   %%%%
35 4 feddischso
<<<<<<< HEAD
36 3 feddischso
=======
37
>>>>>>> initial commit
38 4 feddischso
=======
39
>>>>>>> Updated C and RTL model as well as the documentation
40 2 feddischso
%%%%                                                                    %%%%
41
%%%%%                                                                  %%%%%
42
%%%%                                                                    %%%%
43
%%%%  TODO                                                              %%%%
44 3 feddischso
<<<<<<< HEAD
45 4 feddischso
<<<<<<< HEAD
46 2 feddischso
%%%%        The linear test is not complete                             %%%%
47 3 feddischso
=======
48
%%%%        Some documentation and function description                 %%%%
49
>>>>>>> initial commit
50 4 feddischso
=======
51
%%%%        The linear test is not complete                             %%%%
52
>>>>>>> Updated C and RTL model as well as the documentation
53 2 feddischso
%%%%                                                                    %%%%
54
%%%%                                                                    %%%%
55
%%%%                                                                    %%%%
56
%%%%                                                                    %%%%
57
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
%%%%                                                                    %%%%
59
%%%%                  Copyright Notice                                  %%%%
60
%%%%                                                                    %%%%
61
%%%% This file is part of YAC - Yet Another CORDIC Core                 %%%%
62
%%%% Copyright (c) 2014, Author(s), All rights reserved.                %%%%
63
%%%%                                                                    %%%%
64
%%%% YAC is free software; you can redistribute it and/or               %%%%
65
%%%% modify it under the terms of the GNU Lesser General Public         %%%%
66
%%%% License as published by the Free Software Foundation; either       %%%%
67
%%%% version 3.0 of the License, or (at your option) any later version. %%%%
68
%%%%                                                                    %%%%
69
%%%% YAC is distributed in the hope that it will be useful,             %%%%
70
%%%% but WITHOUT ANY WARRANTY; without even the implied warranty of     %%%%
71
%%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  %%%%
72
%%%% Lesser General Public License for more details.                    %%%%
73
%%%%                                                                    %%%%
74
%%%% You should have received a copy of the GNU Lesser General Public   %%%%
75
%%%% License along with this library. If not, download it from          %%%%
76
%%%% http://www.gnu.org/licenses/lgpl                                   %%%%
77
%%%%                                                                    %%%%
78
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 3 feddischso
<<<<<<< HEAD
80 4 feddischso
<<<<<<< HEAD
81 2 feddischso
function cordic_iterative_test( )
82
 
83
 
84
 
85 3 feddischso
=======
86
 
87
 
88
 
89 4 feddischso
=======
90
>>>>>>> Updated C and RTL model as well as the documentation
91 3 feddischso
function cordic_iterative_test( )
92
 
93
 
94 4 feddischso
 
95 3 feddischso
>>>>>>> initial commit
96 2 feddischso
% global flags/values, they are static
97
% through the whole script and defined below
98
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
99
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
100
 
101
 
102 7 feddischso
cordic_iterative_setup
103 2 feddischso
 
104 7 feddischso
% open output file
105
tb_fid = fopen( TB_FILE, 'w' );
106 2 feddischso
 
107
% Number of tests, which are run
108
N_TESTS    = 10000;
109
 
110 7 feddischso
<<<<<<< HEAD
111 2 feddischso
% open test file
112
tb_fid = fopen( './tb_data.txt', 'w' );
113 3 feddischso
<<<<<<< HEAD
114 4 feddischso
<<<<<<< HEAD
115 2 feddischso
%tb_fid = 0;
116
 
117
 
118
 
119
 
120
 
121
%
122
% run test, which uses random values
123
run_random_test( N_TESTS, tb_fid );
124
%
125
% run tests, which test limits
126
run_limit_test( tb_fid );
127
%
128
% run linear value test
129
run_linear_test( 1000, tb_fid );
130
 
131
% close file
132
if tb_fid > 0
133
    fclose( tb_fid );
134
end
135
 
136
end
137
 
138
 
139
 
140
 
141
function run_limit_test( tb_fid )
142
%RUN_LIMIT_TEST Test the range limit
143
%
144
% run_limit_test( fid )
145
%
146
% This function is used to generate a test pattern
147
% with values, which are at the range limit.
148
% This values are then processed by the fixed-point YAC
149
% implementation. All input and outputs are logged into
150
% a testbench pattern file.
151
%
152
% The argument fid is the file-descriptor of the testbench pattern
153
% file.
154
%
155
 
156
 
157
data_a = [ 0 1 0 1 -1  0 -1  1 -1 ];
158
data_b = [ 0 0 1 1  0 -1 -1 -1  1 ];
159
 
160
data_c = [ 0 0 0 0  0  0  0  0  0 ...
161
           1 1 1 1  1  1  1  1  1 ...
162
           -1 -1 -1 -1 -1 -1 -1 -1 -1 ];
163
 
164
data_d = data_a * pi;
165
 
166
data_a_div = [ 0.5 ,1 -0.5, -1, -0.5, -1 ];
167
data_b_div = [ 1   ,1,  1,   1,   -1, -1 ];
168
 
169
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
170
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
171
[ ~, ~, x_err, y_err, it_3 ]        = crot( [ data_a, data_a, data_a], ...
172
                                            [ data_b, data_b, data_b], ...
173
                                              data_c, tb_fid );
174
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
175
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
176
 
177
print_result_info(    ...
178
    atan_err,   it_1, ...
179
    abs_err,    it_1, ...
180
    sin_err,    it_2, ...
181
    cos_err,    it_2, ...
182
    x_err,      it_3, ...
183
    y_err,      it_3, ...
184
    div_err,    it_4, ...
185
    mul_err,    it_5, ...
186
    0,  0, ...
187
    0,  0, ...
188
    0,  0, ...
189
    0,  0, ...
190
    'Limit Value Test' );
191 3 feddischso
=======
192 4 feddischso
=======
193
%tb_fid = 0;
194 2 feddischso
 
195 4 feddischso
>>>>>>> Updated C and RTL model as well as the documentation
196
 
197
 
198
 
199 7 feddischso
=======
200
>>>>>>> Removed some bugs regarding pre-rotation and negative numbers in the wb wrapper
201 4 feddischso
 
202
%
203 3 feddischso
% run test, which uses random values
204
run_random_test( N_TESTS, tb_fid );
205 4 feddischso
%
206
% run tests, which test limits
207
run_limit_test( tb_fid );
208
%
209
% run linear value test
210
run_linear_test( 1000, tb_fid );
211 3 feddischso
 
212
% close file
213 4 feddischso
if tb_fid > 0
214
    fclose( tb_fid );
215
end
216 3 feddischso
 
217 4 feddischso
end
218
 
219
 
220
 
221
 
222
function run_limit_test( tb_fid )
223
%RUN_LIMIT_TEST Test the range limit
224
%
225
% run_limit_test( fid )
226
%
227
% This function is used to generate a test pattern
228
% with values, which are at the range limit.
229
% This values are then processed by the fixed-point YAC
230
% implementation. All input and outputs are logged into
231
% a testbench pattern file.
232
%
233
% The argument fid is the file-descriptor of the testbench pattern
234
% file.
235
%
236
 
237
 
238
<<<<<<< HEAD
239 3 feddischso
>>>>>>> initial commit
240
 
241 2 feddischso
end
242
 
243
 
244
 
245 3 feddischso
<<<<<<< HEAD
246 2 feddischso
function run_linear_test( N_TESTS, tb_fid )
247
%RUN_LINEAR_TEST Generates a linear test pattern
248
%
249
% run_linear_test( N, fid )
250
%
251
% This function is used to generate linear increasing test
252
% values.
253
% These values are then processed by the fixed-point YAC
254
% implementation. All input and outputs are logged into
255
% a testbench pattern file. In addition, the result is plotted.
256
%
257
% NOTE: only the hyperbolic functions are processed at the moment.
258
% This function needs to be extended in future.
259
%
260
%
261
% The argument fid is the file-descriptor of the testbench pattern
262
% file. The argument N defines the number of values, which are processed.
263
%
264
%
265
 
266
data_a_h = ones( 1, N_TESTS );
267
data_b_h = linspace( -1, 1, N_TESTS ) * 0.78;
268
data_c_h = linspace( -1, 1, N_TESTS );
269
[ atanh_res, sqrt_res, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
270
[ sinh_res, cosh_res, sinh_err, cosh_err, it_7 ]   = csinhcosh( data_c_h, tb_fid );
271
 
272 4 feddischso
=======
273
data_a = [ 0 1 0 1 -1  0 -1  1 -1 ];
274
data_b = [ 0 0 1 1  0 -1 -1 -1  1 ];
275 2 feddischso
 
276 4 feddischso
data_c = [ 0 0 0 0  0  0  0  0  0 ...
277
           1 1 1 1  1  1  1  1  1 ...
278
           -1 -1 -1 -1 -1 -1 -1 -1 -1 ];
279
 
280
data_d = data_a * pi;
281 7 feddischso
 
282 4 feddischso
data_a_div = [ 0.5 ,1 -0.5, -1, -0.5, -1 ];
283
data_b_div = [ 1   ,1,  1,   1,   -1, -1 ];
284
 
285
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
286
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
287
[ ~, ~, x_err, y_err, it_3 ]        = crot( [ data_a, data_a, data_a], ...
288
                                            [ data_b, data_b, data_b], ...
289
                                              data_c, tb_fid );
290
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
291
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
292 7 feddischso
 
293
print_result(    ...
294 4 feddischso
    atan_err,   it_1, ...
295
    abs_err,    it_1, ...
296
    sin_err,    it_2, ...
297
    cos_err,    it_2, ...
298
    x_err,      it_3, ...
299
    y_err,      it_3, ...
300
    div_err,    it_4, ...
301
    mul_err,    it_5, ...
302
    0,  0, ...
303
    0,  0, ...
304
    0,  0, ...
305
    0,  0, ...
306
    'Limit Value Test' );
307
>>>>>>> Updated C and RTL model as well as the documentation
308
 
309 2 feddischso
figure; plot( data_b_h, atanh_res ); title( 'atanh' );
310
figure; plot( data_b_h, atanh_err ); title( 'atanh-error' );
311
figure; plot( data_c_h, sinh_res, data_c_h, cosh_res ); title( 'sinh and cosh' );
312
figure; plot( data_c_h, sinh_err, data_c_h, cosh_err ); title( 'sinh and cosh errors' );
313
end
314
 
315
 
316
 
317 4 feddischso
<<<<<<< HEAD
318 2 feddischso
function run_random_test( N_TESTS, tb_fid )
319
%RUN_RANDOM_TEST Generates a random test pattern
320
%
321
% run_random_test( N, fid )
322
%
323
% This function is used to generate random test
324
% values (uniform distributed).
325
% These values are then processed by the fixed-point YAC
326
% implementation. All input and outputs are logged into
327
% a testbench pattern file.
328 4 feddischso
=======
329
function run_linear_test( N_TESTS, tb_fid )
330
%RUN_LINEAR_TEST Generates a linear test pattern
331 2 feddischso
%
332 4 feddischso
% run_linear_test( N, fid )
333 2 feddischso
%
334 4 feddischso
% This function is used to generate linear increasing test
335
% values.
336
% These values are then processed by the fixed-point YAC
337
% implementation. All input and outputs are logged into
338
% a testbench pattern file. In addition, the result is plotted.
339
%
340
% NOTE: only the hyperbolic functions are processed at the moment.
341
% This function needs to be extended in future.
342
>>>>>>> Updated C and RTL model as well as the documentation
343
%
344
%
345 2 feddischso
% The argument fid is the file-descriptor of the testbench pattern
346
% file. The argument N defines the number of values, which are processed.
347
%
348
%
349 4 feddischso
<<<<<<< HEAD
350 2 feddischso
data_a = -1 + 2 .* rand( 1, N_TESTS );
351
data_b = -1 + 2 .* rand( 1, N_TESTS );
352
data_c = -1 + 2 .* rand( 1, N_TESTS );
353
data_d = -pi + 2*pi .* rand( 1, N_TESTS );
354 3 feddischso
=======
355
function run_random_test( N_TESTS, tb_fid )
356 4 feddischso
=======
357 3 feddischso
 
358 4 feddischso
data_a_h = ones( 1, N_TESTS );
359
data_b_h = linspace( -1, 1, N_TESTS ) * 0.78;
360
data_c_h = linspace( -1, 1, N_TESTS );
361
[ atanh_res, sqrt_res, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
362
[ sinh_res, cosh_res, sinh_err, cosh_err, it_7 ]   = csinhcosh( data_c_h, tb_fid );
363
 
364
 
365
figure; plot( data_b_h, atanh_res ); title( 'atanh' );
366
figure; plot( data_b_h, atanh_err ); title( 'atanh-error' );
367
figure; plot( data_c_h, sinh_res, data_c_h, cosh_res ); title( 'sinh and cosh' );
368
figure; plot( data_c_h, sinh_err, data_c_h, cosh_err ); title( 'sinh and cosh errors' );
369 7 feddischso
 
370
 
371 4 feddischso
end
372
 
373
 
374
>>>>>>> Updated C and RTL model as well as the documentation
375
 
376
function run_random_test( N_TESTS, tb_fid )
377
%RUN_RANDOM_TEST Generates a random test pattern
378
%
379
% run_random_test( N, fid )
380
%
381
% This function is used to generate random test
382
% values (uniform distributed).
383
% These values are then processed by the fixed-point YAC
384
% implementation. All input and outputs are logged into
385
% a testbench pattern file.
386
%
387
%
388
% The argument fid is the file-descriptor of the testbench pattern
389
% file. The argument N defines the number of values, which are processed.
390
%
391
%
392 3 feddischso
data_a = -1 + 2 .* rand( 1, N_TESTS );
393
data_b = -1 + 2 .* rand( 1, N_TESTS );
394 4 feddischso
<<<<<<< HEAD
395 3 feddischso
 
396
>>>>>>> initial commit
397 4 feddischso
=======
398
data_c = -1 + 2 .* rand( 1, N_TESTS );
399
data_d = -pi + 2*pi .* rand( 1, N_TESTS );
400
>>>>>>> Updated C and RTL model as well as the documentation
401 2 feddischso
% adapat data for division
402
data_a_div = data_a;
403
data_b_div = data_b;
404
swap_div   = ( data_b ./ data_a ) >= 2 | ( data_b ./ data_a ) < -2 ;
405
data_a_div( swap_div ) = data_b( swap_div );
406
data_b_div( swap_div ) = data_a( swap_div );
407
 
408
data_a_h   = ones( size( data_a ) );
409 3 feddischso
<<<<<<< HEAD
410 4 feddischso
<<<<<<< HEAD
411 2 feddischso
data_b_h   = data_b .* 0.80694; %0.78;
412 3 feddischso
=======
413
data_b_h   = data_b .* 0.78;
414
>>>>>>> initial commit
415 4 feddischso
=======
416
data_b_h   = data_b .* 0.80694; %0.78;
417
>>>>>>> Updated C and RTL model as well as the documentation
418 2 feddischso
 
419
 
420
 
421
[ ~, ~, atan_err, abs_err, it_1 ]   = ccart2pol( data_a, data_b, tb_fid );
422 3 feddischso
<<<<<<< HEAD
423 4 feddischso
<<<<<<< HEAD
424
=======
425
>>>>>>> Updated C and RTL model as well as the documentation
426 2 feddischso
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_d, data_b, tb_fid );
427
[ ~, ~, x_err, y_err, it_3 ]        = crot( data_a, data_b, data_c, tb_fid );
428
[ ~, div_err, it_4 ]                = cdiv( data_a_div, data_b_div, tb_fid );
429
[ ~, mul_err, it_5 ]                = cmul( data_a, data_b, tb_fid  );
430
[ ~, ~, atanh_err, sqrt_err, it_6 ] = catanh( data_a_h, data_b_h, tb_fid );
431
[ ~, ~, sinh_err, cosh_err, it_7 ]  = csinhcosh( data_a, tb_fid );
432
 
433
 
434 7 feddischso
print_result_header( 'Random Test Result' );
435
print_result2( 'atan', it_1, atan_err, data_a, data_b );
436
print_result2( 'abs ', it_1, abs_err,  data_a, data_b );
437
print_result2( 'sin ', it_2, sin_err,  data_a, data_b );
438
print_result2( 'cos ', it_2, cos_err,  data_a, data_b );
439
 
440
 
441
 
442
print_result(  atan_err,   it_1, ...
443
               abs_err,    it_1, ...
444
               sin_err,    it_2, ...
445
               cos_err,    it_2, ...
446
               x_err,      it_3, ...
447
               y_err,      it_3, ...
448
               div_err,    it_4, ...
449
               mul_err,    it_5, ...
450
               atanh_err,  it_6, ...
451
               sqrt_err,   it_6, ...
452
               sinh_err,   it_7, ...
453
               cosh_err,   it_7, ...
454
               'Random Value Test' );
455
 
456
 
457 2 feddischso
end
458
 
459 7 feddischso
function print_result_header( title )
460
 printf( ' ___________________________________________________________________\n' );
461
 fprintf( '                  %s\n', title);
462
 fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
463
end
464 2 feddischso
 
465 7 feddischso
function print_result2( msg, it, err, a, b )
466
 
467
[ verr, ierr ] = max( err );
468
fprintf( '%s |  %.14f  | (%.14f %.14f) | %.14f  | %.5f \n', msg, verr, a( ierr ), b( ierr ), mean( err ), max( it ) )
469
 
470
end
471
 
472
 
473
function print_result( ...
474 2 feddischso
    atan_err,   atan_it,    ...
475
    abs_err,    abs_it,     ...
476
    sin_err,    sin_it,     ...
477
    cos_err,    cos_it,     ...
478
    x_err,      x_it,       ...
479
    y_err,      y_it,       ...
480
    div_err,    div_it,     ...
481
    mul_err,    mul_it,     ...
482
    atanh_err,  atanh_it,   ...
483
    sqrt_err,   sqrt_it,    ...
484
    sinh_err,   sinh_it,    ...
485
    cosh_err,   cosh_it,    ...
486
    title )
487 4 feddischso
<<<<<<< HEAD
488 2 feddischso
 
489
fprintf( ' ___________________________________________________________________\n' );
490
fprintf( '                  %s\n', title);
491
fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
492
fprintf( '      |     max error     |   mean error       |  max iterations  \n'   );
493
fprintf( ' atan | % .14f | % .14f  | %.5f \n', max( atan_err  ), mean( atan_err  ), max( atan_it   ) );
494
fprintf( ' abs  | % .14f | % .14f  | %.5f \n', max( abs_err   ), mean( abs_err   ), max( abs_it    ) );
495
fprintf( ' sin  | % .14f | % .14f  | %.5f \n', max( sin_err   ), mean( sin_err   ), max( sin_it    ) );
496
fprintf( ' cos  | % .14f | % .14f  | %.5f \n', max( cos_err   ), mean( cos_err   ), max( cos_it    ) );
497
fprintf( ' x    | % .14f | % .14f  | %.5f \n', max( x_err     ), mean( x_err     ), max( x_it      ) );
498
fprintf( ' y    | % .14f | % .14f  | %.5f \n', max( y_err     ), mean( y_err     ), max( y_it      ) );
499
fprintf( ' div  | % .14f | % .14f  | %.5f \n', max( div_err   ), mean( div_err   ), max( div_it    ) );
500
fprintf( ' mul  | % .14f | % .14f  | %.5f \n', max( mul_err   ), mean( mul_err   ), max( mul_it    ) );
501
fprintf( ' atanh| % .14f | % .14f  | %.5f \n', max( atanh_err ), mean( atanh_err ), max( atanh_it  ) );
502
fprintf( ' sqrt | % .14f | % .14f  | %.5f \n', max( sqrt_err  ), mean( sqrt_err  ), max( sqrt_it   ) );
503
fprintf( ' sinh | % .14f | % .14f  | %.5f \n', max( sinh_err  ), mean( sinh_err  ), max( sinh_it   ) );
504
fprintf( ' cosh | % .14f | % .14f  | %.5f \n', max( cosh_err  ), mean( cosh_err  ), max( cosh_it   ) );
505
 
506
 
507 3 feddischso
=======
508
[ ~, ~, sin_err,  cos_err, it_2 ]   = cpol2cart( data_a, data_b, tb_fid );
509
[ ~, div_err, it_3 ]                = cdiv( data_a_div, data_b_div, tb_fid );
510
[ ~, mul_err, it_4 ]                = cmul( data_a, data_b, tb_fid  );
511
[ ~, ~, atanh_err, sqrt_err, it_5 ] = catanh( data_a_h, data_b_h, tb_fid );
512
[ ~, ~, sinh_err, cosh_err, it_6 ]  = csinhcosh( data_a, tb_fid );
513 4 feddischso
=======
514
>>>>>>> Updated C and RTL model as well as the documentation
515 2 feddischso
 
516 3 feddischso
fprintf( ' ___________________________________________________________________\n' );
517 4 feddischso
fprintf( '                  %s\n', title);
518 3 feddischso
fprintf( ' -----+-------------------+--------------------+-------------------\n'   );
519
fprintf( '      |     max error     |   mean error       |  max iterations  \n'   );
520 4 feddischso
fprintf( ' atan | % .14f | % .14f  | %.5f \n', max( atan_err  ), mean( atan_err  ), max( atan_it   ) );
521
fprintf( ' abs  | % .14f | % .14f  | %.5f \n', max( abs_err   ), mean( abs_err   ), max( abs_it    ) );
522
fprintf( ' sin  | % .14f | % .14f  | %.5f \n', max( sin_err   ), mean( sin_err   ), max( sin_it    ) );
523
fprintf( ' cos  | % .14f | % .14f  | %.5f \n', max( cos_err   ), mean( cos_err   ), max( cos_it    ) );
524
fprintf( ' x    | % .14f | % .14f  | %.5f \n', max( x_err     ), mean( x_err     ), max( x_it      ) );
525
fprintf( ' y    | % .14f | % .14f  | %.5f \n', max( y_err     ), mean( y_err     ), max( y_it      ) );
526
fprintf( ' div  | % .14f | % .14f  | %.5f \n', max( div_err   ), mean( div_err   ), max( div_it    ) );
527
fprintf( ' mul  | % .14f | % .14f  | %.5f \n', max( mul_err   ), mean( mul_err   ), max( mul_it    ) );
528
fprintf( ' atanh| % .14f | % .14f  | %.5f \n', max( atanh_err ), mean( atanh_err ), max( atanh_it  ) );
529
fprintf( ' sqrt | % .14f | % .14f  | %.5f \n', max( sqrt_err  ), mean( sqrt_err  ), max( sqrt_it   ) );
530
fprintf( ' sinh | % .14f | % .14f  | %.5f \n', max( sinh_err  ), mean( sinh_err  ), max( sinh_it   ) );
531
fprintf( ' cosh | % .14f | % .14f  | %.5f \n', max( cosh_err  ), mean( cosh_err  ), max( cosh_it   ) );
532 2 feddischso
 
533 3 feddischso
end
534
>>>>>>> initial commit
535 2 feddischso
 
536 3 feddischso
 
537 7 feddischso
end
538 3 feddischso
 
539
 
540 4 feddischso
 
541 2 feddischso
function [sinh_res, cosh_res, sinh_err, cosh_err, it ]= csinhcosh( th, fid )
542
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
543
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
544
 
545
xi = repmat( (2^(XY_WIDTH-1)-1), size( th ) );
546
yi = zeros( 1, length( th ) );
547
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
548
 
549
 
550
 
551
mode = C_MODE_HYP;
552
 
553
 
554
% cordic version
555
[ rcosh rsinh ra, it ] = cordic_iterative( ...
556
                                           xi,          ...
557
                                           yi,          ...
558
                                           ai,          ...
559
                                           mode,        ...
560
                                           XY_WIDTH,    ...
561
                                           ANGLEWIDTH,  ...
562
                                           GUARDBITS,   ...
563
                                           RM_GAIN );
564 7 feddischso
 
565
 
566
 
567 2 feddischso
cosh_res = rcosh  ./ (   2^(XY_WIDTH-1)-1 );
568
sinh_res = rsinh  ./ (   2^(XY_WIDTH-1)-1 );
569
cosh_m = cosh( th );
570
sinh_m = sinh( th );
571
sinh_err = abs(sinh_res - sinh_m );
572
cosh_err = abs(cosh_res - cosh_m );
573
 
574 7 feddischso
 
575 2 feddischso
% write TB data
576
write_tb( fid, xi, yi, ai, rcosh, rsinh, ra, mode );
577
 
578
 
579
end
580
 
581
 
582
 
583
 
584
 
585
function [atan_res, abs_res, atan_err, abs_err, it ]  = catanh( x, y, fid )
586
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
587
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
588
 
589
if( size( x ) ~= size( y ) )
590
    error( 'size error' )
591
end
592
ai = zeros( size( x ) );
593
xi = round( x * (2^(XY_WIDTH-1)-1) );
594
yi = round( y * (2^(XY_WIDTH-1)-1) );
595
 
596
 
597
mode = C_FLAG_VEC_ROT + C_MODE_HYP;
598
 
599
 
600
% cordic version
601
[ rx, ry, ra, it ] = cordic_iterative( xi,          ...
602
                                  yi,          ...
603
                                  ai,          ...
604
                                  mode,        ...
605
                                  XY_WIDTH,    ...
606
                                  ANGLEWIDTH,  ...
607
                                  GUARDBITS,   ...
608
                                  RM_GAIN );
609
% matlab version
610
m_th = atanh( y ./ x );
611
m_r  = sqrt( x.^2 - y.^2 );
612
 
613
% comparison
614
atan_res = ra ./ 2^( (ANGLEWIDTH)-1);
615
abs_res  = rx ./ ( 2^(XY_WIDTH-1) -1 );
616
atan_err = abs( m_th - atan_res );
617
abs_err  = abs( m_r  -  abs_res );
618 7 feddischso
 
619 2 feddischso
% write TB data
620
write_tb( fid, xi, yi, ai, rx, ry, ra, mode );
621
 
622
 
623
end
624
 
625
 
626
 
627
 
628
 
629
function [mul_res, mul_err, it ] = cmul( x, y, fid )
630
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
631
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
632
 
633
if( size( x ) ~= size( y ) )
634
    error( 'size error' )
635
end
636
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
637
ai = round( y * ( 2^(XY_WIDTH-1) -1 ) );
638
yi = zeros( size( x ) );
639
 
640
 
641
mode = C_MODE_LIN;
642
 
643
% cordic version
644
[ rx, rmul, ra, it ] = cordic_iterative( xi,          ...
645
                                        yi,          ...
646
                                        ai,          ...
647
                                        mode,        ...
648
                                        XY_WIDTH,    ...
649
                                        ANGLEWIDTH,  ...
650
                                        GUARDBITS,   ...
651
                                        RM_GAIN );
652 7 feddischso
 
653
 
654 2 feddischso
mul_res  = rmul ./ (2^(ANGLEWIDTH-1)-1);
655
mul_err  = abs( y.*x -  mul_res );
656
 
657
% write TB data
658
write_tb( fid, xi, yi, ai, rx, rmul, ra, mode )
659
 
660
 
661
end
662
 
663
 
664
 
665
 
666
 
667
function [div_res, div_err, it ] = cdiv( x, y, fid )
668
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
669
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
670
 
671
if( size( x ) ~= size( y ) )
672
    error( 'size error' )
673
end
674
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
675
yi = round( y * ( 2^(XY_WIDTH-1) -1 ) );
676
ai = zeros( size( x ) );
677
 
678
 
679
mode = C_FLAG_VEC_ROT + C_MODE_LIN;
680
 
681
% cordic version
682
[ rx, ry, rdiv, it ] = cordic_iterative( xi,          ...
683
                                  yi,          ...
684
                                  ai,          ...
685
                                  mode,        ...
686
                                  XY_WIDTH,    ...
687
                                  ANGLEWIDTH,  ...
688
                                  GUARDBITS,   ...
689
                                  RM_GAIN );
690 7 feddischso
 
691
 
692 2 feddischso
div_res  = rdiv ./ (2^(ANGLEWIDTH-1)-1);
693
div_err  = abs( y./x -  div_res );
694
 
695
% write TB data
696
write_tb( fid, xi, yi, ai, rx, ry, rdiv, mode )
697
 
698
end
699
 
700
 
701 3 feddischso
<<<<<<< HEAD
702 4 feddischso
<<<<<<< HEAD
703
=======
704
>>>>>>> Updated C and RTL model as well as the documentation
705 2 feddischso
function [x_res, y_res, x_err, y_err, it ] = crot( x, y, th, fid )
706
%
707
% does a multiplication with exp( th * i )
708
% and therefore, a rotation of the complex input value x + yi where th
709
% defines the rotation angle
710
%
711
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
712
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
713
 
714
xi = round( x * ( 2^(XY_WIDTH-1) -1 ) );
715
yi = round( y * ( 2^(XY_WIDTH-1) -1 ) );
716
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
717
 
718
mode = C_MODE_CIRC;
719
 
720
[ rx ry ra, it ] = cordic_iterative( ...
721
                                  xi,          ...
722
                                  yi,          ...
723
                                  ai,          ...
724
                                  mode,        ...
725
                                  XY_WIDTH,    ...
726
                                  ANGLEWIDTH,  ...
727
                                  GUARDBITS,   ...
728
                                  RM_GAIN );
729 7 feddischso
 
730 2 feddischso
tmp = ( x + 1i * y ) .* exp( i * th );
731 7 feddischso
 
732 2 feddischso
x_res = rx  ./ (   2^(XY_WIDTH-1)-1 );
733
y_res = ry  ./ (   2^(XY_WIDTH-1)-1 );
734
 
735
y_err = abs(x_res - real(tmp) );
736
x_err = abs(y_res - imag(tmp) );
737
 
738
% write TB data
739
write_tb( fid, xi, yi, ai, rx, ry, ra, mode )
740
 
741
 
742
end
743
 
744
 
745
function [sin_res, cos_res, sin_err, cos_err, it ]= cpol2cart( th, r, fid )
746
%
747
% does the Matlab equivalent pol2cart
748
%
749
 
750 4 feddischso
<<<<<<< HEAD
751 3 feddischso
=======
752
 
753
 
754
 
755
function [sin_res, cos_res, sin_err, cos_err, it ]= cpol2cart( th, r, fid )
756
>>>>>>> initial commit
757 4 feddischso
=======
758
>>>>>>> Updated C and RTL model as well as the documentation
759 2 feddischso
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
760
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
761
 
762
xi = r .* (2^(XY_WIDTH-1)-1);
763
yi = zeros( 1, length( th ) );
764
ai = round( th .* (2^(ANGLEWIDTH-1)-1) );
765
 
766 3 feddischso
<<<<<<< HEAD
767 4 feddischso
<<<<<<< HEAD
768 2 feddischso
mode = C_MODE_CIRC;
769
 
770 3 feddischso
=======
771
 
772
 
773
mode = C_MODE_CIRC;
774
 
775
 
776
% cordic version
777
>>>>>>> initial commit
778 4 feddischso
=======
779
mode = C_MODE_CIRC;
780
 
781
>>>>>>> Updated C and RTL model as well as the documentation
782 2 feddischso
[ rcos rsin ra, it ] = cordic_iterative( ...
783
                                  xi,          ...
784
                                  yi,          ...
785
                                  ai,          ...
786
                                  mode,        ...
787
                                  XY_WIDTH,    ...
788
                                  ANGLEWIDTH,  ...
789
                                  GUARDBITS,   ...
790
                                  RM_GAIN );
791 7 feddischso
 
792
 
793
 
794 2 feddischso
cos_res = rcos  ./ (   2^(XY_WIDTH-1)-1 );
795
sin_res = rsin  ./ (   2^(XY_WIDTH-1)-1 );
796
[ cos_m, sin_m ] = pol2cart( th, r );
797
sin_err = abs(sin_res - sin_m );
798
cos_err = abs(cos_res - cos_m );
799
 
800
% write TB data
801
write_tb( fid, xi, yi, ai, rcos, rsin, ra, mode )
802
 
803
 
804
end
805
 
806
 
807
 
808
 
809 3 feddischso
<<<<<<< HEAD
810 4 feddischso
<<<<<<< HEAD
811 2 feddischso
 
812 3 feddischso
=======
813
>>>>>>> initial commit
814 4 feddischso
=======
815
 
816
>>>>>>> Updated C and RTL model as well as the documentation
817 2 feddischso
function [atan_res, abs_res, atan_err, abs_err, it ]  = ccart2pol( x, y, fid )
818
 
819
global C_FLAG_VEC_ROT C_FLAG_ATAN_3 C_MODE_CIRC C_MODE_LIN C_MODE_HYP
820
global XY_WIDTH ANGLEWIDTH GUARDBITS RM_GAIN
821
 
822
if( size( x ) ~= size( y ) )
823
    error( 'size error' )
824
end
825
ai = zeros( size( x ) );
826
xi = round( x * (2^(XY_WIDTH-1)-1) );
827
yi = round( y * (2^(XY_WIDTH-1)-1) );
828
 
829
mode = C_FLAG_VEC_ROT + C_MODE_CIRC;
830
 
831
 
832
% cordic version
833
[ rx, ry, ra, it ] = cordic_iterative( xi,          ...
834
                                  yi,          ...
835
                                  ai,          ...
836
                                  mode,        ...
837
                                  XY_WIDTH,    ...
838
                                  ANGLEWIDTH,  ...
839
                                  GUARDBITS,   ...
840
                                  RM_GAIN );
841 3 feddischso
<<<<<<< HEAD
842 4 feddischso
<<<<<<< HEAD
843
=======
844
>>>>>>> Updated C and RTL model as well as the documentation
845 2 feddischso
% matlab version:
846
m_th = atan2( y,  x );
847
m_r  = sqrt( x.^2 + y.^2 );
848
 
849 4 feddischso
<<<<<<< HEAD
850 3 feddischso
=======
851
% matlab version
852
[m_th, m_r ] = cart2pol( x, y );
853
>>>>>>> initial commit
854 4 feddischso
=======
855
>>>>>>> Updated C and RTL model as well as the documentation
856 2 feddischso
 
857
% comparison
858
atan_res = ra ./ 2^( (ANGLEWIDTH)-1);
859
abs_res  = rx ./ ( 2^(XY_WIDTH-1) -1 );
860
atan_err = abs( m_th - atan_res );
861
abs_err  = abs( m_r  -  abs_res );
862
 
863 3 feddischso
<<<<<<< HEAD
864 4 feddischso
<<<<<<< HEAD
865 2 feddischso
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
866
 
867 3 feddischso
=======
868
>>>>>>> initial commit
869 4 feddischso
=======
870
% TODO: ATAN oder ATAN2  atan( 0 / x ) != atan2( 0, x )!!!!
871
 
872
>>>>>>> Updated C and RTL model as well as the documentation
873 2 feddischso
% write TB data
874
write_tb( fid, xi, yi, ai, rx, ry, ra, mode )
875
 
876
end
877
 
878
 
879
 
880
 
881
 

powered by: WebSVN 2.1.0

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