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