function func_smithchart_mks(Zo,ratio,VSWR);
% SMITHCHART_MKS     Plot Smithchart
%   SMITHCHART_MKS plots Smithchart with 50 Ohms characteristic impedance
%   SMITHCHART_MKS(Zo) plots Smithchart with characteristic impedance (Zo)
%   SMITHCHART_MKS(Zo,ratio)
%       ratio:  real and imag line ratio
%           ratio = 2 (default):  0 25 50 100
%           ratio = 3:  0 16.7 50 150
%   SMITHCHART_MKS(Zo,ratio,VSWR)
%       VSWR Circle, VSWR can between 1 to Inf
%
%   Example:  smithchart_mks(50,2,[1.5 2 3])
%       Smithchart with 50ohms characteristic impedance
%       Line Ratio is 2, [0 25 50 100 Ohms]
%       VSWR circle are 1.5, 2 and 3

if nargin < 1
    Zo = 50;
    ratio = 2;
    VSWR = 0;
elseif nargin < 2
    ratio = 2;  % default line ratio = 2
    VSWR = 0;   % disable VSWR circle
elseif nargin < 3
    VSWR = 0;
end
    
for Zrr = Zo*[0 1/ratio 1 ratio];
    Zr = Zrr + linspace(-2000,2000,1000)*j;
    gamma_Zr = (Zr - Zo)./(Zr + Zo);
    plot(real(gamma_Zr),imag(gamma_Zr),'k:');
    hold on;
end
for Zii = Zo*[-ratio -1 -1/ratio 0 1/ratio 1 ratio]
    Zi = linspace(0,2000,1000) + Zii*j;
    gamma_Zi = (Zi - Zo)./(Zi + Zo);
    plot(real(gamma_Zi),imag(gamma_Zi),'k:');
    hold on;
end
axis square;
xlabel(['Zo=',num2str(Zo),', Line: 0,',num2str(Zo/ratio),',50,',num2str(Zo*ratio),' Ohms']);

if VSWR ~= 0
    xlabel_VSWR = [];
    for i = 1: length(VSWR)
        gamma_vswr_mag = (VSWR(i)-1)/(VSWR(i)+1);
        gamma_vswr_phase = [-180:10:180].*pi/180;
        gamma_vswr_circle = gamma_vswr_mag*(cos(gamma_vswr_phase)+j*sin(gamma_vswr_phase));
        plot(real(gamma_vswr_circle), imag(gamma_vswr_circle),'r:');
        if i ~= length(VSWR)
            xlabel_VSWR = [xlabel_VSWR,num2str(VSWR(i)),','];
        else
            xlabel_VSWR = [xlabel_VSWR,num2str(VSWR(i))];
        end
        hold on;
    end
    xlabel(['Zo=',num2str(Zo),', Line: 0,',num2str(Zo/ratio),',50,',num2str(Zo*ratio),' Ohms; VSWR(Circle) = ',xlabel_VSWR,'']);
end