i`m doing my thesis comparing CORDIC with polynomial in counting arctan with fixed point. I`m using Q15 format now. I`m using this site CORDIC arctan as a referenced when making with floating point. The problem there`s a lot of error when i try to make it with fixed point.
this is my program -
#include "Unit1.h"
-
#include "math.h"
-
#include "fixed_math.hpp"
-
#define MAXBITS 15
-
static float invGain1;
-
static float atanTable[MAXBITS];
-
static float gain1Cordic();
-
-
-
void initCordic()
-
{
-
/* must call this first to initialise the constants.
-
* of course, here i use the maths library, but the
-
* values would be precomputed.
-
*/
-
float t = 1.0f;
-
int i;
-
for (i = 0; i < MAXBITS; ++i)
-
{
-
atanTable[i] = atan(t);
-
t /= 2;
-
}
-
-
/* set constants */
-
invGain1 = 1/gain1Cordic();
-
}
-
-
/* CORDIC m=1, y-->0 */
-
-
Q15 cordic(Q15 &x0, Q15 &y0, Q15 &z0, Q15 vecmode)
-
{
-
-
short t;
-
Q15 x, y, z;
-
int i;
-
-
t = 1.0f;
-
x = x0; y = y0; z = z0;
-
-
for (i = 0; i < MAXBITS; ++i)
-
{
-
-
double x1;
-
-
if (vecmode >= 0.0f && y < vecmode || vecmode<0.0f && z >= 0.0f)
-
{
-
Q15 x1 = x - y>>t;
-
y = y + x>>t;
-
z = z - atanTable[i];
-
}
-
else
-
{
-
Q15 x1 = x + y>>t;
-
y = y - x>>t;
-
z = z + atanTable[i];
-
}
-
-
x = x1;
-
t /= 2;
-
}
-
-
x0 = x;
-
y0 = y;
-
z0 = z;
-
-
}
-
-
-
static float gain1Cordic()
-
{
-
/* compute gain by evaluating cos(0) without inv gain */
-
float x, y, z;
-
-
x = 1;
-
y = 0;
-
z = 0;
-
cordic(&x, &y, &z, 1.0f);
-
return x;
-
}
-
-
Q15 atanCordic(Q15 a)
-
{
-
/* domain: all a */
-
Q15 x = 1.0f;
-
Q15 z = 0.0f;
-
cordic(&x, &a, &z, 0.0f);
-
return z;
-
}
-
-
void __fastcall TForm1::Button1Click(TObject *Sender)
-
{
-
AnsiString buf;
-
float x;
-
float v,c;
-
-
-
initCordic();
-
-
for (x=0.0;x<=1.0;x=x+0.1)
-
{
-
-
Q15 y = atanCordic(x);
-
v = atan(x);
-
-
-
Memo1->Lines->Add(buf.sprintf("%5.2f\n", x));
-
Memo2->Lines->Add(buf.sprintf("%10.6f\n",Q15ToShort(v)/32768.0));
-
Memo3->Lines->Add(buf.sprintf("%10.6f\n",Q15ToShort(y)/32768.0));
-
-
}
-
-
-
}
-
-
anyone can help?
if you have suggestion about making it with others rather than Q15 format, as long it is fixed point, it is very usefull to
12 9554
astri-
I'm not sure if I can help with the logic of your program (that's a little over my head!), but it's more than likely that I or someone else browsing through would be able to help you with the error messages that you are getting, if you could post those.
sicarie
Can you give us an example of your input and output. What kind of error are you getting?
i`m bolding the font ONLY for error messages(ignore the warning) in my program -
-
#include "Unit1.h"
-
#include "math.h"
-
#include "fixed_math.hpp"
-
#define MAXBITS 15
-
-
static float invGain1;
-
static float atanTable[MAXBITS];
-
static float gain1Cordic();
-
-
-
void initCordic()
-
{
-
/* must call this first to initialise the constants.
-
* of course, here i use the maths library, but the
-
* values would be precomputed.
-
*/
-
float t = 1.0f;
-
int i;
-
for (i = 0; i < MAXBITS; ++i)
-
{
-
atanTable[i] = atan(t);
-
t /= 2;
-
}
-
-
/* set constants */
-
invGain1 = 1/gain1Cordic();
-
}
-
-
/* CORDIC m=1, y-->0 */
-
-
Q15 cordic(Q15 &x0, Q15 &y0, Q15 &z0, Q15 vecmode)
-
{
-
-
short t;
-
Q15 x, y, z;
-
int i;
-
-
t = 1.0f;
-
x = x0; y = y0; z = z0;
-
-
for (i = 0; i < MAXBITS; ++i)
-
{
-
-
double x1;
-
-
if (vecmode >= 0.0f && y < vecmode || vecmode<0.0f && z >= 0.0f)
-
{
-
Q15 x1 = x - y>>t;
-
y = y + x>>t;
-
z = z - atanTable[i];
-
}
-
else
-
{
-
Q15 x1 = x + y>>t;
-
y = y - x>>t;
-
z = z + atanTable[i];
-
}
-
-
x = x1;
-
t /= 2;
-
}
-
-
x0 = x;
-
y0 = y;
-
z0 = z;
-
-
}
-
-
-
static float gain1Cordic()
-
{
-
/* compute gain by evaluating cos(0) without inv gain */
-
float x, y, z;
-
-
x = 1;
-
y = 0;
-
z = 0;
-
cordic(&x, &y, &z, 1.0f);-->THE MAIN PROBLEM,
-
return x; the error messages repeated so much in this line
-
}
-
-
Q15 atanCordic(Q15 a)
-
{
-
/* domain: all a */
-
Q15 x = 1.0f;
-
Q15 z = 0.0f;
-
cordic(&x, &a, &z, 0.0f);
-
return z;
-
}
-
-
void __fastcall TForm1::Button1Click(TObject *Sender)
-
{
-
AnsiString buf;
-
float x;
-
float v,c;
-
-
-
initCordic();
-
-
for (x=0.0;x<=1.0;x=x+0.1)
-
{
-
-
Q15 y = atanCordic(x);
-
v = atan(x);
-
-
Memo1->Lines->Add(buf.sprintf("%5.2f\n", x));
-
Memo2->Lines->Add(buf.sprintf("%10.6f\n",y));
-
Memo3->Lines->Add(buf.sprintf("%10.6f\n",v));
-
-
-
}
-
-
-
}
-
-
this is my error messages
[code]
[C++ errorー] Unit1.cpp(67): E2015 'Q15:: operator -(const Q15 &) const' and 'Q15:: operator -(const Q30 &) const' classification are ambiguous retrieval
[C++ errorー] Unit1.cpp(73): E2015 'Q15:: operator +(const Q15 &) const' and 'Q15:: operator +(const Q30 &) const' classification are ambigous retrieval
[C++ error ー] Unit1.cpp(76): E2015 'Q15::Q15(const short)' and 'Q15::Q15(const float)' classification are ambigous retrieval
[C++ warning] Unit1.cpp(84): W8070 return function value
[C++ warning] Unit1.cpp(95): W8030 'x0' parameter(cordic(Q15 &,Q15 &,Q15 &,Q15))is used as temporarily variables
[C++ error] Unit1.cpp(95): E2064 'Q15 &' cant initialized as 'float *'
[C++ error] Unit1.cpp(95): E2342 'x0'parameter is define as Q15 & so it cant be change to float *
[C++ warning] Unit1.cpp(95): W8030 'y0' parameter(cordic(Q15 &,Q15 &,Q15 &,Q15))is used as temporarily variables
[C++ error] Unit1.cpp(95): E2064 'Q15 &' cant initialized as 'float *'
[C++ error] Unit1.cpp(95): E2342 'y0'b parameter is Q15 & type and cant be change to float *
[C++ warning] Unit1.cpp(95): W8030 'z0' parameters(cordic(Q15 &,Q15 &,Q15 &,Q15))is used as temporarily variables
[C++ error] Unit1.cpp(95): E2064 'Q15 &' cant initialized as 'float *'
[C++ error] Unit1.cpp(95): E2342 'z0' parameter is Q15 & type and cant be change to float *
[C++ warning] Unit1.cpp(97): W8004 'z' subtituted value is not use
[C++ warning] Unit1.cpp(97): W8004 'y' subtituted value is not use [C++ warning] Unit1.cpp(104): W8030 'x0' parameter(cordic(Q15 &,Q15 &,Q15 &,Q15))is used as temporarily variables
[C++ error] Unit1.cpp(104): E2064 'Q15 &' is 'Q15 *' cant be initialized
[C++ error] Unit1.cpp(104): E2342 'x0' parameters is Q15 & type and cant be change to Q15 *
[C++ warning] Unit1.cpp(104): W8030 'y0' parameters(cordic(Q15 &,Q15 &,Q15 &,Q15))is used as temporarily variables
[C++ error] Unit1.cpp(104): E2064 'Q15 &' is 'Q15 *' cant be initialized
[C++ error] Unit1.cpp(104): E2342 'y0' parameters is Q15 & type and cant be change to Q15 *
[C++ warning] Unit1.cpp(104): W8030 'z0' パラメータ(cordic(Q15 &,Q15 &,Q15 &,Q15))is used as temporarily variables
[C++ warning] Unit1.cpp(104): E2064 'Q15 &' は 'Q15 *' cant be initialized
[C++ error] Unit1.cpp(104): E2342 'z0' parameters is Q15 & type and cant be change to Q15 *
i`m thinking the main problem in my program is because i`m trying to use fixed point (its about the data type). I dont really understand that much.
*ps i`m using c++builder for japanese so the error message output is in japanese , i`m translating by myself to english (so if it`s sound weird please correct it or ask me)
the function definition of cordic() sepcifies that the formal parameters and return type are Q15 -
Q15 cordic(Q15 &x0, Q15 &y0, Q15 &z0, Q15 vecmode)
-
you call it with actual parameters of type float -
static float gain1Cordic()
-
{
-
/* compute gain by evaluating cos(0) without inv gain */
-
float x, y, z;
-
-
x = 1;
-
y = 0;
-
z = 0;
-
cordic(&x, &y, &z, 1.0f);-->THE MAIN PROBLEM,
-
return x; the error messages repeated so much in this line
-
}
-
where did you get the Q15 fixed point library from?
the function definition of cordic() sepcifies that the formal parameters and return type are Q15 -
Q15 cordic(Q15 &x0, Q15 &y0, Q15 &z0, Q15 vecmode)
-
you call it with actual parameters of type float -
static float gain1Cordic()
-
{
-
/* compute gain by evaluating cos(0) without inv gain */
-
float x, y, z;
-
-
x = 1;
-
y = 0;
-
z = 0;
-
cordic(&x, &y, &z, 1.0f);-->THE MAIN PROBLEM,
-
return x; the error messages repeated so much in this line
-
}
-
where did you get the Q15 fixed point library from?
my professor make it by himself the library, i included it in fixed_math.hpp
Can you post the .hpp file with your professors code in it? If it is large consider using the website mediafire.com to upload it and give us the link to it. Also, when you translate error messages, please try to translate word for word. What I mean is don't worry about changing the grammar and word order so that is makes sense in english. We can still get the meaning even though it may not look right, and that way there is less loss in translation. :)
Can you post the .hpp file with your professors code in it? If it is large consider using the website mediafire.com to upload it and give us the link to it. Also, when you translate error messages, please try to translate word for word. What I mean is don't worry about changing the grammar and word order so that is makes sense in english. We can still get the meaning even though it may not look right, and that way there is less loss in translation. :)
Sorry guys I've already told the OP they can't as the code is copyrighted.
The professor's code is copyrighted? Or the CORDIC code?
The professor's code is copyrighted? Or the CORDIC code?
sorry my professor code is copyrighted
Would your professor not give limited permission under an academic free license for us to view his/her code?
Would your professor not give limited permission under an academic free license for us to view his/her code?
It would have to be by PM if he/she does as it cannot be publicly published on the site.
Mary
finally i can solved the errors in my program , but the counting result is wrong.Take a look in my program , where is my mistakes?
*ps i had count arctan using CORDIC in floating point and i use the same method when counting it in fixed point only in here i use Q15 class. i`m bold-ing the font which is different from my floating point program and Italic font is what i use for the floating point. -
#include <vcl.h>
-
#pragma hdrstop
-
-
-
#include "Unit1.h"
-
#include "math.h"
-
#include "fixed_math.hpp"
-
#define MAXBITS 15
-
//---------------------------------------------------------------------------
-
#pragma package(smart_init)
-
#pragma resource "*.dfm"
-
TForm1 *Form1;
-
//---------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
-
: TForm(Owner)
-
{
-
}
-
//---------------------------------------------------------------------------
- static float atanTable[MAXBITS];
- static double atanTable[MAXBITS];
-
-
-
void initCordic()
-
{
-
/* must call this first to initialise the constants.
-
* of course, here i use the maths library, but the
-
* values would be precomputed.
-
*/
-
-
float t = 1.0f;
-
double t = 1;
-
int s;
-
for (s = 0; s < MAXBITS; ++s)
-
{
-
atanTable[s] = atan(t);
-
t /= 2;
-
}
-
-
}
-
-
-
/* CORDIC m=1, y-->0 */
-
-
-
- Q15 cordic(Q15* x0, Q15* y0, Q15* z0, Q15 vecmode)
- void cordic(double* x0, double* y0, double* z0, double vecmode)
-
{
-
-
short t;
-
Q15 x, y, z;
-
double t;
-
double x, y, z;
-
-
int s;
-
-
t = 1.0f;
-
x = *x0; y = *y0; z = *z0;
-
-
for (s = 0; s < MAXBITS; ++s)
-
{
-
-
Q15 x1;
-
double x1;
-
-
-
if (vecmode >= 0.0f && y < vecmode || vecmode<0.0f && z >= 0.0f)
-
{
-
Q15 x1 = x - y>>t;
-
y = y + x>>t;
-
z = z - Q15(atanTable[s]);
-
}
-
else
-
{
-
Q15 x1 = x + y>>t;
-
y = y - x>>t;
-
z = z + Q15(atanTable[s]);
-
}
-
-
x=x1;
-
t /= 2;
-
}
-
-
*x0 = x;
-
*y0 = y;
-
*z0 = z;
-
-
return z;
-
}
-
-
- Q15 atanCordic(Q15 a)
- double atanCordic(double a)
-
{
-
/* domain: all a */
- Q15 x = 1.0f;
-
Q15 z = 0.0f;
-
double x = 1;
-
double z = 0;
-
cordic(&x, &a, &z, 0.0f);
-
return z;
-
}
-
-
void __fastcall TForm1::Button1Click(TObject *Sender)
-
{
-
AnsiString buf;
-
float x;
-
float y;
-
double v,y,r;
-
double x;
-
-
-
initCordic();
-
-
for (x=0.0;x<=1.0;x=x+0.1)
-
{
-
-
Q15 v = atanCordic(x);
-
v = atanCordic(x);
-
y = atan(x);
-
-
Memo1->Lines->Add(buf.sprintf("%5.2f\n", x));
-
Memo2->Lines->Add(buf.sprintf("%10.6f\n",Q15ToShort(v)/32768.0));
-
Memo3->Lines->Add(buf.sprintf("%10.6f\n",Q15ToShort(y)/32768.0));
-
-
}
-
-
-
}
-
//---------------------------------------------------------------------------
-
-
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Adrian Parker |
last post by:
I'm using the code below in my project. When I print all of these fixed
length string variables, one per line, they strings in questions do not
properly pad with 0s. strQuantity prints as " ...
|
by: Roger Leigh |
last post by:
Hello,
I'm writing a fixed-precision floating point class, based on the ideas
in the example fixed_pt class in the "Practical C++ Programming" book
by Steve Oualline (O' Reilly). This uses a...
|
by: Shi Mu |
last post by:
any python module to calculate sin, cos, arctan?
|
by: pout |
last post by:
What are the purposes of fixed-point? When should it be used?
I read:
#define Int2Fixed(x) (((long)(short)x) << 16)
and the fixed-point in 16.16 format. Does the 16 in the MACRO refer to...
|
by: Davidlohr Bueso |
last post by:
Hi,
I've been trying to write some trigonometric functions of the math library
(sin, cos, tan, etc, etc.) in C and I've learned that instead of using
series, the best way to go is by using the...
|
by: Gerald |
last post by:
Recently, my program need to be run in embeded enviroment, and I cann't
use standard library. But I need to use arctan(x), so I implement it
like the following:
inline double pow(double x,...
|
by: riya1012 |
last post by:
hello guys,
I need some help from you. I am doing a DSP project and for that I need
to do some C coding for the conversion of sample data which is in
floating point representation to fixed point...
|
by: Dave Townsend |
last post by:
Hi,
I'm working on an implementation of the CORDIC
algorithm for a library of functions.
One of the benefits of the CORDIC algorithm is that you
can implement it with simple additions of...
|
by: astri |
last post by:
i`m doing thesis about comparing calculation of arctan by polynomial and CORDIC. I`ve read a lot of journal and books about CORDIC and this is what i understand.
1. make x and y
2. make...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |