% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Bodeplot creater script. Creates bode plots for comparing the non-linear effect
% 
% Inputs are: [ui,uj,uk] = [z,wg_in,wl_in]
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% Written by:  Knut Åge Meland
% Date:         1.11.2010
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%
clear all
close all
clc


%%
opt = bodeoptions;
opt.MagUnits='abs';
opt.PhaseUnits='rad';
opt.MagScale='log';
opt.YLim = {[10^-3,10^4];[-6,11]};
opt.YLimMode = {'manual';'manual'};
opt.Xlim=[10^-4,10];
%%
ui=0.04;
uj=0.36;
uk=8.64;
u=[ui; uj; uk];

leg=0;
l=1;
for ui=(0.03:0.01:0.06)
u=[ui; uj; uk];
par=v4_new_4d_parameters();
[x0, y0, par] =v4_new_4d_initialize(u,par);
[A,B,C,D]= linmod_knutfunk(x0,y0,u,par);


sys=ss(A,B,C,D);
TF=tf(sys);
h=0;
leg=leg+1; 
    for i=1:3
        for j=1:3
            hold all
            h=h+1;
            figure(h)
            bode(TF(j,i),opt);
            title(['input ' ,num2str(i), ' to output ', num2str(j)]);
            leg2{leg}=num2str(u(l)); 
            legend(leg2); %makes legend
        end
    end

end

%saving figures as eps format:
for fig = 1:9
    dir = 'c:\users\knutage\desktop\Prosjekt 2010\Min_rapport\latex_source\bilder\matlabfig\NewModel\';
    filename = ['figure', num2str(fig),'.eps'];
    saveas(figure(fig), [dir filename],'psc2');
      filename = ['figure', num2str(fig),'.jpg'];
      saveas(figure(fig), [dir filename]);
end
