Sign in

username:

password:



Not a member?

Search c6x



Search tips

Subscribe to c6x



c6x by Keywords

AD535 | BIOS | Booting | Bootloader | C621 | C6211 | C6415 | C671 | C6711 | C6711DSK | C6713 | CCS | Chassaing | COFF | DAT | DM64 | DM642 | DMA | DSK671 | DSK6711 | EDM | EDMA | EMIF | Emulator | EVM | EVM620 | FFT | FIR | GPIO | Halting | HPI | HWI | IDK | JTAG | LDB | LDH | LDW | Linker | LMS | LOG_printf | Matlab | McBSP | MEM_alloc | MIPS | PCI | PCM3003 | Pipeline | Profiling | QDM | Reset | ROM | RTDX | Sampling | SDRAM | Stack | TEB | THS1206 | TMS320C621 | TMS320C6416 | TMS320C6711 | TMS320C6713 | UART | Vector Table | XBUS | XDS560

Sponsor

Industry's highest performing at the lowest power DSPs now as low as $5.00*
Start development today!
*volume pricing for 10ku

Discussion Groups

See Also

Embedded SystemsFPGAElectronics

Discussion Groups | TMS320C6x | SINE AND COSINE OF ANY ANGLE

Technical discussions about the TI C6000 DSPs (including the c62x, c64x and c67x DSPs).

  

Post a new Thread

SINE AND COSINE OF ANY ANGLE - ruben - May 25 17:18:00 2000

Hi, we need a efficient routine to calculate the sin and cos of any
angle(a 32 bits float value) in a TMS320C6701. The problem is that we
call the funtion sin and cos into a C loop. Then, the consecuence is
that the compiler doesn´t generate a software pipelined code. We try
with a Taylor serie and splitted quadratic interpolation, but the code
is too large to be pipelined. We need about 6 digits or more of
accuracy.

Any advices will be greatly appreciated. Thanks...



______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: SINE AND COSINE OF ANY ANGLE - Kiran Gunnam - Jun 8 19:59:00 2000

Hi,
You can try table lookup method if the memory is not a constraint.
regards
Kiran
>From: ruben <>
>Reply-To:
>To:
>Subject: [c6x] SINE AND COSINE OF ANY ANGLE
>Date: Thu, 25 May 2000 19:18:54 +0200
>
>Hi, we need a efficient routine to calculate the sin and cos of any
>angle(a 32 bits float value) in a TMS320C6701. The problem is that we
>call the funtion sin and cos into a C loop. Then, the consecuence is
>that the compiler doesn´t generate a software pipelined code. We try
>with a Taylor serie and splitted quadratic interpolation, but the code
>is too large to be pipelined. We need about 6 digits or more of
>accuracy.
>
>Any advices will be greatly appreciated. >Thanks...
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com






(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: SINE AND COSINE OF ANY ANGLE - Author Unknown - Jun 8 23:01:00 2000

On 25 May 2000, at 19:18, ruben wrote:

> Hi, we need a efficient routine to calculate the sin and cos of any
> angle(a 32 bits float value) in a TMS320C6701. The problem is that we
> call the funtion sin and cos into a C loop. Then, the consecuence is
> that the compiler doesn´t generate a software pipelined code. We try
> with a Taylor serie and splitted quadratic interpolation, but the code
> is too large to be pipelined. We need about 6 digits or more of
> accuracy.

Decimal or binary digits?

> Any advices will be greatly appreciated.

As I understand it, longer code should not be a problem as long as the
pipeline remains full, and does not stall. It doesnt matter that the code
doesn't all fit in the pipeline at once.

YOu should be able to extract the source for sin and cos from the library
that you are using. You'll probably find that its a series expansion. =================================================
Eliot Blennerhassett *:-{)>
AudioScience, Inc. (New Zealand Office)
6 Centaurus Rd
Christchurch 8002 Mobile: +64 21 1183531
New Zealand Ph/fax: +64 3 3327818
e...@audioscience.com
<http://www.audioscience.com>
=================================================
______________________________
Start your Android Ice Cream Sandwich development on TI's AM35x Sitara ARM Cortex-A8 processor today.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

RE: SINE AND COSINE OF ANY ANGLE - Ralph Weir - Jun 9 8:32:00 2000

Hi!

Two things may help:

1) There's a little-known constant you can define - I think it's
TI_ENHANCED_MATH_H - which allows the compiler to use float versions of sin
and cos. Normally sin & cos are doubles - read the manual on this, it will
make quite a difference.

2) Get the archiver out, and extract the source code of sin from the rts
library. The archiver is ar6x.exe, the source is rts.src... sin is likely
to be in either sin.c or sin.asm.

If it's in sin.c, include that function in your own code. Now, the compiler
(if you set the optimiser high enough) can in-line the function, so there is
no function call.

