Tri to Sine diode shaper

A nifty way to do it if the function you're trying to fit has an analytical derivative is this:

Create a stepped approximation to the derivative of the function you're trying to fit; in this case find a stepped approximation to a cosine.

Integrate the stepped approximation and you will get a linear segment approximation.

The slopes of the linear segments are, of course, the values of the steps. The start and finish point of each linear segment is the same as the start and finish of each associated step.

It may not be the exact minimum error fit, but it's really fast to compute and it's good enough for the sort of thing the OP wants. If you want better accuracy, generate more steps.

See the graphic over on ABSE.

Reply to
The Phantom
Loading thread data ...

I see an EXE and a bunch of RAR files over on ABSE. What do I do with them ?:-)

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC\'s and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
         America: Land of the Free, Because of the Brave
Reply to
Jim Thompson

Those aren't for you. You want the one called "Linear segment approximation method".

Reply to
The Phantom

OK. What process did you use to space the segments? (I'm not conversant in Mathematica.)

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC\'s and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
         America: Land of the Free, Because of the Brave
Reply to
Jim Thompson

On Fri, 13 Jun 2008 09:34:19 -0700, Jim Thompson wrote

You just plot a certain function of t and you will get the steps.

For the first sine graph, use:

(Ceiling(y+Cos(t))/y + Floor(y+Cos(t))/y)/2

where y is the number of steps you want. You will get a good approximation for any value of y, but if you make it an integer plus .66, you will get slightly lower distortion than otherwise.

For the second sine graph, the one with a flat on top, use:

(Round(y+Cos(t))/y

where y is the number of steps you want. Make y an integer plus .16 for best results.

For positive numbers:

Ceiling(z) means the integer just greater than z (the integer part of z plus 1).

Floor(z) means the integer just less than z (the integer part of z).

Round(z) means the integer part of (z + .5).

Make the obvious changes for negative numbers.

Reply to
The Phantom

Great!

My oldest son, Aaron, wrote (with some pointers from Brian Hirasuna) these for me for PSpice a number of years ago ...

.FUNC FRACT(X) {(ATAN(TAN(((X+1e-11)-0.5)*PI))/PI+0.5)} .FUNC TRUNC(X) {((X)-FRACT(X))} .FUNC ROUND(X) {(TRUNC((X)+0.5))} .FUNC BIT(X,Y) {(SGN(X-(2**Y)+0.1)+1)/2} .FUNC DIV(X,MOD) {TRUNC((X+1u)/MOD)} .FUNC MODULO(X,MOD) {(FRACT(X/MOD))*MOD} .FUNC INT(X) {((X)-FRACT(X))}

I had forgotten I had them... had to do a HD search to remember where they were ;-)

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC\'s and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
         America: Land of the Free, Because of the Brave
Reply to
Jim Thompson

Mr. Phantom,

Please comment on this discussion...

formatting link

Which convention is generally followed with negative numbers?

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
| Analog/Mixed-Signal ASIC\'s and Discrete Systems  |    manus    |
| Phoenix, Arizona  85048    Skype: Contacts Only  |             |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |    1962     |
             
         America: Land of the Free, Because of the Brave
Reply to
Jim Thompson

I think there are good reasons to use the round-to-even method.

See:

formatting link

Also, Knuth in Vol 2 of "The Art of Computer Programming" discusses rounding.

Reply to
The Phantom

I have a suspicion that all those high-powered math guys who initlally created the contents are often long gone and they're just hiring some generic programmers to port it from language to language, using some sort of regression testing to make sure nothing gets broken in the process.

Not to mention they have some bizarre licensing scheme where just buying the book doesn't entitle you to use the printed code -- that's a separate purchase!

I suppose it's still cheaper than Matlab with the appropriate toolboxes...

Reply to
Joel Koltner

That was the major disappointment for me. The book is not cheap, then they *still* want money off you if you use the contents!

--

John Devereux
Reply to
John Devereux

created

There's a whole pile of better numerical code out there, once you figure out what you want to do--I bought the floppy disc back in the day, which entitled me to use it myself. I've been doing that for about 15 years, which makes it pretty cheap at the price.

Cheers,

Phil Hobbs

Reply to
Phil Hobbs

I've just reread the available licenses (in the book). They appear to want to license per instance of any algorithm used from the book.

Prices from $65 per instance...

Actually they say "per screen". So I guess it is free for my embedded systems after all :)

--

John Devereux
Reply to
John Devereux

They were physicists and engineers and the orignal was in Fortran.

You have to treat it with a little bit of caution. Some of the NA algorithms contain typos in some of the languages and versions. And the C/Pascal code shows its Fortran arrays with base index of 1 heritage in places. Something which makes the bitreverse slightly opaque for instance.

Although these days there are better free libraries available online once you have a few keywords/references out of the book. The references in the chapters are excellent. See sci.numerical-analysis for various gripes about the known defects of the NA code. I think they go a bit overboard on criticising it unfairly but you do need to treat the sample code with a bit of caution. There are more robust solutions but most of the time the NA code will work OK.

Reasonably functional sums it up pretty well. Test carefully that it does what you want and you should be OK.

Regards, Martin Brown

** Posted from
formatting link
**
Reply to
Martin Brown

I have no intention of ever using it in a product. NR has probably saved me 6 months' work over the years, so that sum is completely reasonable for development purposes.

Cheers,

Phil Hobbs

Reply to
Phil Hobbs

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.