function RLC(Rls,Zload)
%
% Draw the characteristics of an RLC filter
%
%  RLC(Rls,Zload)
%
if nargin<1
  Rls=0;
  Zload=10e6;
elseif nargin<2
  Zload=10e6;
end
  
f=1e3;
disp('Select a frequency by clicking in the figure');
disp('Quit by selecting a negative frequency...')
disp('Enjoy!! /Kent')
while f>=0
  draw(f,Rls,Zload);   
  a=ginput(1);
  f=a(1)*1e3;
end

function draw(f,Rls,Zload)

  %Declare components
  R=5e3;    
  L=150e-3; 
  C=6.8e-9; Rcs=0;
  Zg=50;    %Not used yet

  %Declare sweep
  fmin=1e-9;
  fmax=1e4;
  if f>fmax
    fmax=f;
  end
  f=[f fmin:(fmax-fmin)/1000:fmax];
  w=2*pi*f;
  l=length(w);
  
  w=2*pi*f;
  Zc=Rcs+1./(i.*w.*C);
  Zl=Rls+i*w.*L;
  Zlc=(Zl+Zc).*Zload./(Zl+Zc+Zload);
  Z=R+Zlc;
  Ulc=Zlc./Z;
  Ur=R./Z;
  Uc=Zc./Z;
  Ul=Zl./Z;
  
  figure(998);
  clf
  hold on
  h=polar([0 angle(Ul(1))-angle(Ur(1))], [0 abs(Ul(1))], 'r-');
  set(h,'LineWidth',2)
  h=polar([0 angle(Uc(1))-angle(Ur(1))], [0 abs(Uc(1))], 'b-');
  set(h,'LineWidth',2)
  h=polar([0 angle(Ulc(1))-angle(Ur(1))],[0 abs(Ulc(1))],'y-');
  set(h,'LineWidth',2)
  h=polar([0 0], [0 abs(Ur(1))], 'k-');
  set(h,'LineWidth',2)
  h=polar([0 -angle(Ur(1))], [0 1], 'g-');
  set(h,'LineWidth',2)
  set(gca,'FontSize',14);

  axis([-1.2 1.2 -1.2 1.2])
  Ultext= (['U_L=', num2str(abs(Ul(1)),2), '\angle',num2str((angle(Ul(1))-angle(Ur(1)))*180/pi,3)]);
  Uctext= (['U_C=', num2str(abs(Uc(1)),2), '\angle',num2str((angle(Uc(1))-angle(Ur(1)))*180/pi,3)]);
  Ulctext=(['U_L_C=',num2str(abs(Ulc(1)),2),'\angle',num2str((angle(Ulc(1))-angle(Ur(1)))*180/pi,3)]);
  Urtext= (['U_R=', num2str(abs(Ur(1)),2), '\angle 0']);
  Urlctext=(['U_R_L_C=1\angle',num2str(-angle(Ur(1))*180/pi,3)]);
  hh=legend(Ultext,Uctext,Ulctext,Urtext,Urlctext,2);
  set(hh,'Visible','off')
  axis square
  axis off

  figure(999)
  clf
  subplot(211)
  plot(f(2:l)/1e3,abs(Ulc(2:l)),f(1)/1e3,abs(Ulc(1)),'x','MarkerSize',10)
  grid
  ylabel('U_U_T/U_I_N')
  xlabel('Frequency [kHz]')
  set(gca,'FontSize',14);
  subplot(212)
  plot(f(2:l)/1e3,angle(Ulc(2:l)).*(360/2/pi),...
       f(1)/1e3,angle(Ulc(1)).*(360/2/pi),'x',...
       'MarkerSize',10)
  grid
  ylabel('Phase [^o]')
  xlabel('Frequency [kHz]')
  set(gca,'FontSize',14);
return




































































