If it's in sin.asm, there may be a C-code version of the function included
in the .asm file. Again, you could include taht in your source.

With both of these, benchmark the code before and after - it may not hel;p
you very much. Remember sin & cos are still big functions, so unless the
calling functions are very complex, you'll be spending 99% of your time in
sin, and halving the time to do that last 1% might not help...

ATB
Ralph

********************************************************
Ralph Weir mailto:
Hunt Engineering http://www.hunteng.co.uk
Direct: +44 (0)1283 819991
Mobile: +44 (0)7703 472329
Fax: +44 (0)1283 819992

Somerset Office:
+44 (0)1278 760188
+44 (0)1278 760199
********************************************************

> -----Original Message-----
> From: ruben [mailto:]
> Sent: 25 May 2000 18:19
> To:
> Subject: [c6x] SINE AND COSINE OF ANY ANGLE > Hi, we need a efficient routine to calculate the sin and cos of any
> angle(a 32 bits float value) in a TMS320C6701. The problem is that we
> call the funtion sin and cos into a C loop. Then, the consecuence is
> that the compiler doesnt generate a software pipelined code. We try
> with a Taylor serie and splitted quadratic interpolation, but the code
> is too large to be pipelined. We need about 6 digits or more of
> accuracy.
>
> Any advices will be greatly appreciated. > Thanks... >
> ------------------------------------------------------------------------
> Tradiant is creating the premiere marketplace for shippers and ocean
> carriers to conduct the business of moving containerized freight online.
> Our comprehensive suite of online services saves time and money.
> Visit Tradiant today. www.tradiant.com
> http://click.egroups.com/1/5136/7/_/14737/_/960483692/
> ------------------------------------------------------------------------
>
> To Join: Send an email to
>
> To Post: Send an email to
>
> To Leave: Send an email to
>
> Archives: http://www.egroups.com/group/c6x
>
> Other Groups: http://www.dsprelated.com


______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: SINE AND COSINE OF ANY ANGLE - Petr Vicherek - Jun 9 10:01:00 2000

wrote:
>
> On 25 May 2000, at 19:18, ruben wrote:
>
> > Hi, we need a efficient routine to calculate the sin and cos of any
> > angle(a 32 bits float value) in a TMS320C6701. The problem is that we
> > call the funtion sin and cos into a C loop. Then, the consecuence is
> > that the compiler doesn´t generate a software pipelined code. We try
> > with a Taylor serie and splitted quadratic interpolation, but the code
>
> > is too large to be pipelined. We need about 6 digits or more of
> > accuracy.
>
> Decimal or binary digits?
>
> > Any advices will be greatly appreciated.
>
> As I understand it, longer code should not be a problem as long as the
>
> pipeline remains full, and does not stall. It doesnt matter that the
> code
> doesn't all fit in the pipeline at once.

I think that he is talking about so called pipeline optimization,
that is the compiler is not able to prepare second, third or higher
loop iteration before the first is finished.

U seem to be talking about runtime pipeline.

The problem is that no loop that contains a call or another loop
can't be optimized.

I have the same problem on 6202.
Because for this accuracy we need 32-bit multiplies, the sin(x) takes
6 16-bit multipiles and 8 additions/subtractions per iteration
I later actually maanged to schedule 3 iterations in prallel but
it still cannot find better than 6 cycles per iteration.
With 8 iterations and overhead on 200MHz engine it takes dear 300 ns
to get down to 7 digit accuracy.

> YOu should be able to extract the source for sin and cos from the
> library
> that you are using. You'll probably find that its a series expansion.

But that's just what he is doing and the resulting code is so long,
that it cannot be optimized that way eirher.

--
Petr Vicherek Ericsson Mobile Networks Phone: +31 53-450-5287



______________________________
Start your Android Ice Cream Sandwich development on TI's AM35x Sitara ARM Cortex-A8 processor today.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: SINE AND COSINE OF ANY ANGLE - Petr Vicherek - Jun 9 10:01:00 2000


Hello, Ruben and Kiran

Kiran Gunnam wrote:
>
> Hi,
> You can try table lookup method if the memory is not a constraint.
> regards
> Kiran

That's not the approach for 6-digit precision. Besides memory for
huge tables, the lookup and linear (or rather quadratic) interpolation
would take about as long as the taylor series.

Try to make it iterate faster. This can be done by splitting the
interval of <0; Pi/2> to two or more smaller pieces and use two different
taylors develop around different origin.

For instance sin(x) in <0; Pi/4> and cos(Pi/2 - x) for x in <Pi/4; Pi/2>.
This might reduce the number of necessary coefficients by half.

Then hardcode a shorter expansion.

