Drawing Mathematical Blank This A.M.

I need to process (in PSpice) a number of the form:

Integer.Decimal

I want to report Decimal when Decimal is 0.5

(For behavioral modeling of a PLL)

I seem to be foggy-brained this morning and can't sort it out :-)

I have the following functions available:

  • ..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))} ..PARAM PI = 3.141593
*

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson
Loading thread data ...

[snip]

-(1-Decimal) or equivalently Decimal-1

So the result is a _sawtooth_.

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson

"Integer.Decimal" is always a positive number.

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson
[snip]

There is INT and IF, but IF is useful only where it's not useful ;-)

I just came up with this while having a mac-n-cheese lunch with my

3-year-old grand-daughter:

(Integer.Decimal) - Round(Integer.Decimal)

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson

I need it valid for 0 1G ;-)

...Jim Thompson

-- | James E.Thompson, P.E. | mens | | Analog Innovations, Inc. | et | | Analog/Mixed-Signal ASIC's and Discrete Systems | manus | | Phoenix, Arizona Voice:(480)460-2350 | | | E-mail Address at Website Fax:(480)460-2142 | Brass Rat | |

formatting link
| 1962 | I love to cook with wine. Sometimes I even put it in the food.

Reply to
Jim Thompson

Do you mean this, or do you mean -(Decimal-1), which would be a continuous inverted-V-shaped function?

If the latter, then maybe something like

0.5 - sqrt((x-0.5)^2)

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
Reply to
Spehro Pefhany

Does it have to be valid (and is it defined) as above for x < 0 and x > 1 as well?

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
Reply to
Spehro Pefhany

FRACT(X + 0.5) -0.5

is valid/differentiable for -0.5 < x < 1.5

....not good enough?

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
Reply to
Spehro Pefhany

....

Looks like you might have a sign function to work with.

So I look at you having two different behaviors, one on each side of 1/2 and think of using the sign function to tease these apart.

I'm assuming that SGN is your sign function and is +1 when the argument is positive and -1 when it is negative. So if I'm right

(SGN(x-1/2)+1)/2 will be +1 for x > 1/2 and 0 elsewhere

-(SGN(x-1/2)-1)/2 will be +1 for x < 1/2 and 0 elsewhere

Now you want a line y=x-1 for x > 1/2 and you want a line y=x for x < 1/2.

Assemble all the bits

(SGN(x-1/2)+1)/2*(x-1)-(SGN(x-1/2)-1)/2*x

