MATLAB Answers

Using least squares to find the x intercept.

12 views (last 30 days)
madhan ravi
madhan ravi on 30 Dec 2019
Commented: madhan ravi on 30 Dec 2019
I have a set of data points which represent the IV characteristics of a diode. I'm confused on how to get the threshold voltage (x intercept) of that diode. Any suggestions and ideas are welcomed. Illustration:
34e29d4a-a2d4-4d88-bbb7-13a485abc2a1.JPG

  5 Comments

Show 2 older comments
Matt J
Matt J on 30 Dec 2019
You've attached the data, but you haven't told us what equation you are using to model the curve. To fit a curve to data, you need a model equation to fit to. Perhaps a softplus?
y(x)=a*log(1+exp(b*x))-c
If you were to fit this curve to your data, the asymptotic line would be
y=a*b*x-c
and the x-intercept would be c/(a*b). But other models will yield different results, so you need to decide which model is most appropriate.
John D'Errico
John D'Errico on 30 Dec 2019
The point being, you cannot do any prediction (x intercept, for example) without a model of the process. Matt suggests what might be a decent one, but very often there is some model suggested by physical principals. If so, then it makes a great dela of sense to use it.
But what it relly looks like from your drawing is that you do not want the actual curve drawn, but the equation of a tangent line, drawn from some specific point on the curve. Then you might want to find the x intercept of that line.
Or, perhaps the curve drawn is supposed to be asymptotically linear. And you want to find the equation of the asymptote. Given the asymptote equation, it will be easy to find the x intercept. But that asymptote cannot be found without knowing a model for your process.
Still though, without knowing exactly what line is to be created, or how it might be defined, you cannot predict an intercept.
Essentially, we need more than just a drawing.
madhan ravi
madhan ravi on 30 Dec 2019
"But what it relly looks like from your drawing is that you do not want the actual curve drawn, but the equation of a tangent line, drawn from some specific point on the curve. Then you might want to find the x intercept of that line." - that seems to make more sense.Thanks Matt and John D'Errico the model seems to be the one which sir Image Analyst has mentioned below. The point maybe the one at the upper right most point. This intercept which would be found by the experimentation should approximately be near to the literature value of Schottky diode which appears to be in the range from .15 - .45 volts. I really want to make use of MATLAB not interested in using any other softwares than MATLAB. The logic of this method would be helpful for me to apply for all the tasks.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 30 Dec 2019
Note that if you're using the Shockley_diode_equation,
08086e72556f3cf441163d5403f5b104590acae0
or essentially I = a * exp(b * V) + c, then the intersection of the slope line depends on where the slope is evaluated. This is because the exponential function f( x) = e x has the special property that its derivative is the function itself, f′( x) = e x = f( x). So, do you want the slope at the last x that you have provided in your text file? If so, the slope is pretty easy to compute analytically. It's slope = a * b * exp(b * V). So use fitnlm() to figure out a, b, and c (using attached demo), then plug in a, b, and V to get the slope at that point. Then, knowing the slope and using the point-slope version of the equation for a line passing through that right-most point, you can get the equation of the line, then set that equal to 0 and solve for V.
Let me know if you want a fully worked out solution.

  3 Comments

madhan ravi
madhan ravi on 30 Dec 2019
Thats absolutely brilliant answer sir Image analyst. If you could give the full worked out solution it would be really helpful to understand the perfect analysis of whats going on. Thank you once again :)
Image Analyst
Image Analyst on 30 Dec 2019
See this:
% Uses fitnlm() to fit a non-linear model (an exponential decay curve) through noisy data.
% Requires the Statistics and Machine Learning Toolbox, which is where fitnlm() is contained.
% Initialization steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
filename = fullfile(pwd, 'shottky_simr1.txt')
strData = importdata(filename)
X = strData.data(:, 1);
Y = strData.data(:, 2);
% Now we have noisy training data that we can send to fitnlm().
% Plot the noisy initial data.
plot(X, Y, 'b.', 'LineWidth', 2, 'MarkerSize', 15);
grid on;
hold on
beta0 = [0.01, -0.0000001, -0.1]; % Guess values to start with. Just make your best guess.
% y = beta0(1) * exp(beta0(1)*X) + beta0(3);
% plot(X, y, 'r-');
% Convert X and Y into a table, which is the form fitnlm() likes the input data to be in.
tbl = table(X(:), Y(:));
% Define the model as Y = a + exp(-b*x)
% Note how this "x" of modelfun is related to big X and big Y.
% x((:, 1) is actually X and x(:, 2) is actually Y - the first and second columns of the table.
modelfun = @(b,x) b(1) * exp(b(2)*x(:, 1)) + b(3);
% Now the next line is where the actual model computation is done.
mdl = fitnlm(tbl, modelfun, beta0);
% Now the model creation is done and the coefficients have been determined.
% YAY!!!!
% Extract the coefficient values from the the model object.
% The actual coefficients are in the "Estimate" column of the "Coefficients" table that's part of the mode.
coefficients = mdl.Coefficients{:, 'Estimate'}
% Create smoothed/regressed data using the model:
yFitted = coefficients(1) * exp(coefficients(2)*X) + coefficients(3);
% Now we're done and we can plot the smooth model as a red line going through the noisy blue markers.
hold on;
plot(X, yFitted, 'r-', 'LineWidth', 2);
grid on;
title('Exponential Regression with fitnlm()', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
legendHandle = legend('Actual Y', 'Fitted Y', 'Location', 'north');
legendHandle.FontSize = 30;
formulaString = sprintf('Y = %.3e * exp(%.3g * X) + %.3g', coefficients(1), coefficients(2), coefficients(3))
yl = ylim;
text(-0.25, mean(yl), formulaString, 'FontSize', 25, 'FontWeight', 'bold', 'Color', 'r');
% Get slope at xMax
[xMax, indexAtXMax] = max(X)
yMax = Y(indexAtXMax)
slope = coefficients(1) * coefficients(2) * exp(coefficients(2) * xMax)
% Point slope formula (y-yMax) = slope * (x-xMax)
% Get the formula for y=0, and x=xMax
% -yMax/slope = (x - xMax)
x0 = -yMax / slope + xMax
% Plot a * there
plot(x0, 0, 'r*', 'MarkerSize', 20, 'LineWidth', 2);
line([x0, xMax], [0, yMax], 'Color', 'r', 'LineWidth', 2);
caption = sprintf('(%3e, 0)', x0);
text(x0, -0.001, caption, 'FontSize', 25, 'FontWeight', 'bold', 'Color', 'r');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
You can see the fit is very good, and the tangent at the last point intersects the x axis at
x0 =
0.235560584047374
madhan ravi
madhan ravi on 30 Dec 2019
Bulleye! An absolute masterpiece. This forum is the best and this feels like home:) Been struggling with this for days and should have asked this long back!!

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2018b

Translated by