# inldnl

Integral nonlinearity (INL) and differential nonlinearity (DNL) of data converters

## Description

calculates the integral nonlinearity (INL) and differential nonlinearity (DNL) errors of
ADCs and DACs. The function calculates INL and DNL using the analog and digital input output
data and the nominal analog dynamic range of the converter. The function can calculate INL
and DNL either using the endpoint method, or the best fit method, or using both
methods.`s`

= inldnl(`analog`

,`digital`

,`range`

,`type`

)

The `inldnl`

function only analyzes converters with a finite number
of bits. That means ADCs must have saturation and quantization. The function ignores any
digital value pairs that contain NaN values.

calculates the INL and DNL errors of ADCs and DACs using one or more name-value pair
arguments in addition to the input arguments in the previous syntax. Enclose each argument
name in quotes. Unspecified arguments take default values.`s`

= inldnl(___,Name,Value)

**Note**

Initial conditions and other anomalous data can cause this function to behave erratically. This function can analyze nonmonotonic converters, but it cannot handle multiple distinct occurrences of the same code in one transfer function.

## Examples

### Calculate INL and DNL of DAC

Load the digital input and the analog output of a DAC from MAT-files.

load 'digital.mat' load 'analog.mat'

The nominal analog dynamic range of the DAC is `[-1,1]`

. Turn on plotting for the output converter threshold. Calculate INL and DNL using both best fit and endpoint methods.

inldnl(a,d,[-1 1],'DAC','GenPlotData','on','INLMethod','All','DNLMethod','All')

`ans = `*struct with fields:*
Type: 'DAC'
NBits: 5
LSB: 0.0625
MissingCodes: [0x1 double]
Codes: [-16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 ... ]
IdealCodeCenters: [-1 -0.9375 -0.8750 -0.8125 -0.7500 -0.6875 ... ]
CodeCenters: [-0.9465 -0.8780 -0.8048 -0.7310 -0.6557 -0.5862 ... ]
CodeCenterStD: [0.0282 0.0292 0.0296 0.0287 0.0254 0.0237 0.0207 ... ]
EndpointINL: [1.7764e-15 0.0465 0.1679 0.2985 0.4547 0.5169 ... ]
BestFitINL: [-0.5244 -0.4713 -0.3432 -0.2060 -0.0432 0.0257 ... ]
EndpointDNL: [0.0465 0.1215 0.1305 0.1562 0.0623 0.0654 0.0331 ... ]
BestFitDNL: [0.0531 0.1281 0.1371 0.1628 0.0689 0.0720 0.0397 ... ]
BestFitPoly: [0.0652 0.1293]
OffsetError: 0.8562
GainError: 1.5393
GainErrorUnit: 'LSB'
TCNominal: [32x2 double]
TCMeasured: [32x2 double]

## Input Arguments

`analog`

— Analog input to or output from device

vector

If the device under test (DUT) is an ADC, analog input to the ADC, specified as a vector.

If the DUT is a DAC, analog output from the DAC, specified as a vector.

**Data Types: **`double`

`digital`

— Digital output from or input to device

integer vector

If the device under test (DUT) is an ADC, digital output from the ADC, specified as a vector of integers.

If the DUT is a DAC, digital input to the DAC, specified as a vector with integer values.

**Data Types: **`fi`

| `single`

| `double`

| `int8`

| `int16`

| `int32`

| `uint8`

| `uint16`

| `uint32`

`range`

— Nominal analog dynamic range of device

2-element vector

Nominal analog dynamic range of the ADC or DAC, specified as a 2-element vector.

**Data Types: **`double`

`type`

— Type of device

`Auto`

| `ADC`

| `DAC`

Type of the device under test, specified as `Auto`

,
`ADC`

, or `DAC`

. The `type`

determines whether to analyze the data as an ADC or DAC.

If The `type`

is set to `Auto`

and if the
transfer function is discrete, the `inldnl`

function analyzes the
data as a DAC. The transfer function is considered as discrete if the analog data is
less than half of the digital code width for each digital code.

If The `type`

is set to `Auto`

and if the
transfer function is continuous, the `inldnl`

function analyzes the
data as an ADC.

**Data Types: **`string`

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
the argument name and `Value`

is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

**Example: **```
inldnl(a,d,[-1 1],'DAC', 'INLMethod', 'All',
'DNLMethod','All')
```

calculates the INL and DNL of a DAC using both endpoint and
best fit method.

`OffsetErrorUnit`

— Unit of reported offset error

`LSB`

(default) | `%FS`

| `FS`

| `All`

Unit of reported offset error, specified as LSB (least significant bit), %FS (percentage full scale), FS (full scale), or all.

**Note**

The full scale range of the converter is defined as the difference between the last and first code on the +0.5 LSB compensated transfer curve. In a +0.5 LSB compensated transfer curve, first code is 0.5 LSB wide while the last code is 1.5 LSB wide. The input values must be considered within the full scale range of the converter.

**Note**

LSB is calculated by the equation $$\text{LSB=}\frac{\text{Fullscalerangeofconverter}}{{2}^{Nbits}}$$.

**Data Types: **`string`

`GainErrorUnit`

— Unit of reported gain error

`LSB`

(default) | `%FS`

| `FS`

| `All`

Unit of reported gain error, specified as LSB (least significant bit), %FS (percentage full scale), FS (full scale), or all.

**Note**

