You are on page 1of 20

SYSTEM DESIGN LAB

INCHARGE: Ms. Komal Swami










SUBMITTED BY: SUBMITTED TO:
Pankaj Jain Ms. Komal Swami
ID- 2013PEV5039




INDEX

S.No. DATE TITLE SIGN REMARK










































Experiment -1
Objective: Plot DC Response of RTL Inverter circuit using H SPICE Simulation tool. The designing
parameter the given below
(Vdd=3V; Vin= 1V ; R1=1K; W=90.9um;
L=1um; Vtn=1V; kn=22um; gamma=0.2)
Tool: H SPICE A-2008.0 3(32 BIT)
Theory:
NMOS Inverter:-

Figure: NMOS Inverter Circuit
Netlist:

***RTL inverter ciruit***
vdd 3 0 dc 5
vin 1 0 dc .1
R1 3 2 1k
M 2 1 0 0 nmod w=90.9u l=1u
.model nmod nmos (vto=1 kn=22u gamma=0.2)
.dc vm 0 5 .1
.plot dc v(2)
.probe
.option post
.end

Simulation Results:


Result:
A printout of spice input file, plot of the dc response of the NMOS inverter.











Experiment -2
Objective: Plot DC Response of RTL Inverter circuit using H SPICE Simulation tool. The designing
parameter the given below
(Vdd=5V; Vin= 1V ; R1=1K; W=90.9um;
L=1um; Vtp= -1V; kn=22um; gamma=0.2)
Tool: H SPICE A-2008.0 3(32 BIT)
Theory:
PMOS Inverter :-



Figure :- PMOS Inverter Circuit
Netlist:

***RTL inverter ***
vdd 3 0 dc 5
vin 2 0 dc .1
R1 1 0 1k
M 3 2 1 3 Pmod w=90.9u l=1u
.model Pmod Pmos (vto=-1 kP=22u gamma=0.2)
.dc vin 0 5 .1
.plot dc v(1)
.plot
.option post
.end
Simulation Results:


Result:
A printout of spice input file, plot of the dc response of the PMOS inverter.














Experiment -3
Objective: Plot DC Response of CMOS Inverter circuit using H SPICE Simulation tool. The
designing parameter the given below
(Vdd=5V; Vin= 1V ; L=1um; W=90.9um;
Vtn=1V; Vtp=-1V kn=22um; kn=22um;
gamma=0.2)
Tool: H SPICE A-2008.0 3(32 BIT)
Theory:
CMOS Inverter:-

Figure :- CMOS Inverter Circuit
Netlist:
***cmos inverter ciruit***
vdd 3 0 dc 5
vin 1 0 dc .1
M1 2 1 0 0 nmod w=90.9u l=1u
M2 3 1 2 3 pmod w=90.9u l=1u
.model nmod nmos (vtn=1 kn=22u gamma=0.2)
.model pmod pmos (vtp=-1 kp=22u gamma=0.2)
.dc vin 0 5 .1
.plot dc v(2)
.probe
.option post
.end

Simulation Results:

Result:
A printout of spice input file, plot of the dc response of the CMOS inverter.












Depth First Search (DFS)


Depth first search (DFS) is useful for Find a path from one vertex to another Whether or not
graph is connected Computing a spanning tree of a connected graph. DFS uses the backtracking
technique.

Algorithm Depth First Search
Algorithm starts at a specific vertex S in G, which becomes current vertex. Then algorithm
traverse graph by any edge (u, v) incident to the current vertex u. If the edge (u, v) leads to an
already visited vertex v, then we backtrack to current vertex u. If, on other hand, edge (u, v)
leads to an unvisited vertex v, then we go to v and v becomes our current vertex. We proceed in
this manner until we reach to "deadend". At this point we start back tracking. The process
terminates when backtracking leads back to the start vertex.
Edges leads to new vertex are called discovery or tree edges and edges lead to already visited are
called back edges.

DEPTH FIRST SEARCH (G, v)
Input: A graph G and a vertex v.
Output: Edges labeled as discovery and back edges in the connected component.
For all edges e incident on v do
If edge e is unexplored then
w opposite (v, e) // return the end point of e distant to v
If vertex w is unexplained then
- mark e as a discovery edge
- Recursively call DSF (G, w)
else
- mark e as a back edge



Example (CLR)





