• 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. Custom IC SKILL
  3. Harmonic Parametric

Stats

  • Locked Locked
  • Replies 5
  • Subscribers 143
  • Views 14160
  • 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

Harmonic Parametric

AMSboston
AMSboston over 15 years ago

Hi,

Below is a SKILL  to find the Harmonic Frequency distortion level.

If I run a single simulation I get the correct answer.

 However, if I run a Parametric Sweep of VAR("fin") I get the following error:

*Error* round: argument #1 should be a number (type template = "n") - drwave:213939744.

 I get the error because "FreqN" is a vector.

How do I modify the script below such that it can handle a Parametric Sweep?

BTW, if freqN was a list or a vector I could make the code work with a foreach command.

However, freqN is not a list, nor is it a vector.

What is it?

####################################################################### 

procedure( CCSharmonicDistNEW( tranwave dftFrom dftTo numSample freqN freq0)
     let( (res dftwave newFreqN)
     dftwave = dft(tranwave,dftFrom ,dftTo,numSample,"Rectangular",1,1)
newFreqN=abs(round(freqN/250e6)*250e6-freqN)
     res = db20( mag(value(dftwave newFreqN))/mag(value(dftwave freq0)))
     res
)
)

 ocnPrint(CCSharmonicDistNEW(VT("/XQDCA/RECONSTRUCTED") 42.2n 298.2n 64 3*VAR("fin") VAR("fin")))
############################################################################################

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 15 years ago

    Note I have not tested this, but this is the approach normally taken:

    procedure( CCSharmonicDistNEW( tranwave dftFrom dftTo numSample freqN freq0)
      cond(
       ; handle ordinary waveforms
       (drIsWaveform(tranwave)
         let( (res dftwave newFreqN)
           dftwave = dft(tranwave,dftFrom ,dftTo,numSample,"Rectangular",1,1)
           newFreqN=abs(round(freqN/250e6)*250e6-freqN)
           res = db20( mag(value(dftwave newFreqN))/mag(value(dftwave freq0)))
           res
         )
       )
       ; and family waveforms
       (famIsFamily(tranwave)
         famMap('CCSharmonicDistNEW tranwave dftFrom dftTo numSample freqN freq0)
       )
       ; oh dear, help!
       (t
         error("CCSharmonicDistNEW - can't handle %L\n" tranwave)
       )
      )
    )
    

    The idea is that you use famMap to iterate over the family members (recursively) - hence the cond() to determine if the waveform is a family. As each family member is visited by famMap, it will call the function with the inner level, and do the same thing again, until it reaches a conventional waveform. Then as the famMap returns, it will collect all the results into families, and so on.

    There are a few examples of using this on Cadence Online Support.

    Regards,

    Andrew.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AMSboston
    AMSboston over 15 years ago
    Andrew,
    Thanks a lot for your help.
    I modified the code below to also recalculate newFreq0.
    When I do so I get the correct result.
    The purpose of this code is to find the HD of signals that are above Nyquist and therefore I had to recalculate freq0 & freqN.
    If you get a chance maybe you can explain the following:
    I actually don't understand the syntax of the solution.
    If the condition that it's a family is satisfied then famMap iterates over every Waveform in the family and calculates a newFreq, which it then applies to the DFT function.
    The syntax is confusing because famMap calls CCSharmonicDistNEW from within CCSharmonicDistNEW.
    How does it work? (I realize this may be a dumb question because it works by recursion, so maybe nothing needs to be said:)
    Thanks for your help!
    ##############################################################################
    procedure( CCSharmonicDistNEW( tranwave dftFrom dftTo numSample freqN freq0)
      cond(
       ; handle ordinary waveforms
       (drIsWaveform(tranwave)
         let( (res dftwave newFreqN newFreq0)
           dftwave = dft(tranwave,dftFrom ,dftTo,numSample,"Rectangular",1,1)
           newFreqN=abs(round(freqN/250e6)*250e6-freqN)
           newFreq0=abs(round(freq0/250e6)*250e6-freq0)
           res = db20( mag(value(dftwave newFreqN))/mag(value(dftwave newFreq0)))
           res
         )
       )
       ; and family waveforms
       (famIsFamily(tranwave)
        
         famMap('CCSharmonicDistNEW tranwave dftFrom dftTo numSample freqN freq0)
       )
       ; oh dear, help!
       (t
         error("CCSharmonicDistNEW - can't handle %L\n" tranwave)
       )
      )
    )
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 15 years ago
    Hi Dan,

    In pseudo code, famMap does:

    result=emptyFamily()
    foreach(familyMember tranwave
    indivResult=CCSharmonicDistNEW(familyMember dftFrom ...)
    addToFamily(result indivResult)
    )

    famMap essentially loops over the members of its second argument, calling the named function with all the specified arguments (but tranwave is replaced by the family member).

    So if you have a single dimensional family (a family of waveforms), it calls itself with each waveform in turn, and constructs either a waveform (if the result is a scalar) or a family (if the result is a wave).

    For families of families, it's going to peel one layer off at a time as it recursively calls the function with one fewer layer.

    Hope that helps to clarify it?

    Regards,

    Andrew
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 15 years ago
    Apologies for the lack of indenting - the perils of replying via email.

    Regards,

    Andrew
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AMSboston
    AMSboston over 15 years ago
    Andrew,
    Thanks.
    • 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