The full scale range of the converter is defined as the difference between the last and first code on the +0.5 LSB compensated transfer curve. In a +0.5 LSB compensated transfer curve, first code is 0.5 LSB wide while the last code is 1.5 LSB wide. The input values must be considered within the full scale range of the converter.

**Note**

LSB is calculated by the equation $$\text{LSB=}\frac{\text{Fullscalerangeofconverter}}{{2}^{Nbits}}$$.

**Data Types: **`string`

`GenPlotData`

— Send output data vectors to output data structure

off (default) | on

Send the output data vectors of the `inldnl`

function to the
output data structure `s`

, specified as `off`

or
`on`

. If `GenPlotData`

is set to
`on`

, the output data structure contains the output data vectors.
The output data vectors can then be picked up by the DAC DC
measurement, DAC
Testbench, ADC DC
Measurement, or ADC
Testbench blocks to plot the DC analysis results.

**Data Types: **`string`

`INLMethod`

— Method to calculate INL

`Endpoint`

(default) | `BestFit`

| `All`

Method to calculate INL, specified as `Endpoint`

,
`BestFit`

, or `All`

.

If

`INLMethod`

is set to`Enpoint`

, the`inldnl`

function compares each threshold's position to the threshold position of an ideal converter, as determined by a line from the first code transition to the last code transition.If

`INLMethod`

is set to`BestFit`

, the`inldnl`

function first takes the best linear fit of the ADC or DAC transfer curve. Then the function proceeds to calculate the INL using the same steps as the`Enpoint`

method.

**Data Types: **`string`

`DNLMethod`

— Method to calculate DNL

`Endpoint`

(default) | `BestFit`

| `All`

Method to calculate DNL, specified as `Endpoint`

,
`BestFit`

, or `All`

.

If

`DNLMethod`

is set to`Enpoint`

, the`inldnl`

function compares each threshold's position to the threshold position of an ideal converter, as determined by a line from the first code transition to the last code transition to find the INL. The DNL is calculated from the difference between the elements of the INL vector.If

`DNLMethod`

is set to`BestFit`

, the`inldnl`

function first takes the best linear fit of the ADC or DAC transfer curve. Then the function proceeds to calculate the DNL using the same steps as the`Enpoint`

method.

**Data Types: **`string`

`AbsoluteError`

— Return absolute error and full scale DNL for testing

off (default) | on

Return absolute error and full scale DNL for testing, specified as
`on`

or `off`

. Absolute error is the total
uncompensated error including offset error, gain error, and nonlinearities. In
simulation, to specifically test that the measurements match the impairments, absolute
error can be used instead of INL. This is because absolute error describes the entire
transfer curve in a single vector.

**Data Types: **`string`

## Output Arguments

`s`

— Output device information

structure

Output information of the `inldnl`

function, returned as a
structure. The output contains information about the device under test in these
fields:

Name | Values | Description | Data Types |
---|---|---|---|

Type | `ADC` or `DAC` | Type of the device under test (DUT) | string |

Nbits | positive real integer | Resolution of the ADC or DAC DUT | double |

LSB | positive real scalar | Least significant bit value of the DUT. LSB is the smallest level the ADC can convert or the smallest increment of the DAC output. | double |

MissingCodes | vector | Missing codes in DUT. | double |

Codes | column vector | Digital code | double |

IdealCodeCenters | column vector | Ideal code center of the digital code | double |

CodeCenters | column vector | Calculated code center of the digital code | double |

CodeCenterStD | column vector | Standard deviation of the code center from the ideal value | double |

EndpointINL | column vector | INL using `Endpoint` method | double |

BestFitINL | column vector | INL using `BestFit` method | double |

EndPointDNL | column vector | DNL using `Endpoint` method | double |

BestFitDNL | column vector | DNL using `BestFit` method | double |

BestFitPoly | vector | Polynomial describing the best fit using standard curve-fitting technique. | double |

OffsetError | real scalar | Offset error of DUT | double |

GainError | real scalar | Gain error of DUT | double |

OffsetErrorUnit | `LSB` , `%FS` , or
`FS` | Unit of reported offset error | string |

GainErrorUnit | `LSB` , `%FS` , or
`FS` | Unit of reported gain error | string |

TCNominal | vector | Nominal transfer curve of the DUT | double |

TCMeasured | vector | Measured transfer curve of the DUT | double |

If you do not assign an output variable, the `inldnl`

function
also plots the transfer function of the device under test in the active figure.

**Data Types: **`struct`

## More About

### Offset Error

Offset error represents the offset of the data converter transfer function curve from it ideal value at a single point. For more information, see Measuring Offset and Gain Errors in ADC.

### Gain Error

Gain error represents the deviation of the slope of the data converter transfer function curve from its ideal value. For more information, see Measuring Offset and Gain Errors in ADC.

### INL Error

Integral nonlinearity (INL) error, also termed as relative accuracy, is the maximum deviation of the measured transfer function from a straight line. The straight line can either be a best fit using standard curve-fitting technique, or be drawn between the endpoints of the actual transfer function after gain adjustment.

The best fit method gives a better prediction of distortion in AC applications, and a lower value of linearity error. The endpoint method is mostly used in the measurement applications of data converters, since the error budget depends on actual deviation from the ideal transfer function.

### DNL Error

Differential nonlinearity (DNL) is the deviation from the ideal difference (1 LSB) between analog input levels that trigger any two successive digital output levels. The DNL error is the maximum value of DNL found at any transition.

## Version History

**Introduced in R2020a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)