Average over short period of time

Discussion in 'Cadence' started by Matthew, Mar 17, 2010.

  1. Matthew

    Matthew Guest

    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
     
    Matthew, Mar 17, 2010
    #1
  2. 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, Mar 25, 2010
    #2
  3. Andrew Beckett wrote, on 03/25/10 16:05:
    ....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.
     
    Andrew Beckett, Mar 25, 2010
    #3
  4. Matthew

    Matthew Guest

    Thanks yes the second item is sufficient.
     
    Matthew, Apr 13, 2010
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.