• 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 Design
  3. Different THD Results Using thd() function in Calculator...

Stats

  • Replies 6
  • Subscribers 125
  • Views 1110
  • Members are here 0

Different THD Results Using thd() function in Calculator and Spectrum in Viva

Kenny Lu
Kenny Lu 2 months ago

Dear all,

     I am currently running transient simulations for my circuit and would like to calculate the total harmonic distortion of the circuit. 

     My spectre version is 23.1.0.362.isr5, and I ran the simulation using SpectreX -CX.

     Fig. 1 is the DFT result.  The circuit has a third harmonic distortion of about -100.8 dB.

     I performed THD calculations via two different approaches. 

   

     Approach 1:

     I calculate the THD result using the thd() function in Calculator, and the result is shown in Fig. 2. 

    Approach 2:

    I calculate the THD result using "spectrum" in Viva. The settings and the THD result are shown in Fig. 3. 

Fig. 1. DFT Result

Fig. 2 THD Result using thd() in Calculator.

dB20(thd(VT("/VO_LPF") 754.7973u 2.088131m 8192 5250 ) / 100) = -73.99 dB

 

Fig. 3 THD Result using spectrum in Viva. 

It seems like I can't post the image of my setup here. I will just write down the expression generated from Spectrum.

spectrumMeasurement(VT("/VO_LPF") t 0.0007547973 0.002088131 8192 20 20000 3 "Hanning" 0.0 0 200 "thddb") = -96.69 dB

The two results are vastly different for the same circuit and setup.

Approach 1 gave me -74 dB, while Approach 2 gave me -96 dB. I couldn't think of the reason why this was the case. Could you please help me out?

Thank you very much

  • Sign in to reply
  • Cancel
  • Andrew Beckett
    Andrew Beckett 2 months ago

    It's hard to know for certain without seeing the raw data. One key difference is that both the DFT and spectrumMeasurement are using a window, whereas the thd function does not (so it's like using a rectangular window). It might be that the signal is not perfectly periodic or the small difference between the time interval and the fundamental you've given is not exact (it's approximately 7 periods by the looks of things).

    Would it be possible to plot the signal VT("/VO_LPF") in ViVA, select the trace and use Right Mouse->Send To->Export and then export this as PSFXL (you'll need to give a name - e..g VO_LPF - and then it will save as VO_LPF.psfxl as a directory). Then use "tar cfz VO_LPF.tar.gz VO_LPF.psfxl" and then upload the gzipped tarball here? You're only going to be sharing a single signal, but it would be enough for me to experiment with the data and understand what is going on.

    Thanks,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Kenny Lu
    Kenny Lu 2 months ago in reply to Andrew Beckett

    Hi Andrew,

    Thank you very much for your reply. Unfortunately, I can't get the data out from the server since that is prohibited by the provider.

    However, I will try my best to provide you with information you need for investigation.

    As for the input signal, I set it to a frequency of 5.25kHz and the number of cycles I used in the analyzes above is 7. The number of samples is 8192, and the sampling frequency is 6.144 MHz.

    For the first suggestion, I have tried to use a rectangular window in the spectrumMeasurement. This is the result I acquired.

    THD = -96.66 dB (Not much different from that using Hanning)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Andrew Beckett
    Andrew Beckett 2 months ago in reply to Kenny Lu

    I just noticed that your spectrumMeasurement is only looking at the frequencies between 20Hz and 20kHz, and so you're only going to be considering the 3rd harmonic in the THD calculation that way. Looking at your spectrum, there's quite a lot of harmonics at higher frequencies which are significant. thd() will be including all of them, and spectrumMeasurement is filtering many of those. A combination of the 200 argument (for number of harmonics) and the max frequency would make a difference. Maybe set the max frequency to 3M and harmonics to 670 or something like that and compare.

    Of course, it depends whether you want to exclude those upper harmonics in the THD calculation or not.

    I created a simple squarish waveform and I was getting this:

    dB20(thd(v("LPF_OUT" ?result "tran-tran") 754.7973u 2.088131m 8192 5250 )/100)
    -11.93797

    spectrumMeasurement(v("LPF_OUT" ?result "tran-tran") t 0.0007547973 0.002088131 8192 20 20000 3 "Hanning" 0 0 670 ?measType "thddb" )
    -12.2854

    (not such a noticeable difference, but my harmonics tail off fairly quickly). If I instead run:

    spectrumMeasurement(v("LPF_OUT" ?result "tran-tran") t 0.0007547973 0.002088131 8192 20 3M 3 "Hanning" 0 0 670 ?measType "thddb" )
    -11.93797

    Regards,

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Kenny Lu
    Kenny Lu 2 months ago in reply to Andrew Beckett

    Hi Andrew

    After I set the range (750Hz ~ 3.072MHz), number of harmonics = 585, the THD value went down to -82.48 dB, getting close to that acquired using thd().  I think this is the main reason why I observed the huge difference between the two methods.

    Can I please ask three more questions regarding the settings?

    1. I noticed that the start/end freq field has a suggested value (in my case it is suggested 750:3.072M). The value corresponds to the plotted frequency range of the dft spectrum. Is it correct to say that setting the start/end freq is telling the spectrumMeasurement tool that I would like to consider my analysis of the dft spectrum in this frequency range?

    2. I notice that the number of harmonics can be set up to 1024, corresponding to a frequency of 5250*1024 = 5.376MHz. This is outside of half of sampling frequency (6.144M / 2 =3.072 MHz). Should I simply consider 585 harmonics instead (5250*585 = 3.071 MHz)?

    3. Is it correct to say that if max freq (end freq) doesn't cover the number of harmonics specified (for example max freq = 20K, num of harmonics = 20 --> 5250 * 20 = 105kHz), the actual measurement only convers num of harmonics = 3 (5250*3 = 15.75kHz)? As a result, num of harmonics settings should correspond to start/end freq settings.

    Thank you very much

    Kenny Lu

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Andrew Beckett
    Andrew Beckett 2 months ago in reply to Kenny Lu
    1. Yes
    2. It doesn't really matter if you go above nSamples/2/7 (not sure where the 670 came from in my previous post - I think my back-of-envelope calculations were wrong at the time!) because there's nothing there in the dft results for it to sum anyway. At least in my case it made no difference. However, I guess it makes no sense to go above half the 
    3. Yes
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Kenny Lu
    Kenny Lu 2 months ago in reply to Andrew Beckett

    Hi Andrew,

         Thank you very much for your help.

         

         I sincerely appreciate it.  

    Kenny Lu

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • 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