# LOOK UP TABLE for sine wave signal

Status
Not open for further replies.

#### JJFORTY

##### Member level 1
look up table excel sin(x)

Hi Guys,

I'm creating a Look-up table to generate digital values of a Sinewave signal. I'm using excel to calculate data. Does anyone know a better software for this application..

Also which is the best and most accurate method to achive the digital sampling.

Thanks for attention..

#### Davood Amerion

You can use C programming language too.

#### JJFORTY

##### Member level 1
oops forgot to say..

Assembly language programming is required.

#### thuvu

##### Member level 3
Here is a sinewave table

Points: 2

#### antedeluvian

##### Full Member level 1
JJFORTY said:
I'm creating a Look-up table to generate digital values of a Sinewave signal. I'm using excel to calculate data. Does anyone know a better software for this application..

Excel is a good start. It is pretty easy to export the data that is calculated to a text file which can be configured as an assembly or C. First you need to format each cell to a binary number by rounding the number (see the ROUND function). Then you can format to hex if you like using the DEC2HEX and convert it to a string by concatenation like

"0x"& C4

where C4 is the cell. Excel is smart enough to convert the cell to a string.

Finally you need to create a VBA macro that takes each cell in turn and outputs it within a formatted line to a file. A possible example would look something like

Open Filename For Append as #1

'set up a,b for output cells

For iUtil=0 to 255

print #1, cells(a,b)
'increment a and/or b as necessary
'print any other format like a comment

next

close.

I realise this is a bit vague and I apologise, but I can't do much more without actually giving you to solution and time does not permit. If you are interested in taking this approach and learning about the many ways to use excel in electronics consider my book "Excel by Example : A Microsoft Excel Cookbook for Electronics Engineers " published by Elsevier/Newnes ISBN 0750677562. It includes this technique plus many other aspects of Excel. See Amazon.com for the TOC.

-Aubrey Kagan

### JJFORTY

Points: 2

#### echo47

JJFORTY, your question seems to say that you need an assembly language program that generates a table of sinewave values. That sounds strange. Please clarify what programming languages you have available, and what format the sine table needs to be.

Here's a little C program that generates a 256-point table of 16-bit sinewave values:
Code:
#include <stdio.h>
#include <math.h>
#define POINTS 256
#define BITS   16

int main(void)
{
int n;

for (n=0; n<POINTS; n++)
printf("%d\n", (int)floor(0.5 + ((1 << (BITS-1)) - 0.50001) * sin(2 * 3.1415926535897932 / POINTS * n)));
return 0;
}

Points: 2

#### ankit12345

##### Banned
one smple and good solution.
sin(x+dx)=sin(x)+dxcos(x)
cos(x+dx)=cos(x)-dxsin(x)
initially take x as 0(binary 16 bit) and dx as 1/16 binary
from sine 0 and cos 0 ,you can get sine 1 and cos 1.proceed till 180 .......any prob...ask me again

#### JJFORTY

##### Member level 1
Sorry for any confusion,

Basically, the idea is to create the digital equivalent of an analogue sine wave (as accurate as possible), store the binary values in a EPROM together with a DAC and Voilà! a Digitally-Generated sine wave source. (so i hope)

I started off by calcualting some vales of sin(x) look-up table attached, Unfortunally due to the limitations or my poor understanding of the software, excel does not recognize some binary values. Hence my first post

Thank you all for your replies, specialy antedeluvian for your comments and recommendation on the book i will defenitally look into that.

Any help or advice would be most appreciated.

Thanks Again.

#### antedeluvian

##### Full Member level 1
JJFORTY said:
Thank you all for your replies, specialy antedeluvian for your comments and recommendation on the book i will defenitally look into that.

I must apologise. In my rush to get a plug for my book, I forgot to mention that most of what I mentioned is covered in a design idea that I wrote for EDN. The design idea in fact provided the basis for one of the chapters for the book. Of course the book takes the description much slower and the application is far more sophisticated, but the basis of what you need remains in the design idea which you can find here

Incidentally, you can also get a broad idea of the general tone of the book from these articles which actually led to the book. See the articles #138,#139, & #140 here.

http://www.dtweed.com/circuitcellar/xkaganau.htm

-Aubrey

#### ankit12345

##### Banned
I have done a project titled"low area cmos chip that gives digital equivalent of an analogue sine wave (as accurate as possible)".
The logic is
sin(x+dx)=sinx+dxcosx
cos(x+dx)=cosx-dxsinx
where i have taken
x as 16bit binary value
dx as 16bit binary value equal to 1
sin 0 = 000000000000000
cos 0 = 111111111111111
This has been worked out on excel sheet.

#### thuvu

##### Member level 3
Let's say you create the sine table, what is the frequency(min and max) of the sine that can be produced?

#### Supaswing

##### Junior Member level 3
thuvu said:
Let's say you create the sine table, what is the frequency(min and max) of the sine that can be produced?
Iam not an expert but I would say it rely only on the D/A converter.
Btw, the idea of Ankit is not bad. Or what about a Pulse Width Modulation, as it doesnt need a D/A.

#### sandhyaram

##### Newbie level 6
Hai friends.....

I want to create sine look up table at frequency 50Hz and amplitude 2.5.... I confused..... any one clearly said formula and how to create lookup table

#### chiplogic

##### Junior Member level 3
why can't you use CORDIC to get sine value in digital?

#### poornimargowda

##### Junior Member level 3

Status
Not open for further replies.