メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

cordiccos

余弦の CORDIC ベース近似

説明

y = cordiccos(theta) は、CORDIC アルゴリズムの近似を使用して theta の余弦を計算します。

y = cordiccos(theta,niters) は、CORDIC アルゴリズムの反復回数 niters を指定します。

すべて折りたたむ

cordiccos アルゴリズムのさまざまな反復の計算結果を、倍精度関数 cos の結果と比較します。

[0,2*pi) の範囲で 1024 個の点を作成します。

stepSize = pi/512;
thRadDbl = 0:stepSize:(2*pi - stepSize);

固定小数点型を符号付きの 12 ビット固定小数点データ型に設定します。倍精度入力をもつ cos 関数を対照として使用します。

thRadFxp = fi(thRadDbl,1,12);
cosThRef = cos(double(thRadFxp));

12 ビットの量子化入力を使用し、反復回数を 2 から 10 までの間で変化させます。固定小数点の CORDIC の結果を倍精度の三角関数の結果と比較します。

for niters = 2:2:10
    cdcCosTh  = cordiccos(thRadFxp,niters);
    errCdcRef = cosThRef - double(cdcCosTh);    
end

結果をプロットします。

figure
hold on
axis([0 2*pi -1.25 1.25]);
    plot(thRadFxp,cosThRef,'b');
    plot(thRadFxp,cdcCosTh,'g');
    plot(thRadFxp,errCdcRef,'r');
    ylabel('cos(\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: cos(double(\Theta))';
    cdc_str = sprintf('12-bit CORDIC cosine; N = %d',niters);
    err_str = sprintf('Error (max = %f)', max(abs(errCdcRef)));
    legend(ref_str,cdc_str,err_str);

Figure contains an axes object. The axes object with ylabel cos( Theta ) contains 3 objects of type line. These objects represent Reference: cos(double(\Theta)), 12-bit CORDIC cosine; N = 10, Error (max = 0.005047).

10 回の反復の後、CORDIC アルゴリズムは、theta の余弦を、倍精度余弦の結果である 0.005187 以内に近似しました。

入力引数

すべて折りたたむ

入力角度 (ラジアン単位)。符号付きまたは符号なしのスカラー、ベクトル、行列、または多次元配列として指定します。theta のすべての値は実数で、範囲 [–2π 2π) になければなりません。

CORDIC アルゴリズムを実行する反復回数。正の整数値スカラーとして指定します。niters を指定しない場合や指定した値が大きすぎた場合は、アルゴリズムでは最大値が使用されます。固定小数点の演算では、反復の最大回数は theta の語長よりも 1 回少なくなります。浮動小数点の演算では、最大値は double で 52、single で 23 です。反復数を増やすと、結果の精度が高まりますが、計算量も増加しレイテンシも増えます。

出力引数

すべて折りたたむ

theta の余弦の CORDIC ベース近似。スカラー、ベクトル、行列、または多次元配列として返されます。

関数への入力が浮動小数点である場合、出力のデータ型は入力のデータ型と同じです。入力が固定小数点である場合、出力の語長は入力の語長と等しく、小数部の長さは WordLength2 と等しくなります。

アルゴリズム

すべて折りたたむ

参照

[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.

拡張機能

すべて展開する

バージョン履歴

R2010a で導入