-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiode_curvefit.m
38 lines (37 loc) · 1.49 KB
/
diode_curvefit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%curve fitting for diode IN4007
% The 1N400x (or 1N4001 or 1N4000[2]) series is a family of popular 1 A
general-purpose silicon rectifier diodes commonly used in AC adapters for
common household appliances.
% Its blocking voltage varies from 50 volts (1N4001) to 1000 volts
(1N4007). This JEDEC device number series is available in the DO-41 axial
package,[3][4] and similar diodes are available in SMA and MELF surface
mount packages (in other part number series).[5][6]
function [fitresult, gof] = diode_curvefit(Voltage_12, Current_12)
%CREATEFIT1(VOLTAGE_12,CURRENT_12)
% Create a fit.
%
% Data for 'Custom_fit' fit:
% X Input : Voltage_12
% Y Output: Current_12
% Output:
% fitresult : a fit object representing the fit.
% gof : structure with goodness-of fit info.
%% Fit: 'Custom_fit'.
[xData, yData] = prepareCurveData( Voltage_12, Current_12 );
% Set up fittype and options.
ft = fittype( 'Is*(exp(x/(n*0.026))-1)', 'independent', 'x', 'dependent',
'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Display = 'Off';
opts.StartPoint = [0.157613081677548 0.970592781760616];
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft, opts );
% Plot fit with data.
figure( 'Name', 'Custom_fit' );
h = plot( fitresult, xData, yData );
legend( h, 'Current_12 vs. Voltage_12', 'Custom_fit', 'Location',
'NorthEast' );
% Label axes
xlabel Voltage_12
ylabel Current_12
grid on