# How to extract parameters from a PSPICE output file using Matlab?

Status
Not open for further replies. Please see first the shown figure .. it shows a snap shot to the text file that i need to get some data from it automatically with the aid of Matlab..
referring to this topic:

We can say that the MOSFET states are like this:

*Cut off: Vgs < Vt for all Vds
*Linear(triode) : Vgs > Vt and Vds < Vgs-Vt ( I am not sure is it also defined Vds<Vds sat ??)
*Saturation(active): Vgs >Vt and Vds > Vgs-Vt (i have the same wondering about Vds>Vds sat, does this mean MOS is in saturaion??)

How can extract this from the PSPICE output file using Matlab?
I think i have to know some things :
1. How to let Matlab read this text file?
2. How to let Matlab analyze it? i.e. it can search for words like Vgs and take its value that is corresponding to a MOSFET say M_1 as well as its model (n or p) for example
3. Make the required mathematical operations on this data (Vgs-Vt and taking absolute values of Vgs and Vt in case of PMOS) as well as decisions to check state. (cut of, linear, saturation)
4. finally, generate a new Matlab output file saying which MOSFET is in saturation, linear, and which is in cutoff.

I know that this problem needs one to be aware to circuits as well as Matlab programming.. and i hope that i find the person that can help Last edited by a moderator:

#### hr_rezaee Re: Matlab problem!!!

hi
it is easy to open file and search for your parameter.then extract them and use some comparisons.

fid1=fopen('H:\AVANTI\Hspice2004\Project\Gcell\gcell13.tr0');
fid2=fopen('H:\AVANTI\Hspice2004\Project\Gcell\gcell13.CSDF','w+');

while 1
line=fgetl(fid1);
if ~ischar(line), break, end
LL=length(line);
if isempty(line)
continue;
end
if LL>=3
L=line(1:3);
if L=='#N '
disp(char(line(4:LL)))
end
if L=='#C '
fprintf(fid2,'%s\n',char(line(3:LL)));
end
end
end
fclose(fid2);
fclose(fid1);
plot(hspice ,1),hspice ,3))

Points: 2 Re: Matlab problem!!!

Thank you hr_rezaee for help,
But in fact, I can't fully understand somethings:

First, I am using OrCAD PSPICE (not HSPICE) and i don't know what are files *.tr0 and *.CSDF ?? For my problem, assume that output file is like the snap shot in my post and it contains these fields also..

Second, I don't understand what does the Matlab code you wrote do exactly?

I hope you rewrite it adding comments on it in order to be able to understand it better, also remember that my problem is basically to determine the state of MOSFET (linear, saturation, or cutoff) so please help me to guarantee this funcion.

#### hr_rezaee Matlab problem!!!

hi
if you can, i offer you to use hspice.
that is a sample code that i used to read some output of hspice.
empty lines and lines that begin with #N, ignored and lines that begin with #C copied into file *.csdf
you can arrange your parameter in this style and transfer hole file (*.csdf) into matlab matrix.
see matlab help of load() function.