Then throw it at Derive (free 30 day trial at

formatting link
and do a plot of the result to make sure it does what I wanted, discover I had swapped a + and - initially, corrected above. And, then just for grins I tap the Simplify button to ask it if it knows of a simpler form. It responds with (actually Derive uses SIGN, not SGN):

x-1/2-SGN(2*x-1)/2

hummm... which with a few moments thought seems to be

x-1/2-SGN(x-1/2)/2

which I throw back at Derive just to make sure my brain cells haven't completely failed, and all three plots are the same sawtooth.

If I think about the final version for a moment I realize it is a line with the same slope as the one you desire, positioned midway between the two lines you wanted, and they are using SGN to either add or subtract 1/2 to give the desired vertical offset. Cute, I didn't think of that one.

I hope this helps. If you need more fiddling with this let me know and I'll try to think up some alternative solutions.

Reply to
Don Taylor

"Jim Thompson" schrieb im Newsbeitrag news: snipped-for-privacy@4ax.com...

Hello Jim, I will express it in a general form.

IF (number-INT(number) > 0.5 THEN result = -( INT(number) + 1 - number ) ELSE result = number - INT(number)

I assume there is an INT-function and an IF-function in PSPICE.

Best Regards, Helmut

Reply to
Helmut Sennewald

"Jim Thompson" schrieb im Newsbeitrag news: snipped-for-privacy@4ax.com...

Hello Jim, this is mostly the same, but your wish was:

goal yours

10.499 -> 0.49 0.499 10.500 -> 0.500 -0.500 10.501 -> -0.499 -0.499

Ok, I assume you can live with a small change of your requirement.

Decimal when Decimal is < 0.5

-(1-Decimal) when Decimal is >= 0.5

Best Regards, Helmut

Reply to
Helmut Sennewald

On Fri, 04 Mar 2005 12:04:51 -0700, Jim Thompson wroth:

I would suggest using a PIC.

Jim "Foggy in the evening" Meyer

Reply to
James Meyer

Try thinking of it as an analogue opamp problem, with a Vin and a Vout.

Offset Vin by -0.5, full wave rectify it, correct for the offset.

Vout = 0.5 - ABS(Vin - 0.5).

Vin Vout

0.1 0.1 0.2 0.2 0.3 0.3 0.4 0.4 0.5 0.5 0.6 0.4 0.7 0.3 0.8 0.2 0.9 0.1 1.0 0.0
--
Tony Williams.
Reply to
Tony Williams

That might be the answer, BUT with NEARLY ideal diodes.

My expression, N - Round(N), works by itself, but the sharp discontinuities cause insurmountable convergence issues.

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson

Nah- it is fundamentally a discontinuous function and that rules out linear analog computation. Going back to the less obvious algebra where a simple guess will not suffice yields the following argument: View in a fixed-width font such as Courier.

F(X)=0.5-FRACT(0.5-X)

+0.5| /x /x /x | / | / | / | ^ | / / / | | / | / | / | |/ / / F(X) 0------------1------------2-----------3---> X | / / / | | | / | / | / ^ | / / / | | / | / | / -0.5| o/ o/ o/

x==LIM F(Y)=F(X) i.e. F(X) "left" continuous Y->X(-)

o== right limit discontinuity

F(X)= (X-0.5) MOD (0,1] -0.5 , modulo a half-open interval

FRACT(Y)= Y MOD [0,1) and 1-FRACT(-Y)=Y MOD (0,1]

Then F(X)= 1-FRACT(0.5-X)-0.5= 0.5- FRACT(0.5-X)

CHECK: EACH INTEGER n>=0, FRACT (-(n+0.5))=0.5 AND 0.5-0.5=0

EACH INTEGER n+y 0

Reply to
Fred Bloggs

So?

The real issue turns out to be differentiability.

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson

LTSpice has FLOOR built in and it is faster than using TAN to get there.

--
--
kensmith@rahul.net   forging knowledge
Reply to
Ken Smith

It seems that all those functions are going to have differentiability problems.

If you have do have access to the functions used to define those then

-ATAN(K*(X-1/2))/PI+X-1/2

seems to approximate what you want and is a smooth function, where K is a positive constant, the larger you make it the closer you are to a sawtooth but the larger the negative spike the derivative will have. K perhaps somewhere between 10 and 40 might serve your purposes.

Or, if you have hyperbolic tangent, or can build it from e^x, then

-TANH(K*(X-1/2))/2+X-1/2

also seems to approximate what you want and is a smooth function.

And, if I understood your earlier comment, that you wanted your function to linearly increase for increasing x, then either of these satisfy that, unlike x-ROUND(x) that is a sawtooth repeating over and over and not increasing beyond x=1.

Reply to
Don Taylor

Sawtooth _repeating_ IS what I want.

But I do have TANH available.

Thanks for the pointer.

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson

Aha! Sweet! Thanks! Nice and smooth! Now I'll try closing the loop :-)

...Jim Thompson

--
|  James E.Thompson, P.E.                           |    mens     |
|  Analog Innovations, Inc.                         |     et      |
|  Analog/Mixed-Signal ASIC's and Discrete Systems  |    manus    |
|  Phoenix, Arizona            Voice:(480)460-2350  |             |
|  E-mail Address at Website     Fax:(480)460-2142  |  Brass Rat  |
|       http://www.analog-innovations.com           |    1962     |
             
I love to cook with wine.      Sometimes I even put it in the food.
Reply to
Jim Thompson

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.