473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

cprogramming question

Assignment statement
Background theory

Consider a phasor at an angle of Ø (0 <= Ø <= 90°) with projections on the x and y axes as x0 and y0, respectively.

Let it be rotated by an angle of Ø0 (0 <= Ø0 < 90°) so that it is now at an angle of Ø'0 (0 <= Ø'0 <= 90°) with projections on the x and y axes as x1 and y1, respectively.

It can be easily shown that x1 and y1 are related to x0 and y0 as follows:

x1 = x0 * cos(Ø0) - y0 * sin(Ø0)
y1 = x0 * sin(Ø0) + y0 * cos(Ø0)

These equations above can be re-written as:

x1 = cos(Ø0) * [ x0 - y0 * tan(Ø0) ]
y1 = cos(Ø0) * [ x0 * tan(Ø0) + y0 ]

Let the phasor it be rotated for the ith time by an angle of Øi (0 <= Øi < 90°) so that it is now at an angle of Ø'i (0 <= Ø'i <= 90°) with projections on the x and y with projections on the x and y axes as xi and yi, respectively.

The new projections on the x and y axes will be:

xi+1 = cos(Øi) * [ xi - yi * tan(Øi) ]
yi+1 = cos(Øi) * [ xi * tan(Øi) + yi ]

If repeated substitutions are made, then there will be a leading product term

Ci = ∏j=1 to i cos(Øj)

We choose the angles Øi as tan-1(2-i)

Then,

C∞ = ∏j=0 to ∞ (2j / √(1+2j)) ≈ 0.0607253 ≈ 39797/65536 = 39797 / 216

We can avoid the final multiplication by taking sufficient number of terms and accomodate for C∞ in the initial values of x0 and y0.

We can approximate any angle Ø (0 <= Ø <= 90°) by the as Ø ≈ ∑i=0 to N ±Øi.

The above mentioned technique can then be used to compute both sin(Ø) and cos(Ø) without requiring the use of multiplication or division operations.
Problem statement

Write a program to read an angle Ø scaled up by 100. Use only integer varilables for the actual cordic computation (excluding the pre-processing for computing the table of angles). Let Ø' be the approximation of Ø by your algorithm. Your program should compute the sin(Ø') and cos(Ø'). In your program you should not use any multiplication or division operation. You should implement division by 2 using the bitwise right shift operator avaialble in 'C' (>>). You should store values of tan-1(2-i), (0 <= i < 16), scaled up by 100 in an integer array called angles. Initialize the array in your program so angles[i]=arctan(2-i).

At the end of your computation, prior to the final division by 216, your results will be scaled up by 216. Note, that if you do an integer division, then your result will be zero (as sine and cosine values never exceed one).

For reporting the final result, you should use floating point division for the final division (by type casting the operands to float)

As the computation progresses, report the intermediate (scaled) Ø' and values of (xi) sin(Ø') and (yi) cos(Ø') computed by cordic (these will be int values). Finally, report the acutal values of Ø and values of sin(Ø) and cos(Ø) as float values and also the corresponding values given by the math library functions.
Sample output

The numbers below are fictitious values, given only to illustrate the correct format

84 9425 65198
100 1003 65529
0.000000 0.000000 1.000000
0.000000 0.000000 1.000000

The last row shows the given value of Ø and sine and cosine values reported by the library functions

The penultimate line shows the approximated values Ø' and sine and cosine values computed using the cordic procedure, but converted to floating point numbers

The earlier numbers show the intermediate values of Ø' and sine and cosine values as int values
Jan 31 '08 #1
1 1331
weaknessforcats
9,208 Expert Mod 8TB
Please read the posting guidelines.
Jan 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: just4me | last post by:
Exactly how do I read a specific location in the bios eprom. (such as debug.exe location ffff:0000)
12
by: Mars | last post by:
I searched and found quite many, but (nearly) all are about C++....... Any recommendation for such reference for pure C???? Thx~~~~ Mars.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.