473,765 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cprogramming question

1 New Member
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 1348
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
5042
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
3090
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 before rowID answID qryrow questionID datafield 1591 12 06e 06e 06e question 1593 12 06f 06f 06f question 1594 12 answer to the question 06f
10
3094
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
1630
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
9568
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9957
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.