% LED or Other Diode I-V Plots for Data Taken with the Analog Discovery
% K. A. Connor, 4 April 2014 - Updated 25 October 2015
 
% Import Data From Spreadsheet
% Click on Import Data from the Home Tab in Matlab 2015
% Select the CSV File You Stored in the Directory Where This Program is
% Located. Once you have imported the file, type 'whos' to see what the
% default name is for the array with the data in it. The names should 
% also be listed in the Workspace window
 
% Identify the Time Data
time=Times;% The first column is the time vector
 
% Voltage Data
v_diode=C1V;% The voltage across the diode. This may be different for you.
 
% Current Data
i_diode=M1A;% This assumes that you used the Math Channel to find current.
% The current is measured by finding the voltage across a 1000 Ohm Resistor.
% If you did not use the Math Channel on Analog Discovery, You may have
% to divide a voltage channel by the resistance in your circuit. 
 
% There may be some instrumental offsets in the measurements. If they are
% large enough to cause problems, they can be removed. Usually, this step
% is not necessary, so the expressions below have been commented out.
% You should calibrate your Analog Discovery board to minimize offsets.
% Eliminate current offset;
% i_diode=i_diode+8.3333e-004;
% Eliminate voltage offset
% v_diode=v_diode-0.55;
 
% Plot the results
plot(v_diode,i_diode,'.');
hold on;% This allows the next plot command to plot in the same figure
grid;
 
% axis([-2 4 -1e-3 21e-3]);
% The axes can be adjusted to produce a better plot.
 
% Ideal Diode Equation
is=1e-9;n=2;
vd=[-4:.01:4];
id=is.*(exp(vd./(n.*.0259))-1.0);
plot(vd,id,'linewidth',3,'color','r');
axis([-4 4 -.001 .005]);% For most diodes, positive voltages are all that we
% need to plot. However, you may want to extend the range to negative
% voltages in some cases, as is usually done here.
