Home
  • Products
  • Solutions
  • Support
  • Company

This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  • Products
  • Solutions
  • Support
  • Company
Community Mixed-Signal Design straight line (best) fit using viva calculator

Stats

  • Locked Locked
  • Replies 18
  • Subscribers 64
  • Views 27607
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

straight line (best) fit using viva calculator

vamshiky
vamshiky over 7 years ago

Hi,

I need to measure peak to peak variation of phase response (from an AC sim) w.r.t a straight line fit(best fit and not the end point fit)  for the same.

Is it doable using viva calculator or verilogAMS ?

 Thanks,

vamshiky

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 7 years ago

    There's no built-in function to do this, and I'd not written one so far (it's been one of those things I've been meaning to for a while because I think it's come up in the past). So I just quickly wrote this code below.

    To use it, save the code in a file called "abBestFit.ils" and load it from your .cdsinit using load("/path/to/abBestFit.ils") - ensure you keep the .ils suffix. Unfortunately you can't (yet) use the "fx" button in the calculator to register it with the calculator, so for now you'll need to just surround your waveform expression with abBestFit(...) and then  you can plot that.

    Regards,

    Andrew.

    /* abBestFit.ils
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Apr 05, 2018 
    Modified   Nov 22, 2023 
    By         A.D.Beckett
    
    Compute a best fit line for an input waveform. Uses
    Simple Linear Regression to compute the slope and intercept
    and then constructs a waveform with this slope and intercept
    
    Four functions:
    
    abBestFit(waveform) - returns a best fit waveform
    
    abBestFitSlope(waveform) - returns the slope of the best fit line
    
    abBestFitIntercept(waveform) - returns the y intercept of the best fit line
    
    abBestFitCoeffs(waveform) - returns a list of the intercept and slope.
        Note: this function does not handle family waveforms because it
        returns a list - but is useful for single waveforms
    
    Note, this uses SKILL++ lexical scoping so must keep the .ils
    suffix
    
    From IC618 ISR1 can now be added to the calculator via the fx button
    (also in the expression builder via the + button)
    
    ***************************************************
    
    SCCS Info: @(#) abBestFit.ils 11/22/23.14:16:49 1.4
    
    */
    
    (let ()
      /***************************************************************
      *                                                              *
      *                        (mean vector)                         *
      *                                                              *
      *     Internal function to compute the mean of the values      *
      *                        in the vector                         *
      *                                                              *
      ***************************************************************/
      (defun mean (vector)
        (let ((n (drVectorLength vector)) (sum 0.0))
          (for i 0 (sub1 n)
               (setq sum (plus sum (drGetElem vector i))))
          (quotient sum (if (zerop n) 1 n))
          )
        )
      /***************************************************************
      *                                                              *
      *            (uncorrectedStddev vector vectorMean)             *
      *                                                              *
      * Internal function to compute uncorrected standard deviation  *
      *  of vector. Same as population standard deviation. Pass in   *
      *   vector and mean so don't have to compute the mean again    *
      *                                                              *
      ***************************************************************/
      (defun uncorrectedStddev (vector vectorMean)
        (let ((n (drVectorLength vector)) (sum 0.0))
          (for i 0 (sub1 n)
               (setq sum 
                     (plus sum 
                           (expt 
                             (difference (drGetElem vector i) vectorMean)
                             2))))
          (sqrt (quotient sum (if (zerop n) 1 n)))
          )
        )
      /*****************************************************************
      *                                                                *
      *            (sampleCorrCoeff xVec yVec xMean yMean)             *
      *                                                                *
      * Internal function to compute the sample correlation coefficent *
      *                  between the x and y vectors                   *
      *                                                                *
      *****************************************************************/
      (defun sampleCorrCoeff (xVec yVec xMean yMean)
        (let (xSquared ySquared xy xyMean xSquaredMean ySquaredMean)
          (setq xy (times xVec yVec))
          (setq xSquared (expt xVec 2.0))
          (setq ySquared (expt yVec 2.0))
          (setq xyMean (mean xy))
          (setq xSquaredMean (mean xSquared))
          (setq ySquaredMean (mean ySquared))
          (quotient 
            (difference xyMean (times xMean yMean))
            (sqrt
              (times
                (difference xSquaredMean (expt xMean 2.0))
                (difference ySquaredMean (expt yMean 2.0))
                )))
          ))
      /***************************************************************
      *                                                              *
      *                  (computeCoeffs xVec yVec)                   *
      *                                                              *
      *  Internal function to compute the alpha and beta - intercept *
      *             and slope - from the x and y vectors             *
      *                                                              *
      ***************************************************************/
      (defun computeCoeffs (xVec yVec)
        (let (xMean yMean xStddev yStddev rxy alpha beta)
          (setq xMean (mean xVec))
          (setq yMean (mean yVec))
          (setq xStddev (uncorrectedStddev xVec xMean))
          (setq yStddev (uncorrectedStddev yVec yMean))
          (setq rxy (sampleCorrCoeff xVec yVec xMean yMean))
          (setq beta (times rxy (quotient yStddev xStddev)))
          (setq alpha (difference yMean (times beta xMean)))
          (list alpha beta)
          )
        )
      /***************************************************************
      *                                                              *
      *                    (abBestFitCoeffs wave)                    *
      *                                                              *
      *  Global function to compute alpha and beta - intercept and   *
      *          slope of the best fit line and return them          *
      *                                                              *
      ***************************************************************/
      (defglobalfun abBestFitCoeffs (wave)
        (let (xVec yVec)
          (setq xVec (drGetWaveformXVec wave))
          (setq yVec (drGetWaveformYVec wave))
          (when (eq (drGetWaveformYType wave) 'doublecomplex)
            (error "abBestFitCoeffs: Cannot handle waveforms with complex values; use mag() or db20() or similar to convert to double values")
            )
          (computeCoeffs xVec yVec)
          )
        )
      /***************************************************************
      *                                                              *
      *                       (abBestFit wave)                       *
      *                                                              *
      *           Compute the slope and intercept and then           *
      *  create a waveform (with two points) matching the first and  *
      *             last x points of the input waveform              *
      *                                                              *
      ***************************************************************/
      (defglobalfun abBestFit (wave)
        (cond
          ((drIsWaveform wave)
           (let (xVec yVec len firstX lastX newXVec newYVec newWave)
             ;---------------------------------------------------------------
             ; Compute slope and intercept of best fit line
             ;---------------------------------------------------------------
             (setq xVec (drGetWaveformXVec wave))
             (setq yVec (drGetWaveformYVec wave))
             (when (eq (drGetWaveformYType wave) 'doublecomplex)
               (error "abBestFit: Cannot handle waveforms with complex values; use mag() or db20() or similar to convert to double values")
               )
             (destructuringBind (alpha beta) (computeCoeffs xVec yVec)
               ;-------------------------------------------------------------
               ; Construct best fit line waveform
               ;-------------------------------------------------------------
               (setq len (drVectorLength xVec))
               (setq firstX (drGetElem xVec 0))
               (setq lastX (drGetElem xVec (sub1 len)))
               (setq newXVec (drCreateVec 'double 2))
               (setq newYVec (drCreateVec 'double 2))
               (drAddElem newXVec firstX)
               (drAddElem newXVec lastX)
               (drAddElem newYVec (plus alpha (times beta firstX)))
               (drAddElem newYVec (plus alpha (times beta lastX)))
               ;-------------------------------------------------------------
               ; Sort out attributes for new waveform to match input
               ;-------------------------------------------------------------
               (putpropq newXVec (getq xVec units) units)
               (putpropq newXVec (getq xVec name) name)
               (putpropq newYVec (getq yVec units) units)
               (putpropq newYVec (getq yVec name) name)
               (setq newWave (drCreateWaveform newXVec newYVec))
               (famSetExpr newWave `(abBestFit ,(famGetExpr wave)))
               newWave
               )
             )
           )
          ((famIsFamily wave)
           (famMap 'abBestFit wave)
           )
          (t
            (error "abBestFit: cannot handle %L\n" wave)
            )
          )
        )
      /*******************************************************************
      *                                                                  *
      *                      (abBestFitSlope wave)                       *
      *                                                                  *
      * Compute the slope (beta) of the best fit through a set of points *
      *                                                                  *
      *******************************************************************/
      (defglobalfun abBestFitSlope (wave)
        (cond
          ((drIsWaveform wave)
           (cadr (abBestFitCoeffs wave))
           )
          ((famIsFamily wave)
           (famMap 'abBestFitSlope wave)
           )
          (t
            (error "abBestFitSlope: cannot handle %L\n" wave)
            )
          )
        )
      /************************************************************************
      *                                                                       *
      *                       (abBestFitIntercept wave)                       *
      *                                                                       *
      * Compute the intercept (alpha) of the best fit through a set of points *
      *                                                                       *
      ************************************************************************/
      (defglobalfun abBestFitIntercept (wave)
        (cond
          ((drIsWaveform wave)
           (car (abBestFitCoeffs wave))
           )
          ((famIsFamily wave)
           (famMap 'abBestFitIntercept wave)
           )
          (t
            (error "abBestFitIntercept: cannot handle %L\n" wave)
            )
          )
        )
      )
    
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abBestFit
      name abBestFit
      description "Best Fit Line"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave )
              signals (nil
                    wave (nil
                          prompt "Signal"
                          tooltip "Waveform"
                          )
               )
              params(nil
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abBestFitIntercept
      name abBestFitIntercept
      description "abBestFitIntercept"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave )
              signals (nil
                    wave (nil
                          prompt "Signal"
                          tooltip "Waveform"
                          )
               )
              params(nil
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abBestFitSlope
      name abBestFitSlope
      description "abBestFitSlope"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave )
              signals (nil
                    wave (nil
                          prompt "Signal"
                          tooltip "Waveform"
                          )
               )
              params(nil
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 7 years ago

    There's no built-in function to do this, and I'd not written one so far (it's been one of those things I've been meaning to for a while because I think it's come up in the past). So I just quickly wrote this code below.

    To use it, save the code in a file called "abBestFit.ils" and load it from your .cdsinit using load("/path/to/abBestFit.ils") - ensure you keep the .ils suffix. Unfortunately you can't (yet) use the "fx" button in the calculator to register it with the calculator, so for now you'll need to just surround your waveform expression with abBestFit(...) and then  you can plot that.

    Regards,

    Andrew.

    /* abBestFit.ils
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Apr 05, 2018 
    Modified   Nov 22, 2023 
    By         A.D.Beckett
    
    Compute a best fit line for an input waveform. Uses
    Simple Linear Regression to compute the slope and intercept
    and then constructs a waveform with this slope and intercept
    
    Four functions:
    
    abBestFit(waveform) - returns a best fit waveform
    
    abBestFitSlope(waveform) - returns the slope of the best fit line
    
    abBestFitIntercept(waveform) - returns the y intercept of the best fit line
    
    abBestFitCoeffs(waveform) - returns a list of the intercept and slope.
        Note: this function does not handle family waveforms because it
        returns a list - but is useful for single waveforms
    
    Note, this uses SKILL++ lexical scoping so must keep the .ils
    suffix
    
    From IC618 ISR1 can now be added to the calculator via the fx button
    (also in the expression builder via the + button)
    
    ***************************************************
    
    SCCS Info: @(#) abBestFit.ils 11/22/23.14:16:49 1.4
    
    */
    
    (let ()
      /***************************************************************
      *                                                              *
      *                        (mean vector)                         *
      *                                                              *
      *     Internal function to compute the mean of the values      *
      *                        in the vector                         *
      *                                                              *
      ***************************************************************/
      (defun mean (vector)
        (let ((n (drVectorLength vector)) (sum 0.0))
          (for i 0 (sub1 n)
               (setq sum (plus sum (drGetElem vector i))))
          (quotient sum (if (zerop n) 1 n))
          )
        )
      /***************************************************************
      *                                                              *
      *            (uncorrectedStddev vector vectorMean)             *
      *                                                              *
      * Internal function to compute uncorrected standard deviation  *
      *  of vector. Same as population standard deviation. Pass in   *
      *   vector and mean so don't have to compute the mean again    *
      *                                                              *
      ***************************************************************/
      (defun uncorrectedStddev (vector vectorMean)
        (let ((n (drVectorLength vector)) (sum 0.0))
          (for i 0 (sub1 n)
               (setq sum 
                     (plus sum 
                           (expt 
                             (difference (drGetElem vector i) vectorMean)
                             2))))
          (sqrt (quotient sum (if (zerop n) 1 n)))
          )
        )
      /*****************************************************************
      *                                                                *
      *            (sampleCorrCoeff xVec yVec xMean yMean)             *
      *                                                                *
      * Internal function to compute the sample correlation coefficent *
      *                  between the x and y vectors                   *
      *                                                                *
      *****************************************************************/
      (defun sampleCorrCoeff (xVec yVec xMean yMean)
        (let (xSquared ySquared xy xyMean xSquaredMean ySquaredMean)
          (setq xy (times xVec yVec))
          (setq xSquared (expt xVec 2.0))
          (setq ySquared (expt yVec 2.0))
          (setq xyMean (mean xy))
          (setq xSquaredMean (mean xSquared))
          (setq ySquaredMean (mean ySquared))
          (quotient 
            (difference xyMean (times xMean yMean))
            (sqrt
              (times
                (difference xSquaredMean (expt xMean 2.0))
                (difference ySquaredMean (expt yMean 2.0))
                )))
          ))
      /***************************************************************
      *                                                              *
      *                  (computeCoeffs xVec yVec)                   *
      *                                                              *
      *  Internal function to compute the alpha and beta - intercept *
      *             and slope - from the x and y vectors             *
      *                                                              *
      ***************************************************************/
      (defun computeCoeffs (xVec yVec)
        (let (xMean yMean xStddev yStddev rxy alpha beta)
          (setq xMean (mean xVec))
          (setq yMean (mean yVec))
          (setq xStddev (uncorrectedStddev xVec xMean))
          (setq yStddev (uncorrectedStddev yVec yMean))
          (setq rxy (sampleCorrCoeff xVec yVec xMean yMean))
          (setq beta (times rxy (quotient yStddev xStddev)))
          (setq alpha (difference yMean (times beta xMean)))
          (list alpha beta)
          )
        )
      /***************************************************************
      *                                                              *
      *                    (abBestFitCoeffs wave)                    *
      *                                                              *
      *  Global function to compute alpha and beta - intercept and   *
      *          slope of the best fit line and return them          *
      *                                                              *
      ***************************************************************/
      (defglobalfun abBestFitCoeffs (wave)
        (let (xVec yVec)
          (setq xVec (drGetWaveformXVec wave))
          (setq yVec (drGetWaveformYVec wave))
          (when (eq (drGetWaveformYType wave) 'doublecomplex)
            (error "abBestFitCoeffs: Cannot handle waveforms with complex values; use mag() or db20() or similar to convert to double values")
            )
          (computeCoeffs xVec yVec)
          )
        )
      /***************************************************************
      *                                                              *
      *                       (abBestFit wave)                       *
      *                                                              *
      *           Compute the slope and intercept and then           *
      *  create a waveform (with two points) matching the first and  *
      *             last x points of the input waveform              *
      *                                                              *
      ***************************************************************/
      (defglobalfun abBestFit (wave)
        (cond
          ((drIsWaveform wave)
           (let (xVec yVec len firstX lastX newXVec newYVec newWave)
             ;---------------------------------------------------------------
             ; Compute slope and intercept of best fit line
             ;---------------------------------------------------------------
             (setq xVec (drGetWaveformXVec wave))
             (setq yVec (drGetWaveformYVec wave))
             (when (eq (drGetWaveformYType wave) 'doublecomplex)
               (error "abBestFit: Cannot handle waveforms with complex values; use mag() or db20() or similar to convert to double values")
               )
             (destructuringBind (alpha beta) (computeCoeffs xVec yVec)
               ;-------------------------------------------------------------
               ; Construct best fit line waveform
               ;-------------------------------------------------------------
               (setq len (drVectorLength xVec))
               (setq firstX (drGetElem xVec 0))
               (setq lastX (drGetElem xVec (sub1 len)))
               (setq newXVec (drCreateVec 'double 2))
               (setq newYVec (drCreateVec 'double 2))
               (drAddElem newXVec firstX)
               (drAddElem newXVec lastX)
               (drAddElem newYVec (plus alpha (times beta firstX)))
               (drAddElem newYVec (plus alpha (times beta lastX)))
               ;-------------------------------------------------------------
               ; Sort out attributes for new waveform to match input
               ;-------------------------------------------------------------
               (putpropq newXVec (getq xVec units) units)
               (putpropq newXVec (getq xVec name) name)
               (putpropq newYVec (getq yVec units) units)
               (putpropq newYVec (getq yVec name) name)
               (setq newWave (drCreateWaveform newXVec newYVec))
               (famSetExpr newWave `(abBestFit ,(famGetExpr wave)))
               newWave
               )
             )
           )
          ((famIsFamily wave)
           (famMap 'abBestFit wave)
           )
          (t
            (error "abBestFit: cannot handle %L\n" wave)
            )
          )
        )
      /*******************************************************************
      *                                                                  *
      *                      (abBestFitSlope wave)                       *
      *                                                                  *
      * Compute the slope (beta) of the best fit through a set of points *
      *                                                                  *
      *******************************************************************/
      (defglobalfun abBestFitSlope (wave)
        (cond
          ((drIsWaveform wave)
           (cadr (abBestFitCoeffs wave))
           )
          ((famIsFamily wave)
           (famMap 'abBestFitSlope wave)
           )
          (t
            (error "abBestFitSlope: cannot handle %L\n" wave)
            )
          )
        )
      /************************************************************************
      *                                                                       *
      *                       (abBestFitIntercept wave)                       *
      *                                                                       *
      * Compute the intercept (alpha) of the best fit through a set of points *
      *                                                                       *
      ************************************************************************/
      (defglobalfun abBestFitIntercept (wave)
        (cond
          ((drIsWaveform wave)
           (car (abBestFitCoeffs wave))
           )
          ((famIsFamily wave)
           (famMap 'abBestFitIntercept wave)
           )
          (t
            (error "abBestFitIntercept: cannot handle %L\n" wave)
            )
          )
        )
      )
    
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abBestFit
      name abBestFit
      description "Best Fit Line"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave )
              signals (nil
                    wave (nil
                          prompt "Signal"
                          tooltip "Waveform"
                          )
               )
              params(nil
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abBestFitIntercept
      name abBestFitIntercept
      description "abBestFitIntercept"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave )
              signals (nil
                    wave (nil
                          prompt "Signal"
                          tooltip "Waveform"
                          )
               )
              params(nil
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abBestFitSlope
      name abBestFitSlope
      description "abBestFitSlope"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave )
              signals (nil
                    wave (nil
                          prompt "Signal"
                          tooltip "Waveform"
                          )
               )
              params(nil
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
  • vamshiky
    vamshiky over 7 years ago in reply to Andrew Beckett

    Thanks for the quick response Andrew, I shall try and get back.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • zeloufi
    zeloufi over 7 years ago in reply to Andrew Beckett

    Hello Andrew

    I use positively this function and it is great !
    Thank you very much !

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • vamshiky
    vamshiky over 7 years ago in reply to vamshiky

    Hi Andrew,

    Thanks this was very useful, cross checked with matlab as well.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • acrasso
    acrasso over 7 years ago in reply to Andrew Beckett

    Hi Andrew,

    Thank you for this post.  I have two questions related to this code.

    First, when  I use abBestFitCoeffs in the calculator I get an answer that says for example complex( 1, 2 ).  When I enter that into output setups as an expression it gives me an eval error.  I am guessing Explorer has trouble outputting the complex number?  In the calculator I can separate the numbers by doing real and imag on the value returned.  But again when I try to add that in as an expression the tool says that it says Error* real: can't handle real((1 2)).  Any hints on how to output a signal value for each the slope and the intersect when writing it in as an expression? Sorry if I am missing something basic.

    Second, anyway to expand this to higher orders easily?

    Thanks,

    Anthony

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 7 years ago in reply to acrasso

    Hi Anthony,

    The abBestFitCoeffs function isn't really intended to be used in the calculator. It returns a list of two numbers (the slope and the intercept), and the calculator and ADE outputs aren't really designed to receive a list. Rather oddly, the calculator converts the list of two values into a complex number (I wasn't expecting it to do that) - so instead if you need to retrieve the coefficients, I suggest you use:

    car(abBestFitCoeffs(wave))

    or

    cadr(abBestFitCoeffs(wave))

    as then you'll get a single number from each.

    Of course, you could write code to do a higher order polynomial fit, but that's more work (it's not just a trivial change to the code). You'd probably have to read up on how to do it... 

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • vamshiky
    vamshiky over 6 years ago in reply to vamshiky

    Hi Andrew,

    I was wondering if we can get end point fit with the same code.. probably with some minor modifications.

    Thanks,

    vamshiky

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 6 years ago in reply to vamshiky

    So you just want a line between the first and last points? That would be very easy (although it wouldn't need any of the existing best fit code because it's much simpler). Before I show you how, I want to make sure I've understood that this is what you meant...

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • vamshiky
    vamshiky over 6 years ago in reply to Andrew Beckett

    Yes I want a line between first and last points, so that I can find the deviation from this fitted straight line.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 6 years ago in reply to vamshiky

    I wouldn't call it a fitted line, but here's the code nevertheless. Was quite easy to throw together (it does bear some similarities with abBestFit, but it's considerably simpler as it doesn't need to do any linear regression).

    /* abFirstLastLine.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       May 16, 2018 
    Modified   
    By         
    
    Construct a line between first and last points in waveform.
    Not a best fit - just a simple line consisting of just the first
    and last points.
    
    Includes function template so this can be added to the calculator
    with the "fx" button in the calculator function panel.
    
    ***************************************************
    
    SCCS Info: @(#) abFirstLastLine.il 05/16/18.22:55:10 1.1
    
    */
    
    /*********************************************************************
    *                                                                    *
    *                       (abFirstLastLine wave)                       *
    *                                                                    *
    * Output a waveform which just contains the first and last points of *
    *                        the input waveform.                         *
    *                                                                    *
    *********************************************************************/
    (defun abFirstLastLine (wave)
      (cond
        ((drIsWaveform wave)
         (let (xVec yVec newXVec newYVec len newWave)
           (setq xVec (drGetWaveformXVec wave))
           (setq yVec (drGetWaveformYVec wave))
           (setq len (drVectorLength xVec))
           (setq newXVec (drCreateVec 'double 2))
           (setq newYVec (drCreateVec 'double 2))
           (drAddElem newXVec (drGetElem xVec 0))
           (drAddElem newXVec (drGetElem xVec (sub1 len)))
           (drAddElem newYVec (drGetElem yVec 0))
           (drAddElem newYVec (drGetElem yVec (sub1 len)))
           ;-----------------------------------------------------------------
           ; Sort out attributes for new waveform to match input
           ;-----------------------------------------------------------------
           (putpropq newXVec (getq xVec units) units)
           (putpropq newXVec (getq xVec name) name)
           (putpropq newYVec (getq yVec units) units)
           (putpropq newYVec (getq yVec name) name)
           (setq newWave (drCreateWaveform newXVec newYVec))
           (famSetExpr newWave `(abFirstLastLine ,(famGetExpr wave)))
           newWave
           )
         )
        ((famIsFamily wave)
         (famMap 'abFirstLastLine wave)
         )
        (t
          (error "abFirstLastLine: cannot handle %L\n" wave)
          )
        )
      )
    
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abFirstLastLine
      name abFirstLastLine
      description "Create line between first and last points"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave )
              signals (nil
                    wave (nil
                          prompt "Waveform"
                          tooltip "Waveform"
                          )
               )
              params(nil
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )
    

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • sjwprc
    sjwprc over 4 years ago in reply to Andrew Beckett

    Hi Andrew,

    I try to include this abBestFit.il to calculator. But I dont know why after adding the function, 5 different sub-functions are added

    -abBestFitCoeffs

    -computeCoeffs

    -mean

    -sampleCorrCoeff

    -uncorrectedStdde

    but not abBestFit. Do you know what is the reason? My cds vesion is IC618-64b 500.2

    BR

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information