function freqinfo(i)
% Dette skriptet tar inn den lineariserte modell og 
% konverterer den til en tf-modell, deretter beregner den 
% RGA
% 
load ss_DTS_eq
% 
% Finner A,B,C og D matrisene
A=pmod.a;
B=pmod.b;%B=B(:,1:4);
C=pmod.c;%C=C(1:4,:);
D=pmod.d;%D=D(1:4,1:4);
%
if i==1
% 
% Konverterer til tf
% 
[num,den]=ss2tf(A,B,C,D,1); %Første pådrag
G(:,1)=num/den;
H(1,1)=tf(num(1,:),den);
H(2,1)=tf(num(2,:),den);
H(3,1)=tf(num(3,:),den);
H(4,1)=tf(num(4,:),den);
% H(5,1)=tf(num(5,:),den);
% H(6,1)=tf(num(6,:),den);

% 
[num,den]=ss2tf(A,B,C,D,2); %Andre pådrag
G(:,2)=num/den;
H(1,2)=tf(num(1,:),den);
H(2,2)=tf(num(2,:),den);
H(3,2)=tf(num(3,:),den);
H(4,2)=tf(num(4,:),den);
% H(5,2)=tf(num(5,:),den);
% H(6,2)=tf(num(6,:),den);
% 
[num,den]=ss2tf(A,B,C,D,3); %Tredje pådrag
G(:,3)=num/den;
H(1,3)=tf(num(1,:),den);
H(2,3)=tf(num(2,:),den);
H(3,3)=tf(num(3,:),den);
H(4,3)=tf(num(4,:),den);
% H(5,3)=tf(num(5,:),den);
% H(6,3)=tf(num(6,:),den);
% 
[num,den]=ss2tf(A,B,C,D,4); %Fjerde pådrag
G(:,4)=num/den;
H(1,4)=tf(num(1,:),den);
H(2,4)=tf(num(2,:),den);
H(3,4)=tf(num(3,:),den);
H(4,4)=tf(num(4,:),den);
% H(5,4)=tf(num(5,:),den);
% H(6,4)=tf(num(6,:),den);
%
% [num,den]=ss2tf(A,B,C,D,5); %Fjerde pådrag
% G(:,5)=num/den;
% H(1,5)=tf(num(1,:),den);
% H(2,5)=tf(num(2,:),den);
% H(3,5)=tf(num(3,:),den);
% H(4,5)=tf(num(4,:),den);
% H(5,5)=tf(num(5,:),den);
% H(6,5)=tf(num(6,:),den);
%
% [num,den]=ss2tf(A,B,C,D,6); %Fjerde pådrag
% G(:,6)=num/den;
% H(1,6)=tf(num(1,:),den);
% H(2,6)=tf(num(2,:),den);
% H(3,6)=tf(num(3,:),den);
% H(4,6)=tf(num(4,:),den);
% H(5,6)=tf(num(5,:),den);
% H(6,6)=tf(num(6,:),den);
% 
% Beregner RGA, steady state
% disp(G)
% RGA=G.*pinv(G)';
% disp(RGA)
% 
Gny=evalfr(H,1e-4);
disp('Prosessmatrise, steady state')
disp(Gny)
RGAny=Gny.*pinv(Gny)';
disp('Steady state RGA')
disp(RGAny)
%
% Beregner frekvensavhengig RGA
G1=pck(A,B,C,D);
n=1000;
omega=logspace(-4,1,n);
Gw=frsp(G1,omega);
% 
RGAw=veval('.*',Gw,vpinv(vtp(Gw)));
% 
% 
rga2=real(RGAw(1:4*n,1:4));
rga3=reshape(rga2,4,4*n);
% 
a11=rga3(1,1:n);
a21=rga3(2,1:n);
a31=rga3(3,1:n);
a41=rga3(4,1:n);
% a51=rga3(5,1:n);
% a61=rga3(6,1:n);
% 
a12=rga3(1,n+1:2*n);
a22=rga3(2,n+1:2*n);
a32=rga3(3,n+1:2*n);
a42=rga3(4,n+1:2*n);
% a52=rga3(5,n+1:2*n);
% a62=rga3(6,n+1:2*n);
% 
a13=rga3(1,2*n+1:3*n);
a23=rga3(2,2*n+1:3*n);
a33=rga3(3,2*n+1:3*n);
a43=rga3(4,2*n+1:3*n);
% a53=rga3(5,2*n+1:3*n);
% a63=rga3(6,2*n+1:3*n);
% 
a14=rga3(1,3*n+1:4*n);
a24=rga3(2,3*n+1:4*n);
a34=rga3(3,3*n+1:4*n);
a44=rga3(4,3*n+1:4*n);
% a54=rga3(5,3*n+1:4*n);
% a64=rga3(6,3*n+1:4*n);
%
% a15=rga3(1,4*n+1:5*n);
% a25=rga3(2,4*n+1:5*n);
% a35=rga3(3,4*n+1:5*n);
% a45=rga3(4,4*n+1:5*n);
% a55=rga3(5,4*n+1:5*n);
% a65=rga3(6,4*n+1:5*n);
%
% a16=rga3(1,5*n+1:6*n);
% a26=rga3(2,5*n+1:6*n);
% a36=rga3(3,5*n+1:6*n);
% a46=rga3(4,5*n+1:6*n);
% a56=rga3(5,5*n+1:6*n);
% a66=rga3(6,5*n+1:6*n);
% Plotter RGA matrisen
figure(1)
semilogx(omega,a11,omega,a21,omega,a31,omega,a41)
legend('a11','a21','a31','a41')
title('RGA - kolonne 1')
grid
figure(2)
semilogx(omega,a12,omega,a22,omega,a32,omega,a42)
legend('a12','a22','a32','a42')
title('RGA - kolonne 2')
grid
figure(3)
semilogx(omega,a13,omega,a23,omega,a33,omega,a43)
legend('a13','a23','a33','a43')
title('RGA - kolonne 3')
grid
figure(4)
semilogx(omega,a14,omega,a24,omega,a34,omega,a44)
legend('a14','a24','a34','a44')
title('RGA - kolonne 4')
grid
% 
% Plotter RGA til de ulike parringssekvensene
figure(5)
semilogx(omega,a11,omega,a22,omega,a33,omega,a44)
legend('a11','a22','a33','a44')
title('Parring L V S Rl, DTS, DB-control')
grid
figure(6)
semilogx(omega,a11,omega,a32,omega,a23,omega,a44)
legend('a11','a32','a23','a44')
title('Parring L S V Rl, DTS')
grid
figure(7)
semilogx(omega,a31,omega,a12,omega,a23,omega,a44)
legend('a31','a12','a23','a44')
title('Parring V S L Rl, DTS, DB-control')
grid
elseif i==2
% Bode plot til parring L-xA
[mag,phase,w]=bode(A,B,C,D,1);
figure(1)
subplot(2,1,1)
loglog(w,mag(:,1))
title('L-xA')
grid
subplot(2,1,2)
semilogx(w,phase(:,1))
grid
% Bode plot til parring V-xC
[mag,phase,w]=bode(A,B,C,D,2);
figure(2)
subplot(2,1,1)
loglog(w,mag(:,2))
title('V-xC')
grid
subplot(2,1,2)
semilogx(w,phase(:,2))
grid
% Bode plot til parring S-xB
[mag,phase,w]=bode(A,B,C,D,3);
figure(3)
subplot(2,1,1)
loglog(w,mag(:,3))
title('S-xB')
grid
subplot(2,1,2)
semilogx(w,phase(:,3))
grid
% Bode plot til parring Rl-DTS
[mag,phase,w]=bode(A,B,C,D,4);
figure(4)
subplot(2,1,1)
loglog(w,mag(:,4))
title('Rl-DTS')
grid
subplot(2,1,2)
semilogx(w,phase(:,4))
grid
% Bode plot til parring L-xB
figure(5)
[mag,phase,w]=bode(A,B,C,D,2);
subplot(2,1,1)
loglog(w,mag(:,3))
title('L-xB')
grid
subplot(2,1,2)
semilogx(w,phase(:,3))
grid
% Bode plot til parring S-xC
figure(6)
[mag,phase,w]=bode(A,B,C,D,3);
subplot(2,1,1)
loglog(w,mag(:,2))
title('S-xC')
grid
subplot(2,1,2)
semilogx(w,phase(:,2))
grid
figure(7)
[mag,phase,w]=bode(A,B,C,D,2);
subplot(2,1,1)
loglog(w,mag(:,4))
title('V-DTS')
grid
subplot(2,1,2)
semilogx(w,phase(:,4))
grid
elseif i==3
    figure(1)
    sigma(A,B,C,D)
    return
    figure(2)
[sv,w]=sigma(A,B,C,D);
subplot(3,2,1)
loglog(w,sv(1,:))
grid
title('L')
subplot(3,2,2)
loglog(w,sv(2,:))
grid
title('V')
subplot(3,2,3)
loglog(w,sv(3,:))
grid
title('S')
subplot(3,2,4)
loglog(w,sv(4,:))
grid
title('Rl')
subplot(3,2,5)
loglog(w,sv(5,:))
grid
title('D')
subplot(3,2,6)
loglog(w,sv(6,:))
grid
title('B')
elseif i==4
% Beregner poler
G=pck(A,B,C,D);
poles=spoles(G);
figure(1)
plot(poles,'*')
grid
title('Poler')
Zeros=szeros(G);
figure(2)
plot(Zeros,'*')
grid
title('Nullpunkter')
end