Post Go back to editing

Total Harmonic Distortion

Category: Software
Product Number: 24.1.10
Software Version: 24.1.10

Hello,
i have a question to .four 1k 10 -1 v(out).
In the log-file I can find 
Partial Harmonic Distortion: 4.335049%
Total Harmonic Distortion:   4.810931%
The Partial Harmonic Distortion match to result of 1+9 harmonic ( = sprt ((U2^2+...+U9^2)/(U1^2)).
But how can I calculate the Total Harmonic Distortion?
How is the Total Harmonic Distortion defined?

  • Hi  ,

    How is the Total Harmonic Distortion defined?

    It looks like the formula you have stated for PHD is the formula for THD. I will have to ask around. I would think to produce a true PHD, you would have to be able to specify the harmonics of interest.

    mike

  • Hello, mike

    I’m very interested in this topic. Even if we assume that PHD is calculated by collecting only the harmonics within the range specified in the .FOUR directive, I still cannot clearly understand what harmonic range is used for the THD value.

    It seems the discussion ended with “I will check / ask around,” but I would really like to know the exact definition used here.

    Best regards,
    denspa

  • Hi Mike,

    I'm still interested in the exact definition.

    BR Jens

  • Hi  ,  ,

    THD is calculated from Vrms of the signal. using:

    Interesting note: I went back to some older versions of LTspice that reported as thus:

    Total Harmonic Distortion: PHD value ( THD value )

    The THD was noted in parentheses for some reason.

    mike

  • Hello Mike,

    Thank you for your reply—understood.

    In this case, it seems to imply that if the observation interval (the .tran stop time) is not an integer multiple of the signal period (1/f), the result may not be calculated correctly. My reason is that when calculating V1rms, if the time window does not contain an integer number of cycles, the discontinuity of the fundamental waveform V1 at the window edges will spread energy into other frequency components (spectral leakage). This could be mitigated if a window function were applied, but since there is no mention of windowing, I assume no window function is used.

    For PHD, unless “-1” is used for the measurement time, it appears that LTspice performs the FFT on the last N cycles as specified in the .four directive. In that case, the extracted interval matches the intended period and should not have a discontinuity. Therefore, I think PHD can be calculated accurately as long as N full cycles are captured, regardless of the overall .tran duration.

    However, if THD implicitly uses the entire observation interval, then in order to obtain an accurate FFT of V1, is it correct that we should choose the observation interval (.tran stop time) so that it is an integer multiple of the signal period?

    Best regards,
    Denspa

  • Hi  , 

    In this case, it seems to imply that if the observation interval (the .tran stop time) is not an integer multiple of the signal period (1/f), the result may not be calculated correctly. My reason is that when calculating V1rms, if the time window does not contain an integer number of cycles,

    Well, yes and no. LTspice will do exactly what you tell it to do. As View FFT and .four are two different functions, let's start with .four, where I've set Nperiods to 10. 

    .four {fundamental} 40 10  V(sine) V(triangle):

    the result may not be calculated correctly

    Wll, "may not be calculated correctly" is debatable, as LTsice will do exactly what you tell it to do. To wit…

    I ran this simple test for N=10.33 in LTspice 17.1.9, (that version just 'cause I was testing something else) but with Nperiods set to -1 (see the help):

    In contrast, setting the .tran time to exactly 10 cycles:

    Using my handbuilt windowing function:

    However, if THD implicitly uses the entire observation interval, then in order to obtain an accurate FFT of V1, is it correct that we should choose the observation interval (.tran stop time) so that it is an integer multiple of the signal period?

    In short, no, yes, and "up to you". Turns out the actual FFT feature allows you to specify the interval after the fact:

    Circling back to the top of this message, Nperiods in the .four directive will not affect the FFT used in View FFT, but does affect the calculation of Vrms used to report THD in the log.

    Hope this helps.

    mike

  • Hello Mike,

    Thank you very much for your detailed explanation. I’m happy that we can discuss this topic.
    I understand that View FFT allows flexible and detailed analysis.

    There is a reason I’m focusing on the legacy .FOUR command. In situations like the following, the .FOUR output is a very quick and practical indicator:
    - When designing an audio power amplifier and wanting to see how distortion changes as component values are varied,
    it is easy and fast to check the numeric PHD/THD values written in the log.

    Ideally, I would even like to be able to output PHD/THD via a .meas command and plot them to observe trends.
    In the past I have had a few moments of “Hmm… is this THD correct?”, but I could not evaluate it properly enough to report it clearly.

    Since you proposed a very good evaluation approach, I reproduced it on my side.
    In short, I believe this comes down to evaluating the combinations of:
    - “.param N = 10.33” vs “.param N = 10”
    and
    - “.four {fundamental} 40 10 V(sine) V(triangle)” vs “.four {fundamental} 40 -1 V(sine) V(triangle)”

    I tested these combinations on both LTspice V17.0.37.0 and V26.0.1.

    I will not comment on small numerical differences due to analysis resolution, but even when compared against the formulas you provided earlier, there are still some puzzling results.

    In particular, in case (2) below, THD becomes 0. In that case, I cannot understand how THD can be lower than PHD. Is it possible that the expression under the square root becomes negative and therefore THD cannot be computed correctly?

    Aside from that point, the other cases look roughly as expected to me.

    -------------------------------------------------------------------
    (1).param N = 10.33 & .four {fundamental} 40 10 V(sine) V(triangle)
    -------------------------------------------------------------------
    V26.0.1 V(sine) V(triangle)
    Partial Harmonic Distortion: 0.000001% Partial Harmonic Distortion: 12.113810%
    Total Harmonic Distortion: 0.000232% Total Harmonic Distortion: 12.114862%

    V17.0.37.0 V(sine) V(triangle)
    Total Harmonic Distortion: 0.000004%(0.000000%) Total Harmonic Distortion: 12.114207%(12.115284%)

    -------------------------------------------------------------------
    (2).param N = 10.33 & .four {fundamental} 40 -1 V(sine) V(triangle)
    -------------------------------------------------------------------
    V26.0.1 V(sine) V(triangle)
    Partial Harmonic Distortion: 3.152041% Partial Harmonic Distortion: 12.480191%
    Total Harmonic Distortion: 0.000000% Total Harmonic Distortion: 14.705749%

    V17.0.37.0 V(sine) V(triangle)
    Total Harmonic Distortion: 3.168874%(0.000000%) Total Harmonic Distortion: 12.401012%(14.706091%)

    -------------------------------------------------------------------
    (3).param N = 10 & .four {fundamental} 40 10 V(sine) V(triangle)
    -------------------------------------------------------------------
    V26.0.1 V(sine) V(triangle)
    Partial Harmonic Distortion: 0.000001% Partial Harmonic Distortion: 12.113527%
    Total Harmonic Distortion: 0.000000% Total Harmonic Distortion: 12.114564%

    V17.0.37.0 V(sine) V(triangle)
    Total Harmonic Distortion: 0.000004%(0.000000%) Total Harmonic Distortion: 12.114208%(12.115285%)

    -------------------------------------------------------------------
    (4).param N = 10 & .four {fundamental} 40 -1 V(sine) V(triangle)
    -------------------------------------------------------------------
    V26.0.1 V(sine) V(triangle)
    Partial Harmonic Distortion: 0.000001% Partial Harmonic Distortion: 12.113527%
    Total Harmonic Distortion: 0.000000% Total Harmonic Distortion: 12.114564%

    V17.0.37.0 V(sine) V(triangle)
    Total Harmonic Distortion: 0.000004%(0.000000%) Total Harmonic Distortion: 12.114208%(12.115285%)

    Best regards,
    Denspafour_test.asc

  • Hello everyone,

    sorry for the late response.

    I did a simple test with simple amplifier.

    I masher the Amplitude of the FFT and calculate the THD (like mike)

    V(out)                                                                 

    1.(D11)                                2,721872V                       

    2.(D12)                                0,20990547V                  

    3.(D13)                                0,04764792V                  

    4.(D14)                                0,03441362V                  

    5.(D15)                                0,00174543V                  

    6.(D16)                                0,00485138V                  

    THD      0,08010669*100%=8,01066907

    EXCEL: =SQRT(D12^2+D13^2+D14^2+D15^2+D16^2)/D11

    And I use the “.four 1kHz v(in) v(out)” with results for:

    Partial Harmonic Distortion: 8.285432%

    Total Harmonic Distortion:   8.312824%

    I think the PHD is calculated by “mikes formula”.

    On this page :

    www.powerelectronicsnews.com/.../

    I find this information: “The result for all harmonics of the signals is also shown in brackets.” …old LTSPICE 16/17 log

    In a further source I read it’s in clouded the noise.

    How can I calculate the LTSPICE THD (…all harmonics and/ or with noise).

    This is for me the basic thing.

    I make the experience with different circuit.