Main Content

cordicrotate

CORDIC-based approximation of rotation of input

Description

v = cordicrotate(theta,u) rotates the input u by theta using a CORDIC algorithm approximation. The function returns the result of u .* e^(j*theta).

v = cordicrotate(theta,u,niters) performs niters iterations of the algorithm.

example

v = cordicrotate(___,ScaleOutput) specifies whether to scale the output.

Examples

collapse all

Run this code to evaluate the accuracy of CORDIC-based complex rotation.

wrdLn = 16;
theta = fi(-pi/3, 1, wrdLn);
u     = fi(0.25 - 7.1i, 1, wrdLn);
uTeTh = double(u) .* exp(1i * double(theta));

fprintf('\n\nNITERS\tReal\t ERROR\t LSBs\t\tImag\tERROR\tLSBs\n');
fprintf('------\t-------\t ------\t ----\t\t-------\t------\t----\n');
for niters = 1:(wrdLn - 1)
 v_fi   = cordicrotate(theta, u, niters);
 v_dbl  = double(v_fi);
 x_err  = abs(real(v_dbl) - real(uTeTh));
  y_err  = abs(imag(v_dbl) - imag(uTeTh));
 fprintf('%d\t%1.4f\t %1.4f\t %1.1f\t\t%1.4f\t %1.4f\t %1.1f\n',...
   niters, real(v_dbl),x_err,(x_err * pow2(v_fi.FractionLength)), ...
   imag(v_dbl),y_err, (y_err * pow2(v_fi.FractionLength)));
end
fprintf('\n');
NITERS  Real      ERROR	 LSBs	Imag	    ERROR	LSBs
------  -------   ------	 ----      -------	------	----
1       -4.8438   1.1800	 4833.5    -5.1973	 1.4306	 5859.8
2       -6.6567   0.6329	 2592.5    -2.4824	 1.2842	 5260.2
3       -5.8560   0.1678	 687.5     -4.0229	 0.2563	 1049.8
4       -6.3096   0.2858	 1170.5    -3.2654	 0.5013	 2053.2
5       -6.0935   0.0697	 285.5     -3.6526	 0.1141	 467.2
6       -5.9766   0.0472	 193.5     -3.8413	 0.0746	 305.8
7       -6.0356   0.0118	 48.5      -3.7473	 0.0193	 79.2
8       -6.0063   0.0175	 71.5      -3.7947	 0.0280	 114.8
9       -6.0212   0.0026	 10.5      -3.7710	 0.0043	 17.8
10      -6.0283   0.0045	 18.5      -3.7590	 0.0076	 31.2
11      -6.0247   0.0009	 3.5       -3.7649	 0.0018	 7.2
12      -6.0227   0.0011	 4.5       -3.7678	 0.0012	 4.8
13      -6.0237   0.0001	 0.5       -3.7664	 0.0003	 1.2
14      -6.0244   0.0006	 2.5       -3.7656	 0.0010	 4.2
15      -6.0239   0.0001	 0.5       -3.7661	 0.0005	 2.2

Input Arguments

collapse all

Angle values in radians, specified as a signed or unsigned scalar, vector, matrix, or multidimensional array. All values of theta must be in the range [–2π 2π).

Input array, specified as a signed or unsigned scalar, vector, matrix, or multidimensional array. u can be a scalar value or have the same dimensions as theta. u can be real or complex valued.

Number of iterations the CORDIC algorithm performs, specified as a positive integer-valued scalar. This argument is optional. If you do not specify niters, or if you specify a value that is too large, the algorithm uses a maximum value:

  • For fixed-point operation, the maximum number of iterations is the word length of u or one less than the word length of theta, whichever is smaller.

  • For floating-point operation, the maximum value is 52 for double or 23 for single.

Whether to scale the output by the inverse CORDIC gain factor, specified as a Boolean value. This argument is optional. If you set ScaleOutput to true or 1, the output values are multiplied by a constant, which incurs extra computations. If you set ScaleOutput to false or 0, the output is not scaled.

Output Arguments

collapse all

The data type of the output v depends on the data type of the input u:

  • When the input u is floating point, the output v has the same data type as the input.

  • When the input u is a signed integer or fixed point data type, the output v is a signed fi object. This fi object has a word length that is two bits larger than that of u. Its fraction length is the same as the fraction length of u.

  • When the input u is an unsigned integer or fixed point, the output v is a signed fi object. This fi object has a word length that is three bits larger than that of u. Its fraction length is the same as the fraction length of u.

Algorithms

collapse all

References

[1] Volder, Jack E. “The CORDIC Trigonometric Computing Technique.” IRE Transactions on Electronic Computers. EC-8, no. 3 (Sept. 1959): 330–334.

[2] Andraka, Ray. “A Survey of CORDIC Algorithm for FPGA Based Computers.” In Proceedings of the 1998 ACM/SIGDA Sixth International Symposium on Field Programmable Gate Arrays, 191–200. https://dl.acm.org/doi/10.1145/275107.275139.

[3] Walther, J.S. “A Unified Algorithm for Elementary Functions.” In Proceedings of the May 18-20, 1971 Spring Joint Computer Conference, 379–386. https://dl.acm.org/doi/10.1145/1478786.1478840.

[4] Schelin, Charles W. “Calculator Function Approximation.” The American Mathematical Monthly, no. 5 (May 1983): 317–325. https://doi.org/10.2307/2975781.

Extended Capabilities

expand all

Version History

Introduced in R2011a