Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Octave functions to save signal in PWL or .dat file (for Spice or for Qucs)

38 views
Skip to first unread message

wzab

unread,
Feb 9, 2011, 1:40:35 PM2/9/11
to
I had to save signal processed in Octave (http://www.gnu.org/software/octave
) in a file, which then could be used to control the voltage or current
source in a circuit simulator (LT Spice, Spice or Qucs).

Below are two functions able to save the signal either in PWL format
(for LT SPice or Spice) or in .dat format (for Qucs):
I publish these function as PUBLIC DOMAIN

function save_pwl_file(filename, s, fsmp)
[n,m]=size(s);
if m != 1
error("We can only save column vectors")
end
timestep=1/fsmp;
time_axis = ((1:n)-1)' * timestep;
v=[time_axis, s];
save("-ascii",filename,"v")
endfunction

function save_qucs_file(filename, s, fsmp)
[n,m]=size(s);
if m != 1
error("We can only save column vectors")
end
timestep=1/fsmp;
time_axis = ((1:(n+1))-1)' * timestep;
s=[s;s(n)]; #duplicate the last value to workaround bug in Qucs' interpolator
f=fopen(filename,"wt");
fputs(f,"<Qucs Dataset 0.0.15>\n");
fputs(f,["<indep time ",num2str(n+1),">\n"]);
fprintf(f,"%.12e\n",time_axis);
fputs(f,["</indep>\n<dep X time>\n"]);
fprintf(f,"%.12e\n",s);
fputs(f,"</dep>\n");
fclose(f);
endfunction

0 new messages