> >From: ruben <>
> >Date: Thu, 25 May 2000 19:18:54 +0200
> >
> >Hi, we need a efficient routine to calculate the sin and cos of any
> >angle(a 32 bits float value) in a TMS320C6701. The problem is that we
> >call the funtion sin and cos into a C loop. Then, the consecuence is
> >that the compiler doesn´t generate a software pipelined code. We try
> >with a Taylor serie and splitted quadratic interpolation, but the code
> >is too large to be pipelined. We need about 6 digits or more of
> >accuracy.

--
Petr Vicherek Ericsson Mobile Networks Phone: +31 53-450-5287



______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: SINE AND COSINE OF ANY ANGLE - Petr Vicherek - Jun 9 10:21:00 2000


> >From: ruben <>
> >Date: Thu, 25 May 2000 19:18:54 +0200
> >
> >Hi, we need a efficient routine to calculate the sin and cos of any
> >angle(a 32 bits float value) in a TMS320C6701. The problem is that we
> >call the funtion sin and cos into a C loop. Then, the consecuence is
> >that the compiler doesn´t generate a software pipelined code. We try
> >with a Taylor serie and splitted quadratic interpolation, but the code
> >is too large to be pipelined. We need about 6 digits or more of
> >accuracy.
> >
> >Any advices will be greatly appreciated.

Yet another idea, if this will be possible.

If you really need sin/cos od ANY (random) angle, then try
break the code too large to smaller pieces. For instance pre-calculate
the sin/cos in one loop using taylor series and then use it in the
next loop.

If these angles are in some relation, then you should be able to
find some iterative formula how to calculate one sin/cos from the
previously calculated value.

For instance formula:

(1) x = k0*x + k1*y;
y = k0*y - k1*x;

generates orthogonal sine and cosine waves if k0=cos(inc) and k1=sin(inc).
This has low THD, but due to inaccuracies amplitude slowly drifts
and needs to be adjusted.

If you use two formulas like

(2) z = K*y - x; x = y; y = x;

Where K = 2*cos(inc)

then the amplitude stay steady but you have to care to have very
good accuracy for K if the increment 'inc' is small to achieve really
low THD. For larger 'inc' (1) is the ideal formula, unless you do not
care much about frequency deviation since quantized cos(inc) will be always
a little off the accurate irrational value.

--
Petr Vicherek Ericsson Mobile Networks Phone: +31 53-450-5287



______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: SINE AND COSINE OF ANY ANGLE - ruben - Jun 15 17:29:00 2000

Thanks Petr and all who respond to me.

Well, actually when the original message was posted I had a solution. The late
was for reasons not concerning me. I got to split the loops in smallers ones
and with a table for cuadratic interpolation (thanks to Jerry Avins for the
idea) I have an acceptable speed (but not as fast as i wish) and accuracy (
ERROR<0.0001).
Because there's not a linear relation into angles consecutives (Its a cuadratic
relation, with not trivial coeficients), It cant be able to use a recursive
formula.

And using the code from TI like Ralph Weir suggested can´t be done because this
code its not suitable to be inlined and optimized due to serious calls to
others functions and its big size.

Someone said about the newest version of Code Composer and Compiler
Tools...well, It looks like my city is too far away from TI, since always the
new issues take three or four months to get it.

Ruben.
Petr Vicherek wrote:

> Yet another idea, if this will be possible.
>
> If you really need sin/cos od ANY (random) angle, then try
> break the code too large to smaller pieces. For instance pre-calculate
> the sin/cos in one loop using taylor series and then use it in the
> next loop.
>
> If these angles are in some relation, then you should be able to
> find some iterative formula how to calculate one sin/cos from the
> previously calculated value.
>
> For instance formula:
>
> (1) x = k0*x + k1*y;
> y = k0*y - k1*x;
>
> generates orthogonal sine and cosine waves if k0=cos(inc) and k1=sin(inc).
> This has low THD, but due to inaccuracies amplitude slowly drifts
> and needs to be adjusted.
>
> If you use two formulas like
>
> (2) z = K*y - x; x = y; y = x;
>
> Where K = 2*cos(inc)
>
> then the amplitude stay steady but you have to care to have very
> good accuracy for K if the increment 'inc' is small to achieve really
> low THD. For larger 'inc' (1) is the ideal formula, unless you do not
> care much about frequency deviation since quantized cos(inc) will be always
> a little off the accurate irrational value.
>
> --
> Petr Vicherek Ericsson Mobile Networks Phone: +31 53-450-5287
>
> ------------------------------------------------------------------------
> Click here for savings: beMANY!
> http://click.egroups.com/1/4557/7/_/14737/_/960550370/
> ------------------------------------------------------------------------
>
> To Join: Send an email to
>
> To Post: Send an email to
>
> To Leave: Send an email to
>
> Archives: http://www.egroups.com/group/c6x
>
> Other Groups: http://www.dsprelated.com


______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )