Drawing Mathematical Blank This A.M.

J

Jim Thompson

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

Integer.Decimal

I want to report Decimal when Decimal is <= 0.5

But report -(1-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.
 
On Fri, 4 Mar 2005 21:22:07 +0100, "Helmut Sennewald"
<helmutsennewald@t-online.de> wrote:

[snip]
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
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.
 
Jim Thompson <thegreatone@example.com> writes:
I need to process (in PSpice) a number of the form:

Integer.Decimal

I want to report Decimal when Decimal is <= 0.5

But report -(1-Decimal) when Decimal is > 0.5
....
.FUNC BIT(X,Y) {(SGN(X-(2**Y)+0.1)+1)/2}
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 www.derive.com) 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.
 
On Sat, 05 Mar 2005 08:11:14 +0000 (GMT), Tony Williams
<tonyw@ledelec.demon.co.uk> wrote:

In article <vebh21hd6p0r3ear3he4vq24ot6ovob9tr@4ax.com>,
Jim Thompson <thegreatone@example.com> wrote:

I want to report Decimal when Decimal is <= 0.5
But report -(1-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 :)

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
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.
 
On Sun, 06 Mar 2005 11:57:30 -0700, Jim Thompson
<thegreatone@example.com> wrote:

On Sun, 06 Mar 2005 12:23:50 -0600, dont@agora.rdrop.com (Don Taylor)
wrote:
[snip]

But I do have TANH available.

Ah. Well then I think this might do what you are looking for

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

Thanks for the pointer.

Happy to help with math puzzles

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

...Jim Thompson
Looks like the ATAN in function FRACT makes it blow up inside the
feedback 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.
 

Welcome to EDABoard.com

Sponsor

Back
Top