Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Average over short period of time

3,799 views
Skip to first unread message

Matthew

unread,
Mar 17, 2010, 3:17:20 PM3/17/10
to
Does anyone know how to measure the average value of a parameter over
a reduced amount of time using spectre? I am aware of the average
function but this only averages over the entire simulation period. My
circuit has a stabilization period and I am interested in measuring
the average of the final value.

Thanks,

Matt

Andrew Beckett

unread,
Mar 25, 2010, 12:05:46 PM3/25/10
to
Matthew wrote, on 03/17/10 19:17:

Hi Matt,

Not sure if this would help you?

/* abMovingAvg.il

Author A.D.Beckett
Group Custom IC (UK), Cadence Design Systems Ltd.
Language SKILL
Date Jan 13, 2010
Modified
By

Performs a moving average. You specify the X window (typically
time) over which it (effectively) clips and averages, rolling
over the waveform.

; register the abMovingAvg() special function with the calculator
abRegMovingAvgSpecialFunction()

; example of usage:
abMovingAvg(v("signal" ?result 'tran) 5u)

The code is based on the VerilogA in solution 11277434. You may
want to adjust it if you don't like any DC offset it introduces
if the signal does not start at its average value...
The code produces the same result that the VerilogA model does.

***************************************************

SCCS Info: @(#) abMovingAvg.il 01/13/10.14:05:02 1.1

*/

/***************************************************************
* *
* (abCreateMovingAvgForm) *
* *
* Create the form for the moving average *
* *
***************************************************************/
(procedure (abCreateMovingAvgForm)
(let (timeWindow gain)
(setq timeWindow (ahiCreateStringField
?name 'timeWindow
?prompt "Time Window"
?value ""
))
(setq gain (ahiCreateStringField
?name 'gain
?prompt "Gain"
?value "1.0"
))
(calCreateSpecialFunctionsForm
'abMovingAvgForm
(list
(list timeWindow 0:0 180:20 90)
(list gain 0:30 180:20 90)
))
))

/********************************************************************
* *
* (abMovingAvgSpecialFunctionCB) *
* *
* Callback for the moving average special function, which assembles *
* the expression from the form values *
* *
********************************************************************/
(procedure (abMovingAvgSpecialFunctionCB)
(calCreateSpecialFunction
?formSym 'abMovingAvgForm
?formInitProc 'abCreateMovingAvgForm
?formTitle "Moving Average"
?formCallback "calSpecialFunctionInput( 'abMovingAvg '(timeWindow gain))"
))

/***************************************************************
* *
* (abRegMovingAvgSpecialFunction) *
* *
* Register the moving average function *
* *
***************************************************************/
(procedure (abRegMovingAvgSpecialFunction)
(calRegisterSpecialFunction
(list "abMovingAvg" 'abMovingAvgSpecialFunctionCB))
t
)

/***************************************************************
* *
* (abMovingAvg waveform timeWindow @optional (gain 1.0)) *
* *
* Given a waveform, a timewindow and an optional gain, compute *
* the moving average. *
* *
***************************************************************/
(procedure (abMovingAvg waveform timeWindow @optional (gain 1.0))
(cond
;---------------------------------------------------------------------
; Handle ordinary waveform
;---------------------------------------------------------------------
((drIsWaveform waveform)
(let (xVec len firstX lastX delayed k1)
;------------------------------------------------------------------
; Find first and last x-values to clip the shifted waveform
;------------------------------------------------------------------
(setq xVec (drGetWaveformXVec waveform))
(setq firstX (drGetElem xVec 0))
(setq len (drVectorLength xVec))
(setq lastX (drGetElem xVec (sub1 len)))
;------------------------------------------------------------------
; Calculate the gain - taking into account the time window,
; and then delay the signal
;------------------------------------------------------------------
(setq k1 (quotient gain timeWindow))
(setq delayed (clip (lshift waveform -timeWindow) firstX lastX))
;------------------------------------------------------------------
; Integrate the difference between the original waveform and teh
; delayed waveform (multiplied by the gain)
;------------------------------------------------------------------
(iinteg (times k1 (difference waveform delayed)))
)
) ; waveform
;---------------------------------------------------------------------
; Handle family
;---------------------------------------------------------------------
((famIsFamily waveform)
(famMap 'abMovingAvg waveform timeWindow gain)
) ; family
(t
(error "abMovingAvg - can't handle %L\n" waveform)
)
) ; cond
)

Andrew Beckett

unread,
Mar 25, 2010, 12:07:41 PM3/25/10
to
Andrew Beckett wrote, on 03/25/10 16:05:

> Matthew wrote, on 03/17/10 19:17:
>> Does anyone know how to measure the average value of a parameter over
>> a reduced amount of time using spectre? I am aware of the average
>> function but this only averages over the entire simulation period. My
>> circuit has a stabilization period and I am interested in measuring
>> the average of the final value.
>>
>> Thanks,
>>
>> Matt
>
> Hi Matt,
>
> Not sure if this would help you?
>
...code snipped...

Just re-read your question. My solution may have been overkill. Perhaps you just
need to do:

average(clip(<waveform> <endOfStabilizationTime> <endOfSimulationTime>))

Regards,

Andrew.


Matthew

unread,
Apr 13, 2010, 2:11:24 PM4/13/10
to
Thanks yes the second item is sufficient.
0 new messages