cordicsin
CORDIC-based approximation of sine
Description
Examples
Compare Results of cordicsin
and sin
Functions
This example compares the results produced by the cordicsin
algorithm to the results of the double-precision sin
function.
Create 1024 points between [0, 2*pi)
.
stepSize = pi/512; thRadDbl = 0:stepSize:(2*pi - stepSize); thRadFxp = sfi(thRadDbl,12); % signed, 12-bit fixed point sinThRef = sin(double(thRadFxp)); % reference results
Set the number of iterations to 10.
niters = 10; cdcSinTh = cordicsin(thRadFxp,niters); errCdcRef = sinThRef - double(cdcSinTh);
Compare the fixed-point cordicsin
function results to the results of the double-precision sin
function.
figure hold on axis([0 2*pi -1.25 1.25]) plot(thRadFxp,sinThRef,'b'); plot(thRadFxp,cdcSinTh,'g'); plot(thRadFxp,errCdcRef,'r'); ylabel('sin(\Theta)'); gca.XTick = 0:pi/2:2*pi; gca.XTickLabel = {'0','pi/2','pi','3*pi/2','2*pi'}; gca.YTick = -1:0.5:1; gca.YTickLabel = {'-1.0','-0.5','0','0.5','1.0'}; ref_str = 'Reference: sin(double(\Theta))'; cdc_str = sprintf('12-bit CORDIC sine; N = %d',niters); err_str = sprintf('Error (max = %f)', max(abs(errCdcRef))); legend(ref_str,cdc_str,err_str);
After 10 iterations, the CORDIC algorithm has approximated the sine of theta to within 0.005492 of the double-precision sine result.
Input Arguments
theta
— Input angle in radians
scalar | vector | matrix | multidimensional array
Input angle in radians, specified as a signed or unsigned scalar, vector, matrix, or
multidimensional array. All values of theta
must be real and in the
range [–2π 2π).
niters
— Number of iterations
positive integer-valued scalar
Number of iterations the CORDIC algorithm performs, specified as a positive, integer-valued scalar.
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 one less than the word length of theta
. For
floating-point operation, the maximum value is 52 for double or 23 for single.
Increasing the number of iterations can produce more accurate results, but it also
increases the expense of the computation and adds latency.
Output Arguments
y
— CORDIC-based approximation of sine
scalar | vector | matrix | multidimensional array
CORDIC-based approximation of sine of theta
, returned as a
scalar, vector, matrix, or multidimensional array.
When the input to the function is floating point, the output data type is the same
as the input data type. When the input is fixed point, the output has the same word
length as the input, and a fraction length equal to the WordLength
–
2
.
Algorithms
CORDIC
CORDIC is an acronym for COordinate Rotation DIgital Computer. The Givens rotation-based CORDIC algorithm is one of the most hardware-efficient algorithms available because it requires only iterative shift-add operations (see References). The CORDIC algorithm eliminates the need for explicit multipliers. Using CORDIC, you can calculate various functions such as sine, cosine, arc sine, arc cosine, arc tangent, and vector magnitude. You can also use this algorithm for divide, square root, hyperbolic, and logarithmic functions.
Increasing the number of CORDIC iterations can produce more accurate results, but doing so increases the expense of the computation and adds latency.
Signal Flow Diagrams
X represents the sine, Y represents the cosine, and Z represents theta. The accuracy of the CORDIC rotation kernel depends on the choice of initial values for X, Y, and Z. This algorithm uses the following initial values:
fimath Propagation Rules
CORDIC functions discard any local fimath
attached to the
input.
The CORDIC functions use their own internal fimath
when performing calculations:
OverflowAction
—Wrap
RoundingMethod
—Floor
The output has no attached fimath
.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Variable-size signals are not supported.
The number of iterations the CORDIC algorithm performs,
niters
, must be a constant.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
You can generate HDL code for cordicsin
function.
Version History
Introduced in R2010a
See Also
cordiccexp
| cordiccos
| cordicsincos
| sin
| cos
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)