• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Mixed-Signal Design
  3. straight line (best) fit using viva calculator

Stats

  • Locked Locked
  • Replies 18
  • Subscribers 64
  • Views 30635
  • 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
  • sjwprc
    sjwprc over 5 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
  • Andrew Beckett
    Andrew Beckett over 5 years ago in reply to sjwprc

    First of all, the code must have a .ils suffix, not .il because it relies on SKILL++ lexical scoping. I'm not sure whether you kept that (you referred to it as abBestFit.il). Secondly, I updated the code in the post above to a newer version that has the calculator registration functions included, so it should be straightforward to add, especially as you're adding it in a version that supports adding .ils files in the calculator (see the comments at the top of the new code).

    Andrew.

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

    hi Andrew, it works, thanks for your help!

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

    Hello Andrew,

    Is there a function that can be used to construct a line between two chosen points (not first and last points) in waveform? Or can this abFirstLastLine function choose the points to construct a line?

    Thanks,

    Hannah

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

    Hi Hannah,

    No, but it wouldn't be that hard to write one. Perhaps you can expand upon what you want though by answering these questions?

    1. How would you specify the two points that you want to construct the line to go through? Maybe by specifying two x values and then the function determines the y values at those points to decide the line?
    2. Would the line be extrapolated to the first x and last x value in the source waveform? (so in other words, it would have the same x-range as the source waveform, but would go through the points specified by two specific x values)

    That seems the most logical way to do it to me.

    Andrew 

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

    Hello Andrew,

    Thank you for replying to me.

    1.The endpoints fit line function (abFirstLastLine) chooses the first and last points of the input waveform. I am finding a way to draw a fit line of the source waveform with two endpoints different from the first and last points of the source waveform. This means I can choose two x values as the input of the function and set these two corresponding points as the endpoints of the line. 

    2. Yes, the line would have the same x-range as the source waveform, but would go through the points specified by two specific x values.

    Appreciate your help!

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

    Hannah,

    Try this. You can use the "fx" button in the function panel of the calculator, or the + button in the ADE Explorer/Assembler expression builder to add to the calculator.

    Regards,

    Andrew

    /* abLineThroughTwoPoints.il
    
    Author     A.D.Beckett
    Group      Custom IC (UK), Cadence Design Systems Ltd.
    Language   SKILL
    Date       Mar 23, 2021 
    Modified   
    By         
    
    Construct a line which passes through the y values at two specified
    x points on an input waveform, and has the same x-range as the
    input waveform.
    
    Includes function template so this can be added to the calculator
    with the "fx" button in the calculator function panel.
    
    ***************************************************
    
    SCCS Info: @(#) abLineThroughTwoPoints.il 03/23/21.20:07:57 1.1
    
    */
    
    /***************************************************************
    *                                                              *
    *             (abLineThroughTwoPoints wave x1 x2)              *
    *                                                              *
    *  Produce a waveform which intersects the original waveform   *
    * at two specified x values. The x-range of the result is the  *
    *                same as the original waveform.                *
    *                                                              *
    ***************************************************************/
    
    (defun abLineThroughTwoPoints (wave x1 x2)
      (cond
        ((drIsWaveform wave)
         (let (xVec yVec newXVec newYVec len newWave y1 y2 m c)
           ;-----------------------------------------------------------------
           ; Calculate slope and intercept from two points
           ;-----------------------------------------------------------------
           (setq y1 (value wave x1))
           (setq y2 (value wave x2))
           (if (equal x1 x2)
             (progn
               (setq m 0.0)
               (setq c y1))
             (progn
               (setq m (quotient (difference y2 y1) (difference x2 x1)))
               (setq c (difference y2 (times m x2)))
               ))
           (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 (plus (times (drGetElem xVec 0) m) c))
           (drAddElem newYVec (plus (times (drGetElem xVec (sub1 len)) m) c))
           ;-----------------------------------------------------------------
           ; 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 `(abLineThroughTwoPoints ,(famGetExpr wave)))
           newWave
           )
         )
        ((famIsFamily wave)
         (famMap 'abLineThroughTwoPoints wave x1 x2)
         )
        (t
          (error "abLineThroughTwoPoints: cannot handle %L\n" wave)
          )
        )
      )
    
    ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;; GUI builder information ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ocnmRegGUIBuilder(
     '(nil
      function abLineThroughTwoPoints
      name abLineThroughTwoPoints
      description "Generate line which intersects curve at two x values"
      category ("Custom Functions")
      analysis (nil
          general (nil
            args (wave x1 x2 )
              signals (nil
                    wave (nil
                          prompt "Waveform"
                          tooltip "Waveform"
                          )
               )
              params(nil
                     x1 (nil
                           prompt "X1"
                           tooltip "X1"
                           guiRowHint 1
                           type float
                           required t
                     )
                     x2 (nil
                           prompt "X2"
                           tooltip "X2"
                           guiRowHint 1
                           type float
                           required t
                     )
              )
            inputrange t
          )
      )
      outputs(result)
     )
    )
    

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

    Hello Andrew,

    I tried this function and it works! Thank you so much for your help!

    • 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