Published LED SPICE models are limited in numbers and often difficult to find. LED engineers may need to create their own models for specific part numbers to use as loads in more complex SPICE simulations. This process requires fitting the forward bias characteristics of the diode: Series Resistance (RS), Saturation Current (IS), and the Ideality Factor (N).
The figure below shows modeled SPICE output for the Luminus CBM-90-IR LED.
This plot demonstrates a high quality fit and illustrates how changing the N and RS parameters affects the shape of the curve. Manually fitting these interdependent parameters is a time consuming trial and error process. Because changing N or RS shifts the entire curve, you normally have to manually readjust IS to keep the model aligned with the source data.
This article introduces a Python script that automates the IS adjustment. By forcing the curve through a specific data point, the script keeps the model aligned with the target data as you modify the curve shape. This eliminates the separation between the generated curve and the target data that usually occurs during manual fitting.
This automated approach allows for fast and robust parameter extraction from either lab measured current-voltage (IV) data or data pulled from datasheet plots. It works for virtually any LED or laser diode. For engineers modeling series-parallel LED arrays, this tool can also generate a set of slightly varied models to realistically evaluate the impact of current mismatch between strings.
This article describes how to use Python® to automate the fitting of SPICE diode parameters to measured current-voltage (IV) data or data extracted from datasheet plots. This provides a robust, fast method to develop a SPICE model for virtually any LED or laser diode. Additionally, when modeling a series-parallel array of LEDs, this program can be used to generate a set of slightly different models to more realistically evaluate current mismatch effects.
This article is divided into two major sections: Section 1 discusses how to use the Python program, including tips for efficient data analysis and general theory. Section 2 provides an overview of the actual code package.
This code was developed using LTspice® 24.1.10 for Windows® - the macOS® version of LTspice does not work due to fundamental differences in the way intermediate files are created in macOS.
Section 1. Automated Curve Fitting Background and Methods
The Traditional Problem: Manual Curve Fitting
A previous help center article outlines a manual, trial-and-error process in LTspice for extracting SPICE IV parameters. While functional, this method is very time-consuming to set up and perform, giving it limited utility for more than occasional components.
The Automated Solution: Python & PyLTspice
The PyLTspice library (version 5.4.5) allows you to run LTspice as a background process and collect simulation results directly for analysis in Python. This capability simplifies and expedites the process of fitting diode models to measured data points by automating the simulation loop. The methods demonstrated in this script provide a foundation that can be expanded to solve a wide array of other complex LED engineering calculations.
The script discussed in this article is available upon request. To receive a copy, please send an email to techsupport@luminus.com.
Deep Dive: The SPICE Diode Model
The SPICE directive syntax for a simple diode model describing the IV curve in forward bias is:
.model LED-1 D(IS={IS_optimized} RS={RS} N={N} Tnom=27)
The model name is LED-1. The brackets { } indicate variable assignments used by the optimization code. The parameters inside of the D(...) statement are:
- IS – Saturation Current (A): IS primarily affects the voltage of the curve. This program optimizes IS to match a specified point in the IV data set when RS and N are set by the user.
- RS – Series Resistance (Ω): RS has the strongest effect in the high-current region of the IV curve, influencing the slope and overall voltage of that part of the curve. The user sets this value before running the optimization.
- N – Ideality Factor (Dimensionless): N controls the curve shape and the curvature in the knee (sharp knee for small N, soft knee for large N). The user sets this value before running the optimization.
- Tnom – Nominal Temperature (°C): This is the temperature SPICE uses as the basis for the model. 27°C is the default value and should be explicitly specified (Tnom=27) for models developed using this code. Specifying 27°C prevents SPICE from applying an unwanted temperature correction to the diode curve, thus ensuring the model simulates exactly as fitted, regardless of the temperature at which the IV data was originally collected. Advanced modeling involving temperature-dependent parameters is beyond the scope of this article.
SPICE uses a simplified Shockley Diode Equation for voltage sweeps.
Where the new terms in this equation are listed below and the previously defined SPICE parameters are bolded.
Id = Diode current (A)
q = Electronic charge (1.6022e-19 C)
Vd = Applied diode voltage (V)
k = Boltzmann’s constant (1.3806e-23 J/K)
T = Temperature (K) (The Tnom SPICE parameter uses °C -- This equation uses Kelvin)
A circuit schematic of the LED voltage sweep model used by the Python script is shown below. Note that the LED in this schematic must be named the same name as the model definition which is stored in a text file named LED_1s_1p.sub.
Circuit schematic used for this simulation.
SPICE uses default model values for any parameters not explicitly defined in the model directive. These defaults are typically based on historical silicon diode characteristics. The following table lists the most common SPICE parameters and their default values for reference. While this article focuses on the three forward diode sweep parameters (IS, RS, and N), it is important to note that performing frequency or temperature analyses without defining specific values will lead to highly inaccurate results as the simulation will revert to standard silicon defaults.
Interpreting the Results: N, RS, and Curve Shape
The figure below is adapted from a closed-form approximation method [Kielkowski] for calculating N, IS, and RS. While this method serves as an excellent starting point, the resulting SPICE model often requires refinement when compared against measured test data to achieve a high-fidelity match.
Diodes exhibit distinct operating regimes at different current levels.
- Low-Current Region: At the lowest currents, before the space charge is fully developed in the p-n junction, the diode behavior is dominated by shunt conductance, often approximated by Ohm's Law.
- Transition Region: Following the shunt region is a transition where the space charge begins developing, typically following a power law.
- Exponential/Turn-On Region: Next, the diode effectively "turns on," entering the exponential region (which appears linear on a semi-log plot) that spans multiple decades of current. This point generally corresponds to the onset of light emission in an LED.
- High-Current Region: The final regime is where the Series Resistance (RS) has an appreciable contribution to the IV curve shape, causing the voltage to rise faster than the exponential model predicts. On a semi-log plot, such as the one shown below, this effect is known as series rollover.
Series parallel simulations
The figure below is an example of a series-parallel LED circuit, specifically a three-series, three-parallel (3s3p) configuration. The individual IV characteristics of each LED are what ultimately determine the current distribution across the parallel strings (I1 ≠ I2 ≠ I3). This current distribution occurs as the voltage drop across the series LEDs in each string must sum to the source voltage.
To model current mismatch in this type of circuit, each LED needs a slightly different set of model parameters. This can be accomplished in two primary ways: by measuring and fitting a sample of the LEDs and placing them in the circuit randomly, or by simulating the mismatch using slight variations of parameters developed from a single measurement or datasheet curve.
Luminus generally recommends using the same Vf bin in this type of circuit to minimize current hogging effects. The specific voltage at the binning current calculated by this program is thus crucial for developing a reasonable population of models to select from.
While the full methodology is beyond the scope of this article, we have developed advanced Python-based Monte-Carlo scripts to model very large series-parallel LED circuits. These scripts leverage SPICE automation to calculate current mismatch and then use pure Python to process the individual LED's lumen vs. current data, thereby calculating the total lumen output of the array.
Case Study: Fitting a Model to a Measured Luminus CBM-90-IR LED
The following figure shows the program output, illustrating a high-fidelity fit to the IV data for a
Luminus CBM-90-X33-K940 Infrared LED, measured at 27°C. The rated operating current range for this LED
is 200 mA to 18 A, and our primary goal is to achieve an accurate fit within this range.
Good fit to the IV data in the specified operating range of the CBM-90-IR LED.
The divergence seen at low currents results from the simplicity of the three-parameter SPICE diode model. A more complicated sub-circuit model, often including a shunt resistance, would be needed to fit all the data points across the full range. The key takeaway is that this method easily generates a high-quality IV model for forward bias within the rated current range of the LED, which is typically the most critical region for LED engineers. (For more discussion on shunt resistance, see our article: “Data Analysis - Using Python to run LTspice as a remote process.”)
The Python code uses user assigned inputs for N and RS and then fits the IS value such that the curve passes through the designated test point specified in the LED datasheet (e.g., 13.5 A in this case). The voltage does not need to be precisely measured at this current, as the program automatically interpolates the required value from the input data.
Selecting the optimal values for N and RS is an iterative process that requires some practice. The workflow is to incrementally adjust these two shape parameters until the resulting SPICE curve closely matches the data after the program runs the IS optimization. The major advantage of this automation is that the model is guaranteed to pass through the designated test point. When performed manually, finding the N and RS values that match the curve shape, and then repeatedly finding the corresponding IS value to shift the curve onto the data, is extremely time consuming. By automating the IS optimization, the process becomes a significant time-saver.
The parameters N and RS control the shape of the curve, while IS primarily shifts the overall voltage level. As previously shown, N controls the curvature in the knee of the IV curve (large N = soft knee; small N = sharp knee). While older literature suggested N ranges from 1 to 2, this is often inapplicable for modern, quantum-well-based LEDs; the focus must remain on achieving the best fit to the empirical data. The following plots demonstrate the impact of varying N and RS by showing examples of "mismatched" or suboptimal fits.
N Examples: Varying the Ideality Factor
The following Python plots illustrate four examples of fits where the Ideality Factor (N) has been intentionally changed from the optimal value—two examples use an N value smaller than the best fit, and two use an N value larger.
Analysis of N=1 (Sharp Knee):
The plots above clearly demonstrates the effect of a low N value: a sharper knee in the IV curve. As N shifts the curve's overall voltage, the program's automation adjusts IS to compensate, ensuring the IV curve (blue trace) still passes through the designated test point.
The change in slope near 1.5V in the measured data (red points) corresponds to the transition point where the diode turns on and the LED begins to emit light. At lower voltages, the device operates in the shunt regime, where the LED is primarily responsive to shunt resistance. The simulated trace (blue) showing current flow at these low voltages is due to the small shunt conductance that SPICE automatically applies to prevent convergence issues.
The change in slope near 2.6V is the region where Series Resistance (RS) begins to have a stronger effect on the IV curve relative to IS and N. This is known as the series rollover point.
Extreme Example: N = 0.5.
This is an unusually low N value, unlikely to occur in a real device. It is included here to demonstrate the program’s convergence limits. Note the corresponding calculated IS value of 5.5e-91A, which is equally non-physical. SPICE is a highly effective mathematical network solver but does not validate the physics of solutions. You must always verify that the resulting model parameters are physically meaningful.
Analysis of N=4 (Soft Knee):
These plots illustrate that a large N value results in a soft knee in the IV curve, smoothing the transition from the low-current to the high-current region.
Extreme Example: N = 10.
While this is a very high N value for this device, high N values are not always a "bad fit." Some complex LED packages, such as Chip-on-Board (COBs), which are series-parallel arrays of many individual chips, can exhibit a very soft knee and usually need fitting using high N values. We will show a COB example below.
RS Examples: Varying the Series Resistance
The following plots illustrate three examples of fits where the Series Resistance (RS) has been intentionally changed from the optimal value. When manually seeking the best fit, it is highly recommended to first rough in a slope match to the data at the higher current levels (where RS dominates) and then iteratively refine the fit by adjusting N and RS. Note how the N variation samples above (which used the best-fit RS) showed strong divergence only around the IV curve's knee, confirming that the high-current slope was well-matched.
Analysis of RS = 0.06 Ω:
As shown in the plots above, this RS value is higher than the optimal fit. As a result, the series resistance roll-over occurs at a lower voltage and creates a shallower slope in the high-current region compared to the measured data in the standard IV curve on the right.
Analysis of RS = 0.01 Ω:
As shown in the plots above, this value is lower than the optimal fit. The simulated curve is too steep at higher currents.
Analysis of RS = 0.0025 Ω:
As shown in the plots above, this value is significantly lower than the optimal fit. The simulated curve is even steeper at high currents. Additionally, the unmodified voltage sweep produces a nearly 140 A current.
Case Study: CVM-53 – Large format COB.
To demonstrate a case where a significantly large N value is required, we digitized the IV data from the Luminus CVM-53 datasheet and used the Python script to extract SPICE parameters. This COB contains a large series-parallel array of small LED chips and we found that N = 75 and RS = 0.75Ω gives a matching curve shape with a plausible IS value of 2.6e-18A.
Good fit to CVM-53 datasheet IV data.
This result also implies that an LED engineer can use IV data measured directly from a luminaire (not just a single LED component) if that is the final system being modeled.
Section 2. Summary of the “IV_Curve_Fit_Automated.py” Program Components
This program functions by combining LTspice simulation files with a Python script. The SPICE circuit used is shown below. In LTspice, this circuit is defined by an .asc file, created using the LTspice schematic editor. Our example file is named LED_1s_1p.asc.
Screenshot of LED_1s_1p.asc from the LTspice editor (repeated for convenience).
The diode model itself is stored in a separate text file named LED_1s_10.sub. This separate file is crucial as it allows the Python script to easily and iteratively modify the model parameters (IS, RS, N). While the .asc file is also text, direct modification is not recommended, as the file contains graphical data describing the circuit image. When LTspice (Windows version) runs a simulation, it generates a .net file, which contains the precise commands and netlist used by the simulator. The automated curve fitting method modifies the .sub file to update the diode parameters and modifies the .net file to change the voltage sweep limits for each iteration. The macOS version of LTspice does not create a net file so the PyLTspice net file commands do not work.
In general, a library file, such as LED_1s_10.sub, can contain multiple model definitions as long as they have unique names. It is common practice to put all the component definitions in one text file for each SPICE project. The .lib command specifies that the file name that follows contains model definitions. This is best placed in the same directory as the .asc file and Python script to encapsulate different projects.
A general description of the Python code package follows.
Executive Summary
This Python tool speeds up development of SPICE diode model parameters (IS, N, RS) from measured LED I-V data using an iterative bisection method with LTspice simulation. It eliminates manual trial-and-error curve fitting by automatically optimizing the saturation current (IS) parameter to match a specified binning current point. User tests indicate that this code works for the Windows version of LTspice but not the macOS version of LTspice.
Purpose
- Automate SPICE model parameter extraction from LED test data
- Match simulated I-V curves to measured data at a specific operating point (binning current)
- Generate publication-quality plots comparing measured vs. simulated characteristics
- Provide detailed iteration history and convergence diagnostics
Key Features
1. Automated IS Parameter Optimization
- Uses bisection method for robust convergence
- Employs decade search to quickly bracket solutions across many orders of magnitude (handles IS values from ~1e-7 to <1e-90)
- Achieves sub-millivolt accuracy (default: 1 mV tolerance)
- Automatic bracket expansion if initial bounds fail
2. Input Requirements
- Microsoft Excel® file containing measured I-V data (columns: 'If', 'Vf')
- User-specified parameters:
- `N`: Ideality factor (manually specified)
- `RS`: Series resistance (manually specified)
- `IS_initial_guess`: Starting point for saturation current
- `binning_current`: Target operating point for voltage matching
Convergence criterion (default: 1 mV) `voltage_tolerance`
User input section in the code
3. LTspice Integration
- Automatically generates `.sub` model files for each input N and RS
- Adjustable voltage sweep from 0 to ’voltage_sweep’
- Runs parametric DC sweeps via the PyLTspice library
- Extracts simulation results for comparison
4. Algorithm Stages
Stage 1: Initial Bounds (Decade Search)
- Tests initial guess
- Searches by orders of magnitude (±decades) until bracket found
- Handles extreme IS ranges (up to 100 decades)
Stage 2: Decade Narrowing
- Tests each intermediate decade between bounds
- Narrows interval to <2 orders of magnitude
Stage 3: Bisection Refinement
- Iteratively halves the interval
- Converges to sub-mV accuracy
- Auto-expands if bracket fails
5. Outputs
- Console:
Real-time progress for each iteration
If the run pane shows this initial output, the program is installed correctly.
Detailed error tracking (voltage error in mV)
- Convergence diagnostics
- Full iteration summary table
- Plots (Dual Panel):
- Left: Log-scale I-V characteristics
- Right: Linear-scale I-V characteristics
- Overlay of measured data (red scatter) and simulation IV curve (blue line)
- Annotated with binning current line and target voltage markers
- Text box showing final parameters and error
- Files:
- Every time this script runs, the contents of LED_1s_1p.sub is updated. This file can be copied and saved under a new name to preserve a collection of results. To use multiple models such as in a separate series parallel circuit analysis, the diode ID needs to be changed to a unique name. For example LED-1, LED-2, LED-3 would have three LEDs with these names in the schematic and the model library file.
SPICE Diode Model
The tool generates models using standard SPICE diode syntax:
.model LED-1 D(RS={RS} IS={IS_optimized} N={N} Tnom=27)
Where:
- RS: Series resistance (Ω) – strongest effect in high-current region – affects voltage and slope of the curve
- IS: Saturation current (A) – primarily affects voltage level of curve
- N: Ideality factor (dimensionless) - controls curve shape and voltage (typically 1-5 for LEDs)
- Tnom: Nominal temperature (27°C)
RS, IS, and N interact with each other so changing one value will require adjusting the other two. This program automates this process so a user can focus on matching the shape of the data curve.
Typical Workflow:
- Measure LED I-V data and save to an Excel file
- Select an initial N and RS by inspecting curve shape – this takes experience but nearly any set of values will converge.
- Run tool to automatically optimize IS. Continue adjusting N and RS until the Spice model is a good fit to the data.
Performance:
- Speed: ~10-30 simulations to converge (depending on IS range)
- Accuracy: Typically <1 mV at binning current
- Robustness: Handles poor initial guesses via auto-bracketing
- Range: Validated for IS from 1e-4 to 1e-91
Technical Notes
- Requires Windows and PyLTspice 5.x library. The macOS version of LTspice does not work. We have not tested Linux.
- Uses bisection (not gradient methods) for guaranteed monotonic convergence
- Decade search accelerates convergence when initial guess for IS is many orders of magnitude away from the correct value
- Linear interpolation used to find voltage at binning current from discrete simulation data
- Bracket expansion (×1e6 or ÷1e6) handles edge cases
Limitations
- N and RS must be manually selected (tool only optimizes IS)
- Assumes single-diode model (no parallel resistor effects)
- Convergence tests are good for physically reasonable N/RS choices. Convergence usually succeeds for wrong guesses of N and RS.
- LTspice execution is required for each iteration (cannot be parallelized)
Recommendation for Engineers: Start with N/RS estimates from prior models, then use this tool to rapidly optimize IS. Fine-tune N/RS manually if curve shape doesn't match, then re-run optimization.
References and Acknowledgements
The script discussed in this article is available upon request. To receive a copy, please send an email to techsupport@luminus.com.
LTspice is a free software package hosted and maintained by Analog Devices, and the name “LTspice” is a registered trademark of Analog Devices
PyLTspice is an open source Python library maintained by Nuno Brum. The current version is 5.4.5.
Python is a registered trademark of the Python Software Foundation.
Microsoft Excel is a trademark of the Microsoft group of companies.
Windows is a trademark of the Microsoft group of companies.
macOS is a trademark of Apple Inc.
Ron Kielkowski, “SPICE Practical Device Modeling”, McGraw-Hill, Inc., New York, 1995 – discusses how to fit SPICE models to data.
Related Luminus Help Center Articles
Electrical – How do I extract Spice IV parameters from an LED datasheet?
Electrical – Can I simulate a set of LED IV curves that have a single Vf bin?
Electrical – Can I calculate LED lumens with Spice?
Electrical - What is Current Hogging in Series Parallel Designs?
Electrical - How do I sweep an LED IV curve in Spice?
Electrical - How do I insert a diode file into LTspice
Electrical - Can I add reference lines to Spice plot panes?
Data Analysis - Using Python to run LTspice as a remote process.
-------------------------------------------------------------------------------------------------------------------
Luminus Website: https://www.luminus.com/
Luminus Product Information (datasheets): https://www.luminus.com/products
Luminus Design Support (ray files, calculators, ecosystem items [power supplies, lenses, heatsinks]): https://www.luminus.com/resources
Luminus Product Information sorted by Applications: https://www.luminus.com/applications
Where to buy Samples of Luminus LEDs: https://www.luminus.com/contact/wheretobuy.
--------------------------------------------------------------------------------------------------------------------
Technical Support Contact Information: techsupport@luminus.com
Sales Support Contact Information: sales@luminus.com
Customer Service Support Contact Information: cs@luminus.com
Comments
0 comments
Please sign in to leave a comment.