# Tips for improving the quality of optical material fits

This section describes how to modify the automatically generated material fits of Sampled Data materials.

The Sampled data material model allows materials to be defined based on experimental n,k vs frequency data. However, the experimental data cannot be used directly in the simulation. Instead, an analytic material model based on the experimental data is automatically generated and will be used in the simulation. Before simulating, you should check the model (fit) with the Material Explorer. If the fit is not very good, some fitting parameters can be adjusted.

## Fit Parameters

### Fit tolerance

Tolerance specifies the target RMS error between the experimental data and the calculated model. The fitting routine attempts to find a model that gives an RMS error below the tolerance value. The fitting routine will use the fewest number of model coefficients that give an RMS error below the tolerance.

In most cases, setting the fit tolerance to zero is recommended, which means the fitting routines will select the best fit that can be found.

### Max coefficients

Max coefficients sets the maximum number of coefficients allowed in the model. More coefficients allow more complicated features to be fit, but at the expense of more memory and simulation time. The fitting routine will use the fewest number of coefficients that give an RMS error below the tolerance. If the RMS error cannot be achieved, then the model with the smallest RMS error will be used.

### Adjusting Max coefficients

By default, a Sampled data material has a tolerance of 0.1 and max coefficients of 6. In many cases, these are reasonable values. However, it is always a good practice to check the fit before running the simulation. Using excessive number of coefficients can result in the fitting being too sensitive to the noise present in the data, while having too few coefficients will result in significant errors in the fit. The following examples show an example of each case.

**Too few coefficients**

The left image is the fit of Pt (Platinum) with 4 coefficients; its rms error is 8.04. The right image uses 5 coefficients and the rms error is 3.67. The additional coefficient clearly improves the fit, as shown in the plots, and lowers the rms error value.

**Too many coefficients**

The left image is the fit of Ag (Silver) with 4 coefficients; its rms error is 0.14. The right image uses 7 coefficients and the rms error is 0.11.

In this case, even though more coefficients has lowered the rms error, the fit 'looks' worse due to the feature at 0.435 um. The material properties at this wavelength will have a large error when 7 coefficients are used. In this case, the 4 coefficient is probably the better fit.

### Advanced Settings

**imaginary weight**

Typically, the fitting routine gives equal weight to fitting the real and imaginary parts of the permittivity. Use the Imaginary weight parameter to give more or less weight (consideration) to the imaginary part of the permittivity. A value of 10 gives 10 times more consideration to the imaginary part, while 0.1 gives 10 times more consideration to the real part. This parameter is most useful when the real part is much larger or smaller than the imaginary part, and it is important to get a better fit to the smaller part.

**make fit passive**

The automatic fitting routine restricts the range of coefficients used in the material model so that the fit does not have any gain if the imported material data does not have gain. Uncheck 'make fit passive' to allow material models with gain. Take care using this option since even if you introduce gain far from the simulation bandwidth, it is possible to obtain diverging fields.

**improve stability**

Restrict the range of coefficients in the material model in order to minimize numerical instabilities which can cause simulations to diverge. By default, this is selected to make the simulation more stable. Unselecting this option might give a better fit, but the model is more likely to be unstable and the simulation might diverge. Reducing the dt stability factor can sometimes fix this type of divergence.

**specify fit range and Bandwidth range of fit**

Decouple the bandwidth used to generate the material fit from the source bandwidth. Use this option to specify the frequency/wavelength range to be used by the fitting algorithm, rather than using the frequency range of the source.

## Discontinuity and noise in experimental data

Noise or other errors in experimental data can make the automatic fitting difficult. In these cases, the fitting might be poor. One solution is to edit the data so that a reasonable fit can be generated. If the data was imported from a text file, simply edit your text file and import data again as if it were a new material. Otherwise, edit the data directly in the material database. If you intend to edit any of the predefined materials in the material database that came with the Lumerical Solutions installation, you have to make a copy of the original materials. The predefined materials cannot be changed. For more info, please visit Material Database and Creating sampled data materials.

### See also

Importing arbitrary dispersive models, Creating sampled data materials