1+ %% Part 1
2+ Is = 0 .01e- 12 ; % Forward Bias Saturation Current
3+ Ib = 0 .1e- 12 ; % Breakdown Bias Saturation Current
4+ Vb = 1.3 ; % Breakdown Voltage
5+ Gp = 0.1 ; % Parasitic Parallel Conductance
6+ Vt = 1.2 / 0.025 ;% Thermal Voltage
7+
8+ % Voltage
9+ V = linspace(-1.95 ,0.7 ,200 );
10+ % Current
11+ I = Is *(exp(Vt .* V )-1 )+Gp * V - Ib * exp(-Vt .*(V + Vb ));
12+ Irand = I * 0.8 + I .* 0.2 .* rand(size(V ));
13+
14+ % Plots
15+ figure(1 )
16+ plot(V ,I ,' .' )
17+ title(' Diode Voltage vs Current' )
18+ xlabel(' Current (A)' )
19+ ylabel(' Voltage (V)' )
20+
21+ figure(2 )
22+ semilogy(V ,abs(I ),' .' )
23+ title(' Diode Voltage vs log(Current)' )
24+ xlabel(' Current (A)' )
25+ ylabel(' Voltage (V)' )
26+
27+ figure(3 )
28+ plot(V ,Irand ,' .' )
29+ title(' Diode Voltage vs randCurrent' )
30+ xlabel(' Current (A)' )
31+ ylabel(' Voltage (V)' )
32+
33+ figure(4 )
34+ semilogy(V ,abs(Irand ),' .' )
35+ title(' Diode Voltage vs log(randCurrent)' )
36+ xlabel(' Current (A)' )
37+ ylabel(' Voltage (V)' )
38+
39+ %% Part 2
40+ % Polynomial fit
41+ p4I = polyfit(V ,I ,4 );
42+ Ip4 = polyval(p4I ,V );
43+ p8I = polyfit(V ,I ,8 );
44+ Ip8 = polyval(p8I ,V );
45+ p4Irand= polyfit(V ,I ,4 );
46+ Irandp4 = polyval(p4Irand ,V );
47+ p8Irand= polyfit(V ,I ,8 );
48+ Irandp8 = polyval(p8Irand ,V );
49+
50+ % Adding fits to graphs
51+ figure(1 )
52+ hold on
53+ plot(V ,Ip4 )
54+ plot(V ,Ip8 )
55+ hold off
56+
57+ figure(3 )
58+ hold on
59+ plot(V ,Irandp4 )
60+ plot(V ,Irandp8 )
61+ hold off
62+
63+ %% Part 3
64+ % Setting non linear fit parameters
65+ fo1 = fittype(' A.*(exp(1.2*x/25e-3)-1) + 0.1.*x - C*(exp(1.2*(-(x+1.3))/25e-3))' );
66+ ff1 = fit(V ' ,I ' ,fo1 );
67+ If1 = ff1(V );
68+
69+ fo2 = fittype(' A.*(exp(1.2*x/25e-3)-1) + B.*x - C*(exp(1.2*(-(x+1.3))/25e-3))' );
70+ ff2 = fit(V ' ,I ' ,fo2 );
71+ If2 = ff2(V );
72+
73+ fo3 = fittype(' A.*(exp(1.2*x/25e-3)-1) + B.*x - C*(exp(1.2*(-(x+D))/25e-3))' );
74+ ff3 = fit(V ' ,I ' ,fo3 );
75+ If3 = ff3(V );
76+
77+ % Adding to new plot
78+ figure(5 )
79+ hold on
80+ plot(V ,I ,' .' )
81+ plot(V ,If1 )
82+ plot(V ,If2 )
83+ plot(V ,If3 )
84+ legend(' Data' ,' fita' ,' fitb' ,' fitc' );
85+ xlim([-2 1 ])
86+ ylim([-4 4 ])
87+ title(' Non Linear Fit Diode Voltage vs Current' )
88+ xlabel(' Current (A)' )
89+ ylabel(' Voltage (V)' )
90+ hold off
91+
92+ %% Part 4
93+ % Setting up neural net
94+ inputs = V .' ;
95+ targets = I .' ;
96+ hiddenLayerSize = 10 ;
97+ net = fitnet(hiddenLayerSize );
98+ net.divideParam.trainRatio = 70 / 100 ;
99+ net.divideParam.valRatio = 15 / 100 ;
100+ net.divideParam.testRatio = 15 / 100 ;
101+ [net ,tr ] = train(net ,inputs ,targets );
102+ outputs = net(inputs );
103+ errors = gsubtract(outputs ,targets );
104+ performance = perform(net ,targets ,outputs );
105+ % view(net)
106+ Inn = outputs ;
107+
108+ % Plotting neural net
109+ figure(6 )
110+ hold on
111+ plot(V ,I ,' .' )
112+ plot(V ,Inn )
113+ xlim([-2 1 ])
114+ ylim([-4 4 ])
115+ title(' Neural Net Fit Diode Voltage vs Current' )
116+ xlabel(' Current (A)' )
117+ ylabel(' Voltage (V)' )
118+ hold off
0 commit comments