# How to plot/find DNL and INL of a comparator?

#### hsnakejindal

Joined Jan 16, 2024
14

I drew this circuit in LTSpice. I want to find DNL (Differential Non linearity), INL (integral non linearity) and THD ( Total Harmonic Distortion ) of the circuit. Please Help me. Its very urgent!!

#### Papabravo

Joined Feb 24, 2006
21,225
View attachment 312868
I drew this circuit in LTSpice. I want to find DNL (Differential Non linearity), INL (integral non linearity) and THD ( Total Harmonic Distortion ) of the circuit. Please Help me. Its very urgent!!
I'm not sure it makes any sense to talk about DNL and INL for a device whose outputs are continuous. It makes more sense in the case of an A/D converter where there is a discrete step size and things are not continuous. For THD you do a Fourier Analysis (.four) and take the ratio of the harmonic components to the fundamental components.

#### hsnakejindal

Joined Jan 16, 2024
14
I'm not sure it makes any sense to talk about DNL and INL for a device whose outputs are continuous. It makes more sense in the case of an A/D converter where there is a discrete step size and things are not continuous. For THD you do a Fourier Analysis (.four) and take the ratio of the harmonic components to the fundamental components.
Can you please elaborate about THD, when I plot an FFT, a graph is coming out. How to find out Harmonic components?

Or what should I write in spice directive to get it?
Also do you know how to find the offset voltage of this circuit?

#### hsnakejindal

Joined Jan 16, 2024
14
I'm not sure it makes any sense to talk about DNL and INL for a device whose outputs are continuous. It makes more sense in the case of an A/D converter where there is a discrete step size and things are not continuous. For THD you do a Fourier Analysis (.four) and take the ratio of the harmonic components to the fundamental components.
how to find thd?

#### Papabravo

Joined Feb 24, 2006
21,225
how to find thd?
1. Go to the LTspice Help pages
2. Look up the Fourier Analysis command. It would be .four
4. When the simulation is complete, you will find the results in the SPICE Error Log
5. The SPICE Error Log can be shown via menu commands View | SPICE Error Log or using the keyboard shortcut Ctrl+L
6. See the image below

#### hsnakejindal

Joined Jan 16, 2024
14
1. Go to the LTspice Help pages
2. Look up the Fourier Analysis command. It would be .four
4. When the simulation is complete, you will find the results in the SPICE Error Log
5. The SPICE Error Log can be shown via menu commands View | SPICE Error Log or using the keyboard shortcut Ctrl+L
6. See the image below
View attachment 313324
I am getting the THD as 74.146324%(49146395638540.664000%). what does the number under the bracket signify? Also what is the generally acceptable range?

#### Papabravo

Joined Feb 24, 2006
21,225
I am getting the THD as 74.146324%(49146395638540.664000%). what does the number under the bracket signify? Also what is the generally acceptable range?
Since I cannot see what you are doing, I can't very well comment on the results. IIRC correctly THD looks at the magnitude of the fundamental Fourier component (NOT the DC component) with respect to the sum of the magnitudes of all the harmonic components from the 2nd out to infinity. In practice we satisfy ourselves with some finite number of harmonics so that the remaining components do not contribute much to the result. I believe the number of harmonics used is 9 unless you specify otherwise. A larger THD means the magnitudes of the harmonic components is large relative to the magnitude of the fundamental. There are two ways of looking at magnitude: absolute and normalized. At least that is what I think is going on in the example I posted. I have no idea what your seemingly incongruous numbers mean.

#### Papabravo

Joined Feb 24, 2006
21,225
Here is a spreadsheet check of the THD calculations in my example. The discrepancy comes from taking the displayed values instead of their cousins with more significant digits.

You can see that the results should be the same and for my example they are.