Solid Edge = discovery or tree edge
Dashed Edge = back edge.
Each vertex has two time stamps: the first time stamp records when vertex is first discovered and
second time stamp records when the search finishes examining adjacency list of vertex.
DFS algorithm used to solve following problems.
Testing whether graph is connected.
Computing a spanning forest of graph
DFS Algorithm:
#include<stdio.h>
#include<conio.h>
int a[20][20],reach[20],n;
void dfs(int v)
{
int i;
reach[v]=1;
for(i=1;i<=n;i++)
if(a[v][i] && !reach[i])
{
printf("\n %d->%d",v,i);
dfs(i);
}
}
void main()
{
int i,j,count=0;
clrscr();
printf("\n Enter number of vertices:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
reach[i]=0;
for(j=1;j<=n;j++)
a[i][j]=0;
}
printf("\n Enter the adjacency matrix:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
dfs(1);
printf("\n");
for(i=1;i<=n;i++)
{
if(reach[i])
count++;
}
if(count==n)
printf("\n Graph is connected");
else
printf("\n Graph is not connected");
getch();
}




Breadth First Search (BFS)


Breadth First Search algorithm used in
Prim's MST algorithm.
Dijkstra's single source shortest path algorithm.
Like depth first search, BFS traverse a connected component of a given graph and defines a spanning tree.

Algorithm Breadth First Search
BFS starts at a given vertex, which is at level 0. In the first stage, we visit all vertices at level 1. In the
second stage, we visit all vertices at second level. These new vertices, which are adjacent to level 1
vertices, and so on. The BFS traversal terminates when every vertex has been visited.

BREADTH FIRST SEARCH (G, S)
Input: A graph G and a vertex.
Output: Edges labeled as discovery and cross edges in the connected component.
Create a Queue Q.
ENQUEUE (Q, S) // Insert S into Q.
While Q is not empty do
for each vertex v in Q do
for all edges e incident on v do
if edge e is unexplored then
let w be the other endpoint of e.
if vertex w is unexpected then
- mark e as a discovery edge
- insert w into Q
else
mark e as a cross edge
BFS label each vertex by the length of a shortest path (in terms of number of edges) from the start vertex.



Example (CLR)

Step1

Step 2

Step 3

Step 4

Step 5

Step 6

Step 7

Step 8

Step 9



Starting vertex (node) is S
Solid edge = discovery edge.
Dashed edge = error edge (since none of them connects a vertex to one of its ancestors).
As with the depth first search (DFS), the discovery edges form a spanning tree, which in this case we call
the BSF-tree.
BSF used to solve following problem
Testing whether graph is connected.
Computing a spanning forest of graph.
BFS Algorithm:
#include<stdio.h>
#include<conio.h>
int a[20][20],q[20],visited[20],n,i,j,f=0,r=-1;
void bfs(int v)
{
for(i=1;i<=n;i++)
if(a[v][i] && !visited[i])
q[++r]=i;
if(f<=r)
{
visited[q[f]]=1;
bfs(q[f++]);
}
}
void main()
{
int v;
clrscr();
printf("\n Enter the number of vertices:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
q[i]=0;
visited[i]=0;
}
printf("\n Enter graph data in matrix form:\n");
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
scanf("%d",&a[i][j]);
printf("\n Enter the starting vertex:");
scanf("%d",&v);
bfs(v);
printf("\n The node which are reachable are:\n");
for(i=1;i<=n;i++)
if(visited[i])
printf("%d\t",i);
else
printf("\n Bfs is not possible");
getch();
}








KL Partitioning Algorithm


KL Partitioning algorithm:


% Demonstration of Kernighan-Lin Bi-partitioning Algorithm

clear all, close all,

% Circuit specification
% the circuit is specified as a n x n incident matrix c
% where n is even
% c(i,i) = 0, c(i,j) = c(j,i),
% c(i,j) = 0 if there is no connection between
% vertex i to vertex j, and hence the cost of partition them is 0.
valid=0;
while ~valid,
disp('Enter 0 to use circuit discussed in the class note (default);');
disp('Enter 1 to use the circuit in Figure 2.2(b) of text book;');
disp('Enter 2 to use another example;');
disp('Enter 3 to use Figure 4.1(a) of textbook, p. 162;');
disp('Enter 4 to enter connectivity matrix and initial paritition interactively:');
chos=input('Enter a selection, ENTER key means default: ');
if isempty(chos), chos=0;
end
if ismember(chos,[0 1 2 3 4]), valid=1;
else disp('Entry invalid, must be an integer 0, 1, 2, 3, or 4: ');
end
end

if chos==0,
c0=[0 1 0 0 0 0;
1 0 1 1 0 0;
0 1 0 0 0 0;
0 1 0 0 1 1;
0 0 0 1 0 1;
0 0 0 1 1 0];
idxA0=[2 3 4]; idxB0=[1 5 6];
c0=c0([idxA0 idxB0],[idxA0 idxB0]); % permute c0 to fit initial partition
elseif chos==1,
c0=[0 1 2 3 2 4;
1 0 1 4 2 1;
2 1 0 3 2 1;
3 4 3 0 4 3;
2 2 2 4 0 2;
4 1 1 3 2 0];
idxA0=[1 2 3]; idxB0=[4 5 6]; % initial partition node list in A and B
elseif chos==2,
c0=[0 1 0 4 2 0
1 0 0 2 2 3
0 0 0 0 6 0
4 2 0 0 0 0
2 2 6 0 0 4
0 3 0 0 4 0];
idxA0=[1 2 3]; idxB0=[4 5 6]; % initial partition node list in A and B
elseif chos==3,
c0=[0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 1 0 0
1 1 0 0 0 0 1 0
0 0 1 1 0 0 1 0
0 0 0 0 1 1 0 1
0 0 0 0 0 0 1 0];
idxA0=[1 2 3 4]; idxB0 = [5 6 7 8];
elseif chos==4,
c0=input('Enter c0 matrix, remember bracket: ');
idxA0=input('Initial partition A (as a row vector) = ');
idxB0=input('Initial partition B (as a row vector) = ');
else
disp('Input invlid, re-enter between 0 to 3, or press return key: ');
end

% note that A and B are disjoint sets
disp('Initial partitions are:')
disp(['Partition A: ' int2str(idxA0)]);
disp(['Partition B: ' int2str(idxB0)]);
disp('Intial incident matrix [partition A; partition B] is:');
disp(c0);

c=c0; idxA=idxA0; idxB=idxB0;
n=size(c0,1); % c0 is a square, symmetric n x n matrix
n1=n/2; n2=n1; % equal size bi-partition |A| = |B| = n/2

% a few words about indexing of nodes:
% the nodes are labeled as partition A: [1, 2, ..., n1=n/2]
% partition B: [n1+1, n1+2,..., n]
% during iterations, the c matrix will reduce its size by 2
% since the two exchange nodes will be frozen during future iterations
% hence the index to the columns and rows of the c matrix will be
% different from those of the node indices.
% in this program, we will use node indices to indicate nodes
% and matrix indices to refer to matrix column and row numbers
% note that only at the first iteration, these two are identical.
% later, they are different!

iter=1; % iteration count
done=0; % Boolean condition on whether iteration is done

while ~done, % while not yet done,
disp(['*** Iteration ' int2str(iter) ' ***']);
if iter==1, % during the first iteration, compute initial D value
% compute internal cost, external cost, D value and g value
% this will become a callable m-file later
% compute internal cost, 1 x n
intcost=[sum(c(1:n1,1:n1)') sum(c(n1+1:n,n1+1:n)')];
% compute external cost, 1 x n
extcost=[sum(c(1:n1,n1+1:n)') sum(c(n1+1:n,1:n1)')];
% compute D values, 1 x n
Dvalue=extcost-intcost;
% first n1 is partition A, next n2 is partition B
disp(['Initial partition cost = ' int2str(sum(extcost(1:n1)))]);
end
% otherwise, the D values will be updated later.
% compute g value to determine candidate exchange nodes
% compute all combinations of partition A nodes and partition B
% nodes among nodes that are not fixed.
gmat = Dvalue(1:n1)'*ones(1,n2)+ones(n1,1)*Dvalue(n1+1:n)...
-2*c(1:n1,n1+1:n);
% gmat is n1 x n2 that is of the same
% dimension as c(1:n1,n1+1:n). The row indices of gmat is the
% same as those of the c matrix. The column indices of gmat
% are the same as those of the c matrix minus n1
[mtmp,id1]=max(gmat);
% find max g of each column of gmat matrix
% mtmp, id1 are both 1 x n2
[g(iter),id2]=max(mtmp);
% g(iter) is max g of gmat matrix
% id2 is the column index of the max g of the gmat matrix
ida=id1(id2); idb=n1+id2;
% c matrix indices of two exchange nodes
% that yield maximum g (gain) in reducing cut set cost.
disp('The g matrix is:')
disp(gmat);

% now convert into node indices for the two selected nodes
bidx(iter) = idxB(id2); % node index for node b
aidx(iter) = idxA(ida); % node index for node a
disp(['iter = ' int2str(iter) ', nodes to be exchanged: ' ...
int2str(aidx(iter)) ', and ' int2str(bidx(iter)) ...
' Max. g = ' num2str(g(iter))]);
% In summary, the maximum g value corrsponds to exchange
% node aidx(iter) in A and node bidx(iter) in B, and these nodes correspond to
% the ida, and idb rows and columns in the current c matrix

% Now consider if it is necessary to go to the next iteration
% Here for demonstration purpose, we use the naive criteria that
% when c matrix is reduced to a 2 x 2 matrix in this iteration, then
% it is done. Otherwise, we proceed.

if size(c,1)==2, done=1; % stop the next iteration, done
else
iter=iter+1; % move to the next iteration
% First remove node aidx(iter) and bidx(iter) from the node indices of
% A and B, idxA and idxB respectively
idxA=setdiff(idxA,aidx); % A-{a}
idxB=setdiff(idxB,bidx); % B-{b}

% next, remove the ida, idb rows and columns of the c matrix
idv=[setdiff([1:n],[ida idb]) [ida idb]]; % permute the indices of c
c1 = c(idv,idv); % move ida, idb rows and columns to the last two rows
% and last two columns
% before removing the last two columns and rows, we may update the
% Dvalues of remain nodes in partitions A and B due to the selection of
% nodes aidx and bidx for exchange
% First permute the Dvalue vector:
Dvalue=Dvalue(idv(1:n-2)); % move the Dvalue of a and b to last two entries
% and then drop them. Dvalue is now 1 x (n-2)
%
% D' = D + 2*c(idx in the same partition) - 2*c(idx in different partition)
% Hence, partitions A and B must be updated separately
% (I) partition A
% D' = D + 2*c(a,vA) - 2*c(b,vA)
% correspond to first n1-1 column/rows of the c1 matrix and
% ida is the second to last row/column of the c1 matrix
% hence c(a,vA) is c1(n-1,1:n1-1), c(b,vA) is c1(n, 1:n1-1)
Dvalue(1:n1-1)=Dvalue(1:n1-1)+2*c1(n-1,1:n1-1)-2*c1(n,1:n1-1);
% (II) partition B
% correspond to n1:n-2 column/row of the c1 matrix
% D' = D + 2*c(b,vB) - 2*c(a,vB)
% c(a,vB) is c1(n-1,n1:n-2), c(b,VB) is c1(n,n1:n-2)
Dvalue(n1:n-2)=Dvalue(n1:n-2)+2*c1(n,n1:n-2)-2*c1(n-1,n1:n-2);
% Dvalue is reduced length by 2
disp('Updated D values are:');
disp(Dvalue)

% Now, reduced c matrix with ida, idb rows and columns removed
c= c1(1:n-2,1:n-2);
n = size(c,1); n1=n/2; n2=n1; % update c matrix indices
% Note that idxA is now 1 x n1, idxB is 1 x n2;
disp('Press any key to continue to the next iteration ...')
pause
end % if not terminate, update D'
end % of while loop

% Now that all the g values are computed, we need to determine k,
% the number of exchanges needed.
% k is the maximum partial sum of the g vector.
% triu(toeplitz(g)) gives an upper triangular matrix. The first column
% contains g(1), the second column has g(2), g(1), the 3rd column has
% g(3), g(2), g(1), etc.
% sum(triu(toeplitz(g))) gives a running partial sum of the g sequence.
% K is the index of the maximum entry of the running partial sum.
[tmp,K]=max(sum(triu(toeplitz(g))));
disp('Decision ...');
disp(['Exchange first ' int2str(K) ' pairs of nodes']);
disp('Final partition = ');
disp(['Partition A: ' int2str(union(setdiff(idxA0,aidx(1:K)),bidx(1:K)))]);
disp(['Partition B: ' int2str(union(setdiff(idxB0,bidx(1:K)),aidx(1:K)))]);

You might also like