⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smith.m

📁 实现smith圆图显示和阻抗匹配
💻 M
📖 第 1 页 / 共 2 页
字号:
  %smith
function ui2(action)
if nargin==0,
    action='initialize';
end
switch(action)                                    %初始化
    case'initialize'
      axes('position',[0 0.26 0.8 0.7]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %圆图背景
 for R=[0 0.2 0.5 1 2 ];
    for X=[-4 -2 -1  -0.5 -0.3 0.3 0.5  1 2 4];%循环输入归一化阻抗
tr=2*pi*(0:0.005:1);
rr=1/(1+R);cr=1-rr;
plot(cr+rr*cos(tr),rr*sin(tr),'g');%画电阻圆
axis square;
hold on;
x=X;
rx=1/x;cx=rx;
tx=2*atan(x)*(0:0.01:1);
if tx<pi
plot(1-rx*sin(tx),cx-rx*cos(tx),'g')%画电抗圆
else
plot(1-rx*sin(tx),-cx-rx*cos(tx),'g')
end
hold on;
  end
end
t=-1:0.001:1;%画横轴
plot(t,0,'g');
axis square;
hold on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%设置各种输出显示控件
h001=uicontrol('style','text','string','红色:电阻圆','position',[60,60,90,30],'fontsize',11,'fontweight','demi','foregroundcolor','r','backgroundcolor',[0.8 0.8 0.8]);
h002=uicontrol('style','text','string','紫色:电抗圆','position',[150,60,90,30],'fontsize',11,'fontweight','demi','foregroundcolor','m','backgroundcolor',[0.8 0.8 0.8]);
h003=uicontrol('style','text','string','蓝色:等反射系数圆','position',[240,60,130,30],'fontsize',11,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]);

h10=uicontrol('style','text','string','数值显示','position',[390,380,160,30],'fontsize',15,'fontweight','demi','foregroundcolor','r','backgroundcolor',[0.8 0.8 0.8]);

h11=uicontrol('style','text','string','归一阻抗=','position',[375,360,70,20],'fontsize',11,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]);  
h110=uicontrol('style','edit','position',[442,360,55,24],'fontsize',8); 
h111=uicontrol('style','text','string','+j','position',[497,360,8,20],'fontsize',8,'foregroundcolor','k','backgroundcolor',[0.8 0.8 0.8]);  
h112=uicontrol('style','edit','position',[505,360,55,24],'fontsize',8); 


h12=uicontrol('style','text','string','归一导纳=','position',[375,330,70,20],'fontsize',11,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]); 
h120=uicontrol('style','edit','position',[442,330,55,24],'fontsize',8); 
h121=uicontrol('style','text','string','+j','position',[497,330,8,20],'fontsize',8,'foregroundcolor','k','backgroundcolor',[0.8 0.8 0.8]);  
h122=uicontrol('style','edit','position',[505,330,55,24],'fontsize',8); 

h13=uicontrol('style','text','string','反射系数=','position',[375,300,70,20],'fontsize',11,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]);  
h130=uicontrol('style','edit','position',[442,300,55,24],'fontsize',8); 
h131=uicontrol('style','text','string','+j','position',[497,300,8,20],'fontsize',8,'foregroundcolor','k','backgroundcolor',[0.8 0.8 0.8]);  
h132=uicontrol('style','edit','position',[505,300,55,24],'fontsize',8); 


h14=uicontrol('style','text','string','行波系数=','position',[375,270,70,20],'fontsize',11,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]); 
h140=uicontrol('style','edit','position',[450,270,100,24],'fontsize',12); 

h15=uicontrol('style','text','string','驻波比=','position',[375,240,70,20],'fontsize',13,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]);    %设置各种输出显示控件
h150=uicontrol('style','edit','position',[450,240,100,24],'fontsize',12); 

h16=uicontrol('style','text','string','相位角=','position',[375,210,70,20],'fontsize',13,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]); 
h160=uicontrol('style','edit','position',[450,210,100,24],'fontsize',12); 

h17=uicontrol('style','text','string','波长数=','position',[375,180,70,20],'fontsize',13,'fontweight','demi','foregroundcolor','b','backgroundcolor',[0.8 0.8 0.8]); 
h170=uicontrol('style','edit','position',[450,180,100,24],'fontsize',12); 

%设置最底一排按钮
h20=uicontrol('style','pushbutton','string','返回首页','position',[20 10 80 50],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击返回首页');
h25=uicontrol('style','pushbutton','string','导纳圆图','position',[110 10 80 50],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击进入导纳圆图');
h21=uicontrol('style','pushbutton','string','行波演示','position',[200 10 80 50],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击进入行波演示');
h22=uicontrol('style','pushbutton','string','驻波演示','position',[290 10 80 50],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击进入驻波演示');
h23=uicontrol('style','pushbutton','string','帮    助','position',[380 10 80 50],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','May I Help You?');
h24=uicontrol('style','pushbutton','string','退    出','position',[470 10 80 50],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击退出演示程序');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%设置最底一排按钮回调函数
set(h20,'callback',['clf;close;main']);
set(h21,'callback',['close;hold off;clf;xing_bo']);
set(h22,'callback',['close;hold off;clf;zhu_bo']); 
set(h23,'callback','smith(''callback23'')');        
set(h24,'callback','smith(''callback24'')');  
set(h25,'callback',['close;hold off;clf;daona']);  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

h1=uicontrol('style','pushbutton','string','取点读数','position',[380,110,80,40],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击取点,即可显示参数');%设置取点和返回孔件
h2=uicontrol('style','pushbutton','string','清   除','position',[470,110,80,40],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击清除各种显示');%设置取点和返回孔件
h3=uicontrol('style','pushbutton','string','输值求点','position',[380,65,80,40],'fontsize',13,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击按键,弹出对话框;输入阻抗值即可定点求值');%设置取点和返回孔件
h4=uicontrol('style','pushbutton','string','传输线求解','position',[470,65,80,40],'fontsize',11,'fontweight','demi','foregroundcolor',[0.2 0.6 0.4],'backgroundcolor',[0.2 0.6 0.4],'tooltipstring','单击按键,输入已知条件即可求解传输线参数');%设置取点和返回孔件
%预留用于设置 动态显示 按钮
%设置中间按钮回调函数  
set(h1,'callback','smith(''callback1'')');%设置对 取点的操作
set(h2,'callback','smith(''callback2'')');%设置对 取点的操作
set(h3,'callback','smith(''callback3'')');%设置对 取点的操作
set(h4,'callback','smith(''callback4'')');%设置对 取点的操作
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%取点画圆
case 'callback1'                            %callback1事件为取点后的具体操作函数
      %首先清除前一次留下的图形和数据
    delete(findobj('color','k'));delete(findobj('color','b'));delete(findobj('color','r'));delete(findobj('color','m'));
    delete(findobj('position',[375,150,70,20]));delete(findobj('position',[450,150,100,24]));
h130=uicontrol('style','edit','string','','position',[442,300,55,24],'fontsize',8); 
h132=uicontrol('style','edit','string','','position',[505,300,55,24],'fontsize',8);                
h110=uicontrol('style','edit','string','','position',[442,360,55,24],'fontsize',8); 
h112=uicontrol('style','edit','string','','position',[505,360,55,24],'fontsize',8); 
h210=uicontrol('style','edit','string','','position',[442,330,55,24],'fontsize',8); 
h212=uicontrol('style','edit','string','','position',[505,330,55,24],'fontsize',8);   
h150=uicontrol('style','edit','string','','position',[450,240,100,24],'fontsize',12); 
h160=uicontrol('style','edit','string','','position',[450,210,100,24],'fontsize',12); 
h140=uicontrol('style','edit','string','','position',[450,270,100,24],'fontsize',12); 
h170=uicontrol('style','edit','string','','position',[450,180,100,24],'fontsize',12);       
         
  
  %鼠标定点数据获取于处理
[U,V]=ginput(1);
if(( U^2+V^2)>1)
    warndlg({'警告:您所取的点已超出圆图范围!','请重新取点!'},'警告');
else
R=(1-U^2-V^2)/((1-U)^2+V^2);%阻抗
X=2*V/((1-U)^2+V^2);
tr=2*pi*(0:0.00001:1);
%z=U+V*j;

cosA=U/sqrt(U^2+V^2);
sinA=V/sqrt(U^2+V^2);
r0=0:0.00001:1;
g0=plot(r0*cosA,r0*sinA,'k','linewidth',1.5);%画相角线
axis square;
hold on;

rr=1/(1+R);cr=1-rr;
g1=plot(cr+rr*cos(tr),rr*sin(tr),'r','linewidth',1.5);%画电阻圆
axis square;
hold on;
x=X;
rx=1/x;cx=rx;
tx=2*atan(x)*(0:0.0001:1);
if tx<pi
g2=plot(1-rx*sin(tx),cx-rx*cos(tx),'m','linewidth',1.5);%画电抗圆
else
g3=plot(1-rx*sin(tx),-cx-rx*cos(tx),'m','linewidth',1.5);
end
hold on;
r=sqrt(U^2+V^2);
g4=plot(r*cos(tr),r*sin(tr),'--','linewidth',1.5);% 等反射系数圆的半径
axis square;
hold on;                                     %当有新的图形输入的时候 原来图形被清除,同时保证 第二次取点的时候背景保留。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%取点后显示输出参数
h130=uicontrol('style','edit','string',U,'position',[442,300,55,24],'fontsize',7.5,'HorizontalAlignment','center'); %反射系数
h132=uicontrol('style','edit','string',V,'position',[505,300,55,24],'fontsize',7.5,'HorizontalAlignment','center');                

R=(1-U^2-V^2)/((1-U)^2+V^2);          %阻抗
X=2*V/((1-U)^2+V^2);
h110=uicontrol('style','edit','string',R,'position',[442,360,55,24],'fontsize',7.5,'HorizontalAlignment','center'); 
h112=uicontrol('style','edit','string',X,'position',[505,360,55,24],'fontsize',7.5,'HorizontalAlignment','center'); 
            
G=R/(R^2+X^2);%导纳
B=-X/(R^2+X^2);
h210=uicontrol('style','edit','string',G,'position',[442,330,55,24],'fontsize',8,'HorizontalAlignment','center'); 
h212=uicontrol('style','edit','string',B,'position',[505,330,55,24],'fontsize',8,'HorizontalAlignment','center');                   

zhu_bo_bi=(1+sqrt(U^2+V^2))/(1-sqrt(U^2+V^2));%驻波比
%zhu_bo_bi
h150=uicontrol('style','edit','string',...
[sprintf('%1.4g',zhu_bo_bi)],'position',[450,240,100,24],'fontsize',12); 
                    
A0=atan(V/U);                                %相位角 
if U<0
      A=(180/pi)*(A0+pi);
elseif V>=0     
       A=(180/pi)*A0;
           else 
                A=(180/pi)*(A0+2*pi);
end    
h160=uicontrol('style','edit','string',...                                    
[sprintf('%1.4g',A),'度'],'position',[450,210,100,24],'fontsize',12); 

if V>=0
    B=(0.5/360)*(180-A);
else
    B=0.75-(0.5/360)*A;
end
h170=uicontrol('style','edit','string',...           %波长数
[sprintf('%1.4g',B)],'position',[450,180,100,24],'fontsize',12); 

xing_bo_xi_shu=1/zhu_bo_bi;                       %行波系数
h140=uicontrol('style','edit','string',...
[sprintf('%1.4g',xing_bo_xi_shu)],'position',[450,270,100,24],'fontsize',12); 


end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%如果清除键被按下,响应以下过程
case'callback2'   
  %先根据颜色属性寻找画上去的 反射圆 阻抗圆 相角线,然后删除
  delete(findobj('color','k'));delete(findobj('color','b'));delete(findobj('color','r'));delete(findobj('color','m'));
    delete(findobj('position',[375,150,70,20]));delete(findobj('position',[450,150,100,24]));
  %清空所有输出数
h130=uicontrol('style','edit','string','','position',[442,300,55,24],'fontsize',8); 
h132=uicontrol('style','edit','string','','position',[505,300,55,24],'fontsize',8);                
h110=uicontrol('style','edit','string','','position',[442,360,55,24],'fontsize',8); 
h112=uicontrol('style','edit','string','','position',[505,360,55,24],'fontsize',8); 
h210=uicontrol('style','edit','string','','position',[442,330,55,24],'fontsize',8); 
h212=uicontrol('style','edit','string','','position',[505,330,55,24],'fontsize',8);   
h150=uicontrol('style','edit','string','','position',[450,240,100,24],'fontsize',12); 
h160=uicontrol('style','edit','string','','position',[450,210,100,24],'fontsize',12); 
h140=uicontrol('style','edit','string','','position',[450,270,100,24],'fontsize',12); 
h170=uicontrol('style','edit','string','','position',[450,180,100,24],'fontsize',12);  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -