Tri to Sine diode shaper

Jun 10, 2008 20 Replies

Can someone please direct me to a passive circuit using breakpoint diodes, preferably no more than six, to shape a sine wave from a 5Vpp triangle? The available power source is single supply 6V.



I did check the net, but had no luck with finding a basic approach.



Mike Kendall


Patent:3737642 shows one way to do it.

General question comes to mind... has anyone written a program that would derive the "best" piecewise linear fit to a function, f(x), for a given number of segments?

...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

For *diode shapers*? Wow, great idea, I'll get right on it, as soon as I finish my .NET visualization tool for helping pigs decide on their lipstick colour. ;)

If you really want to do this, you can kluge it up pretty fast from a singular value decomposition routine, e.g. SVDFIT from Numerical Recipes, with an optimization loop that moves the fit points around to minimize the residual. For linear fits, you use a set of triangular eigenfunctions, each of which goes from 0 at point m-1 to 1 at point m to 0 again at point m+1. Any piecewise linear approximation is a weighted sum of those.

I did this a couple of months ago with cubic splines for a tunnel junction parameter extraction program--it needed speeding up so I could generalize it to finite temperature, which takes a lot more computation. The spline bit took about half a day, and it works great, but I have to go back and finish debugging the finite-temperature part. :(

Cheers,

Phil Hobbs

Cheers,

Phil Hobbs

My approach to "diode shapers" uses OpAmps, so I don't have to contend with diode vagaries.

"Numerical Recipes", the book I presume? I think I've opened it once or twice since I bought it a very long time ago ;-)

...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

Sometimes I envy you all the transistors you can use. Here I spend years just trying to make one or two useful devices, and all the while, you're squandering them on breakpoint amplifiers. ;)

Widlar (iirc) published a cute trick using BJT saturation for making breakpoint amplifiers--you run a bunch of emitter followers whose bases connect to the summing junction, and their emitters to the output via resistors, with collector resistors to some appropriate reference. When a transistor saturates, its beta drops to zilch, and the emitter resistor suddenly appears in parallel with the feedback resistor. It's reasonably temperature independent because the switchover depends on VCE instead of VBE, and it has much sharper edges than a garden-variety diode breakpoint amp.

Yes, it's a pretty good book attached to some reasonably functional although sometimes ugly code. I built a shared library out of it some years back, because (unlike most other numerical codes I've seen) NR's documentation quality is excellent and the number of actual bugs is quite small.

Cheers,

Phil Hobbs

Yes, a long time ago. I've also used Excel, believe it or not. Mathematicians tend to define "best" in terms of least squares, but often (at least in instrumentation design) what you want to minimize is the maximum abs. value of error everywhere within a range. I have access to Mathcad these days, so I might try that if Excel didn't work. Best regards, Spehro Pefhany

"it\'s the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com

Least squares _would_ get messy. I'll try Excel. PSpice can do it but it's a tedious process of tweak-tweak-tweak :-(

...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

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.

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

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

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

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.

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

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

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.

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...

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

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

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

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
**

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required