image thumbnail

MiAD - MATALB integrated Amplifier Design Tool

by

 

10 Apr 2011 (Updated )

MiAD evaluates the Amplifier Stability and Gain Distribution using the s-parameters of a transistor.

HF Amplifier Desin and Analysis Tool

HF Amplifier Desin and Analysis Tool

This project work has been submiited as a part of the ECE527 course Work.
Usage : User provides S-Parameters and the Tool Draws input/output
        stability circle as well as possible design combinations of solutions for required gain.
Program Coded By : Chiranjit Bordoloi
Dated : 04/04/2011
%-----------------------------------------------------------------------------------------------------

function varargout = AmpDesign(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @AmpDesign_OpeningFcn, ...
                   'gui_OutputFcn',  @AmpDesign_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

function AmpDesign_OpeningFcn(hObject, eventdata, handles, varargin)
         handles.output = hObject;
         guidata(hObject, handles);

function varargout = AmpDesign_OutputFcn(hObject, eventdata, handles)
         varargout{1} = handles.output;

function Tag_S11_Mag_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S11_Mag_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_S11_Ang_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S11_Ang_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_S21_Mag_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S21_Mag_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_S21_Ang_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S21_Ang_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_S12_Mag_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S12_Mag_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_S12_Ang_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S12_Ang_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_S22_Mag_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S22_Mag_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_S22_Ang_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_S22_Ang_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function PushB_Design_Callback(hObject, eventdata, handles)
         S11_MAG = str2num(get(handles.Tag_S11_Mag,'String'));
         S12_MAG = str2num(get(handles.Tag_S12_Mag,'String'));
         S21_MAG = str2num(get(handles.Tag_S21_Mag,'String'));
         S22_MAG = str2num(get(handles.Tag_S22_Mag,'String'));

         S11_ANG = str2num(get(handles.Tag_S11_Ang,'String'));
         S12_ANG = str2num(get(handles.Tag_S12_Ang,'String'));
         S21_ANG = str2num(get(handles.Tag_S21_Ang,'String'));
         S22_ANG = str2num(get(handles.Tag_S22_Ang,'String'));

         DESIRED_dB = str2num(get(handles.Tag_Desired_dB,'String'));
         GIVEN_FREQ = str2num(get(handles.Tag_Freq_Value,'String'));

         %-----------------------------------------------------------------------------------------------------
         % initial setup
           clc;              % clean screen
           close all;        % close all opened graphs
           format shortG;    % format the number display

         % define the S-parameters of the transistor
           s11 = S11_MAG*exp(j*(S11_ANG)/180*pi);
           s12 = S12_MAG*exp(j*(S12_ANG)/180*pi);
           s21 = S21_MAG*exp(j*(S21_ANG)/180*pi);
           s22 = S22_MAG*exp(j*(S22_ANG)/180*pi);

         % given frequency
           f = GIVEN_FREQ;

         % detremine delta
           disp('Delta Value is:');
           delta = s11*s22 - s12*s21
           delta_mag = abs(delta)
           delta_ang = angle(delta)*(180/pi)
           sq_delta = (delta_mag)^2;
           disp('-----------------------------------------------------------------');
         % find K factor
           disp ('Stabilty Coefficient is:');
           k = (1 - abs(s11)^2 - abs(s22)^2 + sq_delta)/(2*abs(s12*s21))
           if (2*abs(s12*s21)) ~= 0
               if k >= 1
                   disp('System is Stable');
               else
                   disp('System is NOT Stable');
               end
           else
               disp('System is unconditionally Stable');
           end

           disp('-----------------------------------------------------------------');

         % claculate maximum power transfer
           Gsmax = 1/(1-abs(s11)^2);
           Glmax = 1/(1-abs(s22)^2);
           G0 = abs(s21)^2;
           Gsmax_dB = 10*log10(Gsmax);
           Glmax_dB = 10*log10(Glmax);
           G0_dB = 10*log10(G0);
           disp('       Gsmax       Gsmax_dB');
           disp([Gsmax Gsmax_dB]);
           disp('       Glmax       Glmax_dB');
           disp([Glmax Glmax_dB]);
           disp('       Gtmax       Gtmax_dB');
           disp([G0    G0_dB]);
           disp('-----------------------------------------------------------------');
           disp('Total Available Gain is:');
           Total_dB = Gsmax_dB + Glmax_dB + G0_dB
           disp('-----------------------------------------------------------------');
         % required power
           Rp = DESIRED_dB;
           surplus_dB = round(Rp - G0_dB);

           if Rp > (Gsmax_dB + Glmax_dB + G0_dB)
               disp('Unaccepted Gain');
           else
               % draw Smith Chart
                 SmithChart(2);
                 disp('Gain Distribution Table');

               % loop the stages
                 for i = (fix(Gsmax_dB)):-1:(surplus_dB - fix(Glmax_dB))
                     %if i <= surplus_dB && (surplus_dB-i)<=Glmax          % excluded to show -ve dB
                         Gs = (10^(i/10))/Gsmax;
                         Gl = 10^((surplus_dB-i)/10)/Glmax;

                         Cs = (Gs*conj(s11))/(1-(1-Gs)*(abs(s11))^2);
                         Cs_Mag = abs(Cs);
                         Cs_Ang = angle(Cs)*180/pi;

                         Cl = (Gl*conj(s22))/(1-(1-Gl)*(abs(s22))^2);
                         Cl_Mag = abs(Cl);
                         Cl_Ang = angle(Cl)*180/pi;

                         Rs = (sqrt(1-Gs))*(1-(abs(s11))^2)/(1-(1-Gs)*(abs(s11))^2);
                         Rl = (sqrt(1-Gl))*(1-(abs(s22))^2)/(1-(1-Gl)*(abs(s22))^2);

                         disp('-----------------------------------------------------------------');
                         disp(['     Gsmax_dB      Gsmax        Cs_Mag         Cs_Ang        Rs']);
                         disp([i                Gs Cs_Mag Cs_Ang Rs])

                         disp(['     Glmax_dB      Glmax        Cl_Mag         Cl_Ang        Rl']);
                         disp([(surplus_dB-i)   Gl Cl_Mag Cl_Ang Rl]);

                         % draw constant gain circles
                           hold on;
                           alpha_text = 82/180*pi;
                           ct = cos(alpha_text);
                           st = sin(alpha_text);
                           alpha = 2*pi*(0:0.01:1);

                           N = length(Cs);

                           for n = 1:N
                               color = [0.5*(1+n/N) 0 0];
                               gain = i;
                               plot(real(Cs(n))+Rs(n)*cos(alpha),imag(Cs(n))+Rs(n)*sin(alpha),...
                               'LineWidth',1,'color',color);
                               text(real(Cs(n))+Rs(n)*ct,imag(Cs(n))+Rs(n)*st,num2str(gain,'%.1fdB'), ...
                               'horizontalalignment','left','VerticalAlignment','bottom',...
                               'color',color);
                           end;

                           N = length(Cl);

                           for n = 1:N
                               color = [0 0 0.5*(1+n/N)];
                               gain = surplus_dB-i;
                               plot(real(Cl(n))+Rl(n)*cos(alpha),imag(Cl(n))+Rl(n)*sin(alpha),...
                               'LineWidth',1,'color',color);
                               text(real(Cl(n))+Rl(n)*ct,imag(Cl(n))+Rl(n)*st,num2str(gain,'%.1fdB'), ...
                               'horizontalalignment','left','VerticalAlignment','bottom',...
                               'color',color);
                           end;

                           hold off;
                     end
                 %end
           end
% call back the function
  AmpDesign

function Tag_Freq_Value_Callback(hObject, eventdata, handles)

function Tag_Freq_Value_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_Desired_dB_Callback(hObject, eventdata, handles)
         input = str2num(get(hObject,'String'));
         if (isempty(input))
             set(hObject,'String','0')
         end
         guidata(hObject, handles);

function Tag_Desired_dB_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function PushB_Circle_Callback(hObject, eventdata, handles)
         S11_MAG = str2num(get(handles.Tag_S11_Mag,'String'));
         S12_MAG = str2num(get(handles.Tag_S12_Mag,'String'));
         S21_MAG = str2num(get(handles.Tag_S21_Mag,'String'));
         S22_MAG = str2num(get(handles.Tag_S22_Mag,'String'));

         S11_ANG = str2num(get(handles.Tag_S11_Ang,'String'));
         S12_ANG = str2num(get(handles.Tag_S12_Ang,'String'));
         S21_ANG = str2num(get(handles.Tag_S21_Ang,'String'));
         S22_ANG = str2num(get(handles.Tag_S22_Ang,'String'));

         %-----------------------------------------------------------------------------------------------------
         % initial setup
           clc;              % clean screen
           close all;        % close all opened graphs
           format shortG;    % format the number display

         % define the S-parameters of the transistor
           s11 = S11_MAG*exp(j*(S11_ANG)/180*pi);
           s12 = S12_MAG*exp(j*(S12_ANG)/180*pi);
           s21 = S21_MAG*exp(j*(S21_ANG)/180*pi);
           s22 = S22_MAG*exp(j*(S22_ANG)/180*pi);

         % detremine delta
           delta = s11*s22 - s12*s21;

         % draw input/output stability circle
           Cs = (conj(s11) - conj(delta)*s22)/((abs(s11)^2 - (abs(delta))^2));
           Cs_Mag = abs(Cs);
           Cs_Ang = angle(Cs)*180/pi;

           Cl = (conj(s22) - conj(delta)*s11)/((abs(s22)^2 - (abs(delta))^2));
           Cl_Mag = abs(Cl);
           Cl_Ang = angle(Cl)*180/pi;

           Rs = abs(s12*s21)/abs((abs(s11)^2 - (abs(delta))^2));
           Rl = abs(s12*s21)/abs((abs(s22)^2 - (abs(delta))^2));

           disp('Circle Parameters:');
           disp('-------------------------------------------------------');
           disp(['       Cs_Mag         Cs_Ang        Rs']);
           disp([Cs_Mag Cs_Ang Rs]);
           disp(['       Cl_Mag         Cl_Ang        Rl']);
           disp([Cl_Mag Cl_Ang Rl]);
           disp('-------------------------------------------------------');

         % check stabilty
           if (Cs_Mag - Rs)>1
               disp('I/P Gain is Stable');
           else
               disp('I/P Gain is Unstable');
           end

           if (Cl_Mag - Rl)>1
               disp('O/P Gain is Stable');
           else
               disp('O/P Gain is Unstable');
           end

         % draw radius 1 circle
           radius = 1;
           center = [0,0];
           style = 'g--';
           THETA = linspace(0,2*pi,100);
           RHO = ones(1,100)*radius;
           [X,Y] = pol2cart(THETA,RHO);
           X = X + center(1);
           Y = Y + center(2);
           H = plot(X,Y,style);
           axis square;
           grid on;

         % draw constant gain circles
           hold on;
           alpha_text = 82/180*pi;
           ct = cos(alpha_text);
           st = sin(alpha_text);
           alpha = 2*pi*(0:0.01:1);

           N = length(Cs);

           for n = 1:N
               color = [0.5*(1+n/N) 0 0];
               plot(real(Cs(n))+Rs(n)*cos(alpha),imag(Cs(n))+Rs(n)*sin(alpha),...
               'LineWidth',1,'color',color);
               text(real(Cs(n))+Rs(n)*ct,imag(Cs(n))+Rs(n)*st,'Input Gain Circle', ...
               'horizontalalignment','left','VerticalAlignment','bottom',...
               'color',color);
           end;

           N = length(Cl);

           for n = 1:N
               color = [0 0 0.5*(1+n/N)];
               plot(real(Cl(n))+Rl(n)*cos(alpha),imag(Cl(n))+Rl(n)*sin(alpha),...
               'LineWidth',1,'color',color);
               text(real(Cl(n))+Rl(n)*ct,imag(Cl(n))+Rl(n)*st,'Output Gain Circle', ...
               'horizontalalignment','left','VerticalAlignment','bottom',...
               'color',color);
           end;

           hold off;
         % call back the function
           AmpDesign

function Tag_Real_Part_Callback(hObject, eventdata, handles)

function Tag_Real_Part_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function Tag_Img_Part_Callback(hObject, eventdata, handles)

function Tag_Img_Part_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function edit13_Callback(hObject, eventdata, handles)

function edit13_CreateFcn(hObject, eventdata, handles)
         if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
             set(hObject,'BackgroundColor','white');
         end

function PushB_Convert_Callback(hObject, eventdata, handles)
         clc;              % clean screen
         format shortG;    % format the number displayclc;
         a = str2num(get(handles.Tag_Real_Part,'String'));
         b = str2num(get(handles.Tag_Img_Part,'String'));
         c = a / ((a * a) + (b * b));
         d = -b / ((a * a) + (b * b));
         X = num2str(c);
         Y = num2str(d);
         if d > 0
             Result = strcat(X,'+',Y, 'j')
         else
             Result = strcat(X,Y,'j')
         end
         set(handles.Tag_Result,'String',Result);

function Tag_Result_Callback(hObject, eventdata, handles)

Contact us