trigonometric functions

Go To Last Post
121 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And in C++14 (at least in g++) you don't even need anything external to the language to generate a LUT at compile time, as I have shown before:

https://www.avrfreaks.net/forum/g...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It does require the manual work of creating the program in the first place.

 

In this case, it's a once-off task - so I think the different approaches are probably quits.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Write code to do it?

 

I'd just go here...

 

http://www.daycounter.com/Calcul...

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"not mess about doing it on an embedded target.":

 

Table generation is not meant to be done on an embedded target, it is meant to be done on a PC/RPi -being it standard or not is utterly pointless: in a school, dedicated to MCU/computer science , it would be terrible if a native c compiler was not in every computer -> OP has a working solution, and

thus does not need to mess with pointless (can a vague, inexisting thing have a meaning?) spreadshts.

 

Hundreds of scripting languages (dared to add  http://merd.sourceforge.net/ )  can do table generation, too.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Write code to do it?

 

Do your sine generator cope with cosines?

Changine some lines in a trivial C program (same thing would apply with Fortran ...) can give access to any function (is there a compute_any_one_variable_function_online site?)

LUTs are quite reusable, fast , but the generation should not depend on an IT link, which might break...

 

Another advantage, from OP point of view: it is less trivial than library calling, less terrible than implementing from a Taylor series in asm.... heis crual teacher might think -s-he did part of the work.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

some "real "noise:

 

Table generation is not meant to be done on an embedded target

 That depends I have seen code (for fast CRC) where the table is generated on the fly, either at init (where speed don't matter), or when rx/tx are enabled (to save RAM use when no in use).

So that way the code can be very small even for big tables.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
Table generation is not meant to be done on an embedded target

Yes - that was exactly my point!

 

And I would consider an RPi an "embedded target" in this context - really not a great choice as a development host.

 

And, again, the OP has said (s)he is using AVR Studio - so (s)he does have Windows.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It does require the manual work of creating the program in the first place.

 

Then, a cleverly designed compiler can detect 90% of the typos. spreadshts are too interactive for clumsy people and no trace is kept of the errors (one cannot fix them) .

 

 

I choose C (would have prefered R or Fortran) because:if OP has a less cruel teacher next year/next life, he will have to learn C (and to use libraries!). Else, may be, in a embedded oriented course, I hope he already knows...

 

Last Edited: Thu. Jan 25, 2018 - 02:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:
spreadshts (sic) are too interctive (sic)  for clumsy people

laugh

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jan 25, 2018 - 02:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"And I would consider an RPi an "embedded target" in this context - really not a great choice as a development host."

 

Well, in Macon -France- Rpis are given to student in electrical engeneering... making the "My PC is GREATEST than you RPi" war utterly absurd... (unless you convince me that Macon teachers are very cruel) 

(nanopis -chinese, cheaper, Brexit oblige; are 30% slower than RPis -can run R and open CV with the same time and ... same results as plain PC, 5 yrs old).

RPis (nanoPis are smaller) cannot be a great choice.

Small is beautiful.

Last Edited: Thu. Jan 25, 2018 - 02:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Corrected typo which needed correction; gave link to an unknown -thanks Heaven- language.

Last Edited: Thu. Jan 25, 2018 - 02:41 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I can not believe I have read this entire thread in real time, debating whether or not I wanted to contribute.

 

Part of the reason I wanted to get the ol basic interpreter from 1977 to run again, was I still remember the first night I sat down with an Eliza program.  The random function on these older computers seemed so much better.  Anyway the word for all of these higher math functions are Chebyshev_polynomials . These are so straightforward they were used on computer back in the 1960s on an IBM360 when computers consisted of sliding beads on strings of wood called abacuses and slide rules.

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

awneil wrote:
actually, I'd probably include that in the spreadsheet.

dbrion0606 wrote:
spreadshts (sic) are too interctive (sic)  for clumsy people

laugh

 

I would do it in a spreadsheet also.  In fact I did do it in a spreadsheet for T2K because the desk I was sitting at when doing much of it only had office tools available and no compilers/IDEs etc.

 

If you have concerns about a spreadsheet being wrong (clumsy human) then you can self-test yourself by drawing graphs with the data.  I also used the spreadsheet to calculate the polar co-ord data of the aliens and draw them on an X/Y line graph in the spreadsheet.  Later the AVR used the three cycle long sin() function to convert the stored polar co-ord back to cartesian for drawing to the TV screen.

 

I even got the spreadsheet to write the 12 thousand lines of assembly code that comprise the insane video mode because I could not work out a way to write a macro to get the compiler to do it for me.

 

It's funny that.  In my case sin() = 2 lines of ASM code that executed in 3 clocks.  Spitting a pixel out every 5 clock cycles to an NTSC TV = 12K lines of ASM code.

 

Spreadsheets are really awesome tools that don't just need to be used for profit and loss statements.  They can pre-calculate all sorts of look up tables, they can help you create bitmap fonts tables, they can even write code for you that is too tedious to write by hand and too complex for a macro.

 

Edit:  Thought I'd add an image showing how spreadsheets can draw you graphs to check your numbers.

 

spreadsheet polar co-ord and the graph draw to check the image

Last Edited: Thu. Jan 25, 2018 - 08:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jporter wrote:
The random function on these older computers seemed so much better.

I had to read and re-read, being confused about random on old computers pertaining here.  Then it dawned that it was a continuation of the Eliza reference.

 

But I still need to think about your assertion.  As time has gone on and the computers are more powerful, aren't there analyses of the randomness of random?  I can only assume that the randomness has gotten better and not worse.  Why would a library provider use a "worse" implementation?  I guess I can see a reason -- a not-worse implementation might be too pricey in time and/or space and the toolchain/target cannot afford it.

 

It has been many decades since Eliza on a Teletype.  I've probably used rand() (and COBOL and FORTRAN and PLI and ... equivalents)  only occasionally, and not in anger when randomness was of vital importance to the app.  In fact, I find it useful that rand() will generate the same sequence with the same seed as the repeatability occasionally makes testing a bit easier.

 

Now, how you >>get<< that seed...

[edit] An answer about rand() on Stack Overflow sounds decent:

...However, rand() uses an LCG which does not give you a uniform distribution of numbers. That is, you'll get some number hit with a higher frequency than others (although with infinite time you would hit all since infinity is just that cool). If you require a uniform distribution...

And another, that pretty much supports you:

3 down vote

rand()i...s bad because it's not a random function - not even a mediocre one. Every library, operating system, yahoo with a keyboard, can write his own rand and get away with it. The purpose of rand is to give output that looks random enough to be used in non-critical applications, usually with an LCG.

Once in a blue moon you might come across some library that uses a sound algorithm for rand but there's simply no guarantee that this will ever happen. Thus, you are much more likely to run into a 15-liner hack than a sophisticated CSPRNG - and that's OK. rand() was never meant to be crypto-grade.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Thu. Jan 25, 2018 - 08:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

I had to read and re-read, being confused about random on old computers pertaining here.  Then it dawned that it was a continuation of the Eliza reference.

Well I was actually thinking about the Chebyshev polynomials but the rand() function was part of the same library.

 

Better is probably not the best word to use.  I think the seeds came from the keystroke buffers.  That might have been on the time share system.  Interesting enough, the 1981 version and the 1977 version have different polynomial coefficients in the tables. So there must be a reason for this change.  My mentor used to like to check the results of the computer with his slide rule,  Especially after the pentium fiasco.  I have a little hard bound booklet on rounding errors in computer floating point.  A 16 bit float still only has 65535 unique numbers it can represent.  I think standard floats represent something like 24 million.    I was given an assignment while in school to bitpack floating point numbers to store RA and Dec in astronomy tables.  The idea was to use all the bits in the floating point array as that was how the system stored the numbers.  The whole table had to fit into 8K.

 

theusch wrote:

But I still need to think about your assertion.  As time has gone on and the computers are more powerful, aren't there analyses of the randomness of random?  I can only assume that the randomness has gotten better and not worse.  Why would a library provider use a "worse" implementation?  I guess I can see a reason -- a not-worse implementation might be too pricey in time and/or space and the toolchain/target cannot afford it.

better or worse is probably not the best way of putting it.  I am of an age where pi was best represented by 22/7ths.  A lot of engineering has been done to that approximation. 

 

As for modern randomness numbers, most of these seem to be graded by color as in a noise profile.  Like white, pink blue.  Other times they are represented by some long dead European white guy living in the 18th century as in Gaussian or Baysian distribution.    Curious how a lot of this math came about in the french revolution, as the peasants to to lying on their census forms. Not to mention battle field estimates and weather prediction.  When the royalty was restored, the kings were angered to learn the country was smaller.  I think china has similar stories where the leaders were not too happy when the mathematicians and astronomers, told them that things were not practicable.

 

In an old textbook I have it gives the user a sample of some random numbers from the 1973 draft lottery (How old the book is.)  This is not a new problem.  In antiquity lotteries where used to determine  such things as who served in the Athenian senate. There were questions even then about the fairness of such devices.  (so we have written descriptions of how such machines worked.)  

 

It is interesting in looking back at the older ways of problem solving.  Without asking a smart "Winston Smith" aka siri/alexia for help on political forecasting.  So much in this day and age relies on knowing how to ask the question.   Otherwise there is likely to be 125 somewhat random replies to the simplest of queries.

 

theusch wrote:

It has been many decades since Eliza on a Teletype.  I've probably used rand() (and COBOL and FORTRAN and PLI and ... equivalents)  only occasionally, and not in anger when randomness was of vital importance to the app.  In fact, I find it useful that rand() will generate the same sequence with the same seed as the repeatability occasionally makes testing a bit easier.

I guess in this day and age Eliza has a lot more phrases in her dictionary. 

 

Well it certainty makes emulating the old games somewhat consistent.  I had a favorite Mahjong tile game from the Mac Plus days.  I converted this to a more modern programming language.  The random seed was the time of day in system time.  Once I found what the formula for rand() was, I was able to reproduce the old game play.

 

It could just be that when I was first starting out programs like Eliza and Hammurabi/Kingdoms, seemed so much more effective.  

 

(edit: what is this box thing I can not delete, also what happed to the BBCode version of the editor?---->)

   
Last Edited: Thu. Jan 25, 2018 - 10:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the 1981 version and the 1977 version have different polynomial coefficients in the tables

 

My guess is (unless there was an error) that the first version was with the "correct" polynomials, and the newer has a correction to compensate for the value form first element that aren't used.

 

I remember that I checked the C64 poly's and the last element was wrong so the max error was less. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

andrewm1973 wrote:
Spreadsheets are really awesome tools that don't just need to be used for profit and loss statements.

 

That's worthy of a thread all of its own: https://www.avrfreaks.net/forum/spreadsheets-are-really-awesome-tools

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thankx for the most counterproductive post about spreadshts..

A tab completed line of R/{matlab,octave) can plot data....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wondering how seeing alternate methods is counter productive.

 

Regardless if using R could have done that little bit faster for me, at the time I only had access to a spreadsheet, a word processor and an email client.

 

Aside from that - I think not having an interest in the way other people might like to do something is quite ignorant.

 

If someone does something amazing, does it matter if they chose the same toolset as you?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, if belittling other people ways is ignorant, I can be ignorant too (see awneil's post about RPi, in ca 108).... 

 

I choose *not* to use spreashts last century (too typo prone,  Time I speared was used learning Arabic and Malagasy (no infinite brain, if any).)

 

OP may have learnt some C (and even some *.asm, to do his homework). I cannt guess whether -s-he has learnt some rational use of spreadshts -or how to interface them with cppcheck, say- .

Last Edited: Fri. Jan 26, 2018 - 01:03 PM

Pages