Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Simple sine table


  • Please log in to reply
22 replies to this topic

#21 mbruner63

mbruner63

    New Member

  • Members
  • Pip
  • 3 posts

Posted 05 July 2013 - 12:30 PM

This great!  I will certainly use this for my AGENT performance algorithm.  For the circadian rhythm component, I use a double sine wave.



#22 mbruner63

mbruner63

    New Member

  • Members
  • Pip
  • 3 posts

Posted 05 July 2013 - 06:11 PM



#23 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 10 August 2013 - 08:02 AM

Hello all,

 

When Hanzibal first posted his sine & Cosine table code, I tried it out and wished for a few updates.

 

The first thing I did was to write a test harness where I spotted the same issue reported by Dan T.

The test harness showed that around zero (or 90 degrees for cosine) and each time the table wraps the waveform was not symetrical:

Sin( -2) =  -1Sin( -1) =   0Sin(  0) =   0Sin(  1) =   1Cos(254) =   1Cos(255) =   0Cos(256) =   0Cos(257) =  -1

It turns out that I solved the problem in the same way Dan T did - by adding an extra value to give an odd number of samples in the byte array. This allows it to be symetrical around each quarter cycle.

 

I also noticed that the peak value was not being reached at the correct moment. I solved that by a small modification to the generation of the table data.

 

Next I added the features I wanted for myself - adjustable table length, and adjustable peak value.

These are specified by setting the two private parameters at the start of the class. _peakValue and _tableLength. Everything else is calculated from these, so no other code should need to be edited.

I also added two new functions that return the peak, and the total virtual table size if the program needs them.

 

The code is commented, so it should be easy to use.

 

My updated class and test harness program.cs file are attached in the zip.

The test harness prints the cross over points of the waves, and the entire table to the debug output, the printing is formatted so that the output can be saved as a .csv file and opened in a spreadsheet for plotting.

 

Have fun - Paul






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.