Maker Pro
Maker Pro

Drawing Mathematical Blank This A.M.

J

Jim Thompson

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
 
S

Spehro Pefhany

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

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)


(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


Best regards,
Spehro Pefhany
 
J

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)
[snip]

-(1-Decimal) or equivalently Decimal-1

So the result is a _sawtooth_.

...Jim Thompson
 
S

Spehro Pefhany

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)
[snip]

-(1-Decimal) or equivalently Decimal-1

So the result is a _sawtooth_.

...Jim Thompson

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



Best regards,
Spehro Pefhany
 
J

Jim Thompson

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

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

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)
[snip]

-(1-Decimal) or equivalently Decimal-1

So the result is a _sawtooth_.

...Jim Thompson

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



Best regards,
Spehro Pefhany

"Integer.Decimal" is always a positive number.

...Jim Thompson
 
H

Helmut Sennewald

Jim Thompson said:
On Fri, 04 Mar 2005 14:25:40 -0500, Spehro Pefhany

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

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

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)


[snip]

-(1-Decimal) or equivalently Decimal-1

So the result is a _sawtooth_.

...Jim Thompson

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



Best regards,
Spehro Pefhany

"Integer.Decimal" is always a positive number.

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
 
J

Jim Thompson

On Fri, 4 Mar 2005 21:22:07 +0100, "Helmut Sennewald"

[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
 
S

Spehro Pefhany

"Integer.Decimal" is always a positive number.

...Jim Thompson

FRACT(X + 0.5) -0.5

is valid/differentiable for -0.5 < x < 1.5

....not good enough?


Best regards,
Spehro Pefhany
 
J

Jim Thompson

FRACT(X + 0.5) -0.5

is valid/differentiable for -0.5 < x < 1.5

...not good enough?


Best regards,
Spehro Pefhany

I need it valid for 0 <= X -> 1G ;-)

...Jim Thompson
 
H

Helmut Sennewald

Jim Thompson said:
On Fri, 4 Mar 2005 21:22:07 +0100, "Helmut Sennewald"

[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)

Hello Jim,
this is mostly the same, but your wish was:
I want to report Decimal when Decimal is <= 0.5
But report -(1-Decimal) when Decimal is > 0.5

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
 
G

Genome

Spehro Pefhany said:
On Fri, 04 Mar 2005 12:04:51 -0700, the renowned Jim Thompson


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

Hohup,.... -(1-Decimal) is (Decimal-1), not... -(Decimal-1).

DNA
 
G

Genome

Jim Thompson said:
On Fri, 4 Mar 2005 21:22:07 +0100, "Helmut Sennewald"

[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

Whilst I will not deny that your solution was nice you poofed me off for
using a programming language syntax (and called the bugger C).

Helmuts answer suggests to me that Spice might just have such a
method/programming language.

As if you didn't mention.......

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

WTF

DNA
 
S

Spehro Pefhany

Hohup,.... -(1-Decimal) is (Decimal-1), not... -(Decimal-1).

DNA

Right. Any ideas on making a function that works?


Best regards,
Spehro Pefhany
 
J

Jim Thompson

Right. Any ideas on making a function that works?


Best regards,
Spehro Pefhany

N - Round(N) "works" mathematically, but causes PSpice to have great
convergence heartburn.

Now I have to figure out a smoothing function ;-)

...Jim Thompson
 
J

James Meyer

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

I would suggest using a PIC.

Jim "Foggy in the evening" Meyer
 
G

Genome

Spehro Pefhany said:
Right. Any ideas on making a function that works?


Best regards,
Spehro Pefhany

I haven't got a fucking clue.

Didn't understand the original question.

DNA
 
D

Don Taylor

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

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

Tony Williams

Jim Thompson said:
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
 
F

Fred Bloggs

Tony said:
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

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<y<=0.5, FRACT(-(n+y-0.5))=

=FRACT(-n + 0.5-y)=0.5-y in (0.5,0]

then 0.5-FRACT(-(n+y-0.5)) in (0,0.5] as 0<y<=0.5


EACH INTEGER n+0.5+y 0<y<0.5

FRACT (-(n+0.5+y-0.5))=FRACT(-n-y)=FRACT(-(n+1)+(1-y))

=1-y so that 0.5-(1-y)=y-0.5 in (-0.5,0) as 0<y<0.5
 
Top