CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
Cordic Class Reference

#include <Cordic.h>

Public Member Functions

 Cordic (const uint32_t &aPhiScale, const uint32_t &aMagnitudeBits, const uint32_t &aSteps)
 
int32_t IntegerizeMagnitude (const double &aMagnitude) const
 
double NormalizeMagnitude (const uint32_t &aMagnitude) const
 
double NormalizePhi (const uint32_t &aPhi) const
 
void operator() (int32_t aX, int32_t aY, int32_t &aPhi, uint32_t &aMagnitude) const
 
virtual ~Cordic ()
 

Private Member Functions

uint32_t tower (const double &aRadians) const
 

Private Attributes

uint32_t mMagnitudeBits
 
uint64_t mMagnitudeRenormalization
 
uint32_t mMagnitudeScale
 
uint32_t mPhiScale
 
const double mPi
 
std::vector< uint32_t > mRotations
 
uint32_t mSteps
 

Detailed Description

Definition at line 7 of file Cordic.h.

Constructor & Destructor Documentation

Cordic::Cordic ( const uint32_t &  aPhiScale,
const uint32_t &  aMagnitudeBits,
const uint32_t &  aSteps 
)

Definition at line 9 of file Cordic.cc.

References mMagnitudeRenormalization, mMagnitudeScale, mRotations, mSteps, funct::pow(), mathSSE::sqrt(), and tower().

10  : mPhiScale(aPhiScale),
11  mMagnitudeScale(1 << aMagnitudeBits),
12  mMagnitudeBits(aMagnitudeBits),
13  mSteps(aSteps),
14  mPi(3.1415926535897932384626433832795) {
15  mRotations.reserve(mSteps);
16 
17  double lValue(1.0);
18 
19  for (uint32_t lStep(0); lStep != mSteps; ++lStep) {
20  lValue /= sqrt(1.0 + pow(4.0, -double(lStep)));
21  mRotations.push_back(tower(atan(pow(2.0, -double(lStep)))));
22  }
23  mMagnitudeRenormalization = uint32_t(round(mMagnitudeScale * lValue));
24 }
uint32_t tower(const double &aRadians) const
Definition: Cordic.cc:36
uint32_t mMagnitudeBits
Definition: Cordic.h:24
uint32_t mPhiScale
Definition: Cordic.h:22
T sqrt(T t)
Definition: SSEVec.h:19
const double mPi
Definition: Cordic.h:29
uint32_t mSteps
Definition: Cordic.h:25
uint64_t mMagnitudeRenormalization
Definition: Cordic.h:26
uint32_t mMagnitudeScale
Definition: Cordic.h:23
std::vector< uint32_t > mRotations
Definition: Cordic.h:27
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
Cordic::~Cordic ( )
virtual

Definition at line 26 of file Cordic.cc.

26 {}

Member Function Documentation

int32_t Cordic::IntegerizeMagnitude ( const double &  aMagnitude) const

Definition at line 34 of file Cordic.cc.

References mMagnitudeScale.

34 { return int32_t(aMagnitude * mMagnitudeScale); }
uint32_t mMagnitudeScale
Definition: Cordic.h:23
double Cordic::NormalizeMagnitude ( const uint32_t &  aMagnitude) const

Definition at line 30 of file Cordic.cc.

References mMagnitudeScale.

30  {
31  return double(aMagnitude) / double(mMagnitudeScale);
32 }
uint32_t mMagnitudeScale
Definition: Cordic.h:23
double Cordic::NormalizePhi ( const uint32_t &  aPhi) const

Definition at line 28 of file Cordic.cc.

References mPhiScale.

28 { return double(aPhi) / double(mPhiScale); }
uint32_t mPhiScale
Definition: Cordic.h:22
void Cordic::operator() ( int32_t  aX,
int32_t  aY,
int32_t &  aPhi,
uint32_t &  aMagnitude 
) const

Definition at line 38 of file Cordic.cc.

References mMagnitudeBits, mMagnitudeRenormalization, mPi, mRotations, mSteps, and tower().

38  {
39  bool lSign(true);
40 
41  switch (((aY >= 0) ? 0x0 : 0x2) | ((aX >= 0) ? 0x0 : 0x1)) {
42  case 0:
43  aPhi = tower(mPi);
44  break;
45  case 1:
46  aPhi = tower(2 * mPi);
47  lSign = false;
48  aX = -aX;
49  break;
50  case 2:
51  aPhi = tower(mPi);
52  lSign = false;
53  aY = -aY;
54  break;
55  case 3:
56  aPhi = 0;
57  aX = -aX;
58  aY = -aY;
59  break;
60  default:
61  throw 0;
62  }
63 
64  for (uint32_t lStep(0); lStep != mSteps; ++lStep) {
65  if ((aY < 0) == lSign) {
66  aPhi -= mRotations[lStep];
67  } else {
68  aPhi += mRotations[lStep];
69  }
70 
71  int32_t lX(aX), lY(aY);
72  if (lY < 0) {
73  aX = lX - (lY >> lStep);
74  aY = lY + (lX >> lStep);
75  } else {
76  aX = lX + (lY >> lStep);
77  aY = lY - (lX >> lStep);
78  }
79  }
80 
81  aMagnitude = (aX * mMagnitudeRenormalization) >> mMagnitudeBits;
82 }
uint32_t tower(const double &aRadians) const
Definition: Cordic.cc:36
uint32_t mMagnitudeBits
Definition: Cordic.h:24
const double mPi
Definition: Cordic.h:29
uint32_t mSteps
Definition: Cordic.h:25
uint64_t mMagnitudeRenormalization
Definition: Cordic.h:26
std::vector< uint32_t > mRotations
Definition: Cordic.h:27
uint32_t Cordic::tower ( const double &  aRadians) const
private

Definition at line 36 of file Cordic.cc.

References mPhiScale, and mPi.

Referenced by Cordic(), and operator()().

36 { return uint32_t(round(mPhiScale * 0.5 * aRadians / mPi)); }
uint32_t mPhiScale
Definition: Cordic.h:22
const double mPi
Definition: Cordic.h:29

Member Data Documentation

uint32_t Cordic::mMagnitudeBits
private

Definition at line 24 of file Cordic.h.

Referenced by operator()().

uint64_t Cordic::mMagnitudeRenormalization
private

Definition at line 26 of file Cordic.h.

Referenced by Cordic(), and operator()().

uint32_t Cordic::mMagnitudeScale
private

Definition at line 23 of file Cordic.h.

Referenced by Cordic(), IntegerizeMagnitude(), and NormalizeMagnitude().

uint32_t Cordic::mPhiScale
private

Definition at line 22 of file Cordic.h.

Referenced by NormalizePhi(), and tower().

const double Cordic::mPi
private

Definition at line 29 of file Cordic.h.

Referenced by operator()(), and tower().

std::vector<uint32_t> Cordic::mRotations
private

Definition at line 27 of file Cordic.h.

Referenced by Cordic(), and operator()().

uint32_t Cordic::mSteps
private

Definition at line 25 of file Cordic.h.

Referenced by Cordic(), and operator()().