Documente Academic
Documente Profesional
Documente Cultură
format;
load -mat rc_line.dat;
%LINELEM= [86 0 1 0 2 3 5.0e-10 2.0e+00 2.0e-9 2 2.5e-9 0; 82 100 1 2 0 0 0 0 0
0 0 0 ; 67 5.0e-13 2 0 NaN 0 0 0 0 0 0 0 ];
%NODES=[101 102];
% to check if file is loaded the following command is given
%disp(LINELEM);
global BetaP;
%BetaP=0.5*MU*COX*30e-6*0.35e-6;
global deltaT;
deltaT= 1e-10;%1.0e-9;
global simTime;
simTime= 0;%1.0e-5;
global timeStep;
timeStep=deltaT;
global NODES1;
NODES1=NODES;
%NODES=[103 105 ];
[LIN_mat_rowNumber,LIN_mat_cols]=size(LINELEM); % number of linear elemts
%[NLN_mat_rowNumber, Cols]=size(NLNELEM);
%[NLN_mat_size,LIN_mat_cols]=size(NLNELEM); %number of non linear elements
global MNA_size;
MNA_size = numel(NODES1);% calculating number of nodes
disp(MNA_size);
global numberOfNodes;
numberOfNodes= numel(NODES);
global DC_NV;
DC_NV=zeros(numberOfNodes,1);
global Y_Mat; % creation of zero matrix for storing stamp values
Y_Mat = zeros(MNA_size);
global v_Mat ; %creation of v matrix
v_Mat = zeros (MNA_size, 1);
global J_Mat; % creation of J matrix
J_Mat= zeros(MNA_size,1);
global branchCurrent; % to store branch currents
branchCurrent=zeros(MNA_size,1);
global storeCurrent; % Index used to stamp voltage, needed to get last index use
d
storeCurrent=0;
global storeCurrentIndex;
storeCurrentIndex=1;
%capIndexStore = 1;%% Stamp Volatge Last index used
global New_MNA_size;
New_MNA_size= MNA_size;
global localVolt; % to be used for storing instant voltages in stampCap()
localVolt=0;
global localCur; % to be used for storing instant curent in stampCap()
localCur=0;
global timeElapsed; % to be used for storing instant curent in stampCap()
timeElapsed=0;
global capCount;
% to be used for storing instant count of caps to find curr
ent for localCur
capCount=0;
global b;
global iterationC; % to be used for iteration count such that new iterations cou
d be done w/o creating new memory
iterationC=0;
global iterationL; % for inductor
iterationL=0;
global capIndexStoreIndex;
capIndexStoreIndex=1;
global localVolti;
localVolti=0;
global caps;% this will store all the capacitor values
global loopInt3;
loopInt3=1;
global final_out;
final_out=1;
global variable;
variable=0;
global nodeVoltage;
nodeVoltage=0;
global t;% used in trans function to set voltages
t=0;
global RUN; RUN=0;
notToBeUsedVaribale4=1;
end
function []=do_Trans(LINELEM, LIN_mat_rowNumber,time)
global MNA_size;
global NODES1;
MNA_size = numel(NODES1); % Re-initializing MNA_size to start Trans response
global New_MNA_size;
New_MNA_size= MNA_size;
global Y_Mat;
global J_Mat;
global v_Mat;
global capIndexStore;
global deltaT;
global b;
global iterationC;
global simTime;
global t;
global RUN; %for capacitors to stop stamping after first iteration
global storeCurrent;
global storeCurrentIndex;
for i=1:LIN_mat_rowNumber
if (LINELEM(i,1)== 86) %VOLTAGE__VOLTAGE__VOLTAGE__VOLTAGE__VOLTAGE__VOLTAG
E__VOLTAGE__VOLTAGE__VOLTAGE__
if (LINELEM(i,5)==2)
simTime= LINELEM(i,5+(2*(LINELEM(i,6)))); % calculates the simu
lation time for ckt
New_MNA_size=New_MNA_size+1;
%test
if ((time+deltaT)>= LINELEM(i,7+2*t))
t=t+1;
if(t==(LINELEM(i,6)))
t=t-1;
end
end
if((time+deltaT)< LINELEM(i,7+2*t) )
if(t==0)
SLOPE= LINELEM(i,8)/LINELEM(i,7);
stampVol((deltaT+time)*SLOPE, LINELEM(i,3), LINELEM(i,4)
);
else
SLOPE= (LINELEM(i,8+2*t)-LINELEM(i,8+2*(t-1)))/ (LINELE
M(i,7+2*t)-LINELEM(i,7+2*(t-1)));
stampVol((((deltaT+time-LINELEM(i,7+2*(t-1)))*SLOPE)+ LI
NELEM(i,8+2*(t-1))), LINELEM(i,3), LINELEM(i,4));
end
end
end
elseif ((LINELEM(i,1)== 67)) %CAPACITOR__CAPACITOR__CAPACITOR__CAPACITOR__CA
PACITOR__CAPACITOR__CAPACITOR__
if(RUN==0)
if (iterationC==0)
if(LINELEM(i,4)<1)
stampCur((2*LINELEM(i,2)*(b(LINELEM(i,3))))/deltaT
, LINELEM(i,3), LINELEM(i,4));
%stampCur( (b(LINELEM(i,3)))*(LINELEM(i,2)/deltaT)
, LINELEM(i,3), LINELEM(i,4));
stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3),
LINELEM(i,4));
iterationC=1;
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*
(b(LINELEM(i,3))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
else
stampCur((2*LINELEM(i,2)*(b(LINELEM(i,3))-b(LINELEM(i
,4))))/deltaT, LINELEM(i,3), LINELEM(i,4));
%stampCur((b(LINELEM(i,3))-b(LINELEM(i,4)))*(LINELEM(
i,2)/deltaT), LINELEM(i,3), LINELEM(i,4));
stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3), LINE
LEM(i,4));
iterationC=1;
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*(b(L
INELEM(i,3))-b(LINELEM(i,4))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
end
else
if (LINELEM(i,4)<1)
curr=(b(LINELEM(i,3)))*((LINELEM(i,2)/deltaT)-store
Current(storeCurrentIndex-1,1));
stampCur(curr + (2*LINELEM(i,2)*(b(LINELEM(i,3))))/
deltaT, LINELEM(i,3), LINELEM(i,4)); %volt is used instead of current
stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3), L
INELEM(i,4));
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*
(b(LINELEM(i,3))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
else
curr=(b(LINELEM(i,3))-b(LINELEM(i,4)))*((LINELEM(i,
2)/deltaT)-storeCurrent(storeCurrentIndex-1,1));
stampCur(curr + (2*LINELEM(i,2)*(b(LINELEM(i,3))-b(
LINELEM(i,4))))/deltaT, LINELEM(i,3), LINELEM(i,4)); %volt is used instead of c
urrent
stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3),
LINELEM(i,4));
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*
(b(LINELEM(i,3))-b(LINELEM(i,4))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
end
end
else
if (iterationC==0)
if(LINELEM(i,4)<1)
stampCur((2*LINELEM(i,2)*(b(LINELEM(i,3))))/deltaT, LINELE
M(i,3), LINELEM(i,4));
%stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3), LINELEM
(i,4));
iterationC=1;
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*(b(LINE
LEM(i,3))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
else
stampCur((2*LINELEM(i,2)*(b(LINELEM(i,3))-b(LINELEM(i,4))))/de
ltaT, LINELEM(i,3), LINELEM(i,4));
%stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3), LINELEM(i,4
));
iterationC=1;
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*(b(LINELEM(
i,3))-b(LINELEM(i,4))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
end
else
if (LINELEM(i,4)<1)
curr=(b(LINELEM(i,3)))*((LINELEM(i,2)/deltaT)-storeCurrent(
storeCurrentIndex-1,1));
stampCur(curr + (2*LINELEM(i,2)*(b(LINELEM(i,3))))/deltaT,
LINELEM(i,3), LINELEM(i,4)); %volt is used instead of current
% stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3), LINELEM(
i,4));
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*(b(LINELEM
(i,3))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
else
curr=(b(LINELEM(i,3))-b(LINELEM(i,4)))*((LINELEM(i,2)/delta
T)-storeCurrent(storeCurrentIndex-1,1));
stampCur(curr + (2*LINELEM(i,2)*(b(LINELEM(i,3))-b(LINELEM(
i,4))))/deltaT, LINELEM(i,3), LINELEM(i,4)); %volt is used instead of current
% stampCond(2*(LINELEM(i,2)/deltaT), LINELEM(i,3), LINELEM
(i,4));
storeCurrent(storeCurrentIndex,1)=(2*LINELEM(i,2)*(b(LINEL
EM(i,3))-b(LINELEM(i,4))))/deltaT;
storeCurrentIndex=storeCurrentIndex+1;
end
end
end
elseif((LINELEM(i,1)== 76)) % Inductor__Inductor__Inductor__Inductor__Induc
tor__Inductor__Inductor__
cur= (b(LINELEM(i-1, 3))-b(LINELEM(i, 3)))/LINELEM(i-1, 2)
; % calculates the current in 1 previous node
stampCur( cur+(b(LINELEM(i,3))*deltaT/(2*(LINELEM(i,2)))),
LINELEM(i,3), LINELEM(i,4));
stampCond(deltaT/(LINELEM(i,2)));
end
end
end
% Stamping function for Conductance
function[] = stampCond(condValue, Y_Mat_rowValue, Y_Mat_colValue)
%NODES=[103 101 102 ];
global NODES1;
global MNA_size;
%MNA_size = numel(NODES);% calculating number of nodes
global Y_Mat; % creation of zero matrix for storing stamp values
%Y_Mat = zeros(MNA_size);
if(Y_Mat_rowValue>0 && Y_Mat_colValue>0)
Y_Mat(Y_Mat_rowValue, Y_Mat_rowValue) = Y_Mat(Y_Mat_rowValue, Y_Mat_rowValue)
condValue;
Y_Mat(Y_Mat_rowValue, Y_Mat_colValue) = Y_Mat(Y_Mat_rowValue, Y_Mat_colValue)
condValue;
Y_Mat(Y_Mat_colValue, Y_Mat_rowValue) = Y_Mat(Y_Mat_colValue, Y_Mat_rowValue)
condValue;
Y_Mat(Y_Mat_colValue, Y_Mat_colValue) = Y_Mat(Y_Mat_colValue, Y_Mat_colValue)
condValue;
+
+