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

📄 smith.m

📁 smith圆图的matlab实现,快速解决一些电阻电容方面的计算
💻 M
📖 第 1 页 / 共 3 页
字号:
function V_amp_Callback(hObject, eventdata, handles)
% hObject    handle to V_amp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of V_amp


% --- Executes on button press in I_amp.
function I_amp_Callback(hObject, eventdata, handles)
% hObject    handle to I_amp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of I_amp


% --- Executes on button press in VI_amp.
function VI_amp_Calack(hObject, eventdata, handles)
% hObject    handle to VI_amp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of VI_amp

% --- Executes on button press in impedance.
function impedance_Callback(hObject, eventdata, handles)
% hObject    handle to impedance (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of impedance




% --- Executes on slider movement.
function speeder_Callback(hObject, eventdata, handles)
% hObject    handle to speeder (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


% --- Executes during object creation, after setting all properties.
function speeder_CreateFcn(hObject, eventdata, handles)
% hObject    handle to speeder (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on button press in mov_wave.
function mov_wave_Callback(hObject, eventdata, handles)
% hObject    handle to mov_wave (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Z0;

subplot(handles.wave);
cla;
Z = complex(real(Z0), imag(Z0));
[Mg, Ph] =  ConvertZ2Mg_Ph(real(Z0), imag(Z0));
Draw_Moving_Wave(handles,Mg, Ph);


function Draw_Moving_Wave(handles, Mg, Ph)
N_lamda= 2;
fh = @sin;%function hanle 
t = 0
A = 1;
w = 2*pi;
k = 2*pi;
Tl =ConvertMg_Ph2Tl(Mg, Ph);

speed_adj = get(handles.speeder,'Value')*5;
%speed_adj=3;
delta = 0.01 * (1 + round(speed_adj));

m = 0:delta:N_lamda
z=2-m;
%MAX = round(N_lamda / delta) + 1;
MAX = round(N_lamda / delta) + 1;% Rounding is used in case fraction occurs
N = 1;
moving_inci_wave = zeros(1,MAX);
moving_refl_wave = zeros(1,MAX);
while(t< 3* MAX * delta)%display only three cycles
%   z=2-m;
    subplot(handles.wave);
   cla;
    inci_wave = A*fh(w*t - k*(2-z));
    moving_inci_wave(1,[1:N]) = inci_wave(1,[1:N]);
    comb_wave = moving_inci_wave;
% comb_wave=inci_wave;
    if(t> MAX * delta)
        refl_wave = real(Tl*((A*sin(w*t + k*z) + j * A*cos(w*t + k*(2-z)))));
        moving_refl_wave(:,[MAX-N:MAX]) = refl_wave(:,[MAX-N:MAX]);
        comb_wave = inci_wave + moving_refl_wave;
    end
    if(t> 2*MAX*delta)
        comb_wave = inci_wave + refl_wave;
    end
    plot(z, comb_wave);
    set(gca,'XTick',0:0.5:2);
    axis([0, 2, -2*A, 2*A]);
    pause(0.01);%pause for a short while
    t = t+delta;
    N = mod(N + 1, MAX);
end
flag = 1;
% hObject    handle to mov_wave (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

function Tl = ConvertMg_Ph2Tl(Mg, Ph)
Tl = complex(Mg*cos(Ph), Mg*sin(Ph));


function [Mg, Ph] =  ConvertZ2Mg_Ph(Z_Re, Z_Im)
Z = complex(Z_Re, Z_Im);
if(Z == -1)
    errordlg('Divided by zero during calculating of reflection coeficient')';
    %Usually it's impossible for the real part to be negative
end
if(Z == 1)
    Ph = 0;
    Mg = 0;%For zero relection coeficient, set the phase to zero.
else
    Refl_Coef = (Z - 1) / (Z + 1);
    Refl_Coef_Re = real(Refl_Coef);
    Refl_Coef_Im = imag(Refl_Coef);
    Mg = sqrt(Refl_Coef_Re^2 + Refl_Coef_Im^2);
    Ph_temp = atan(Refl_Coef_Im/Refl_Coef_Re);
%Phase value between -0.5pi to 1.5pi
    if (Refl_Coef_Re < 0)
        Ph = Ph_temp + pi;
    else
        Ph = Ph_temp;
    end
end


% --- Executes on button press in sin_stub_cal.
function sin_stub_cal_Callback(hObject, eventdata, handles)
global Z0;
%[Mg, Ph] = ConvertZ2Mg_Ph(real(Z0), imag(Z0));
%Z_Re = str2num(get(handles.real, 'String'));
%Z_Im = str2num(get(handles.imag, 'String'));
Z = complex(real(Z0), imag(Z0));
[Y_Re, Y_Im] = ConvertZ2Y(real(Z0), imag(Z0));
[Mg, Ph] =  ConvertZ2Mg_Ph(real(Z0), imag(Z0));
b1=2*sqrt(Mg^2-Mg^4)/(1-Mg^2);
b2=-b1;
L1=atan(-1/b1)/2/pi;%stub conductance is the opposite of the conductance of load
L2=atan(-1/b2)/2/pi;
if L1<0
    L1=L1+0.5;
end;
if L2<0
    L2=L2+0.5;
end;
D1 = Dist_From_Load(Z, 1/complex(1, -b1)); 
D2 = Dist_From_Load(Z, 1/complex(1, -b2)); 
set(handles.stub_len1, 'string', num2str(L1));
set(handles.stub_len2, 'string', num2str(L2));
set(handles.dis_ld1, 'string', num2str(D1));
set(handles.dis_ld2, 'string', num2str(D2));
set(handles.sin_con1, 'string', num2str(b1));
set(handles.sin_con2, 'string', num2str(b2));

subplot(handles.Smith);
hold on;
Draw_Circle(0.5,0,0.5,[0 1 1]);
Draw_Circle(0,0,Mg,[1 0 0]);
plot(Mg*cos(Ph+pi),Mg*sin(Ph+pi),'k.', 'MarkerSize',6);
text(Mg*cos(Ph+pi),Mg*sin(Ph+pi),'Yin','FontSize',9,'FontUnits','normalized');
[Mg1, Ph1] =  ConvertZ2Mg_Ph(1, b1);
[Mg2, Ph2] =  ConvertZ2Mg_Ph(1, b2);
plot(Mg*cos(Ph1),Mg*sin(Ph1),'k.', 'MarkerSize',6);
plot(Mg*cos(Ph2),Mg*sin(Ph2),'k.', 'MarkerSize',6);
text(Mg*cos(Ph1),Mg*sin(Ph1),'Bingo~','FontSize',9,'FontUnits','normalized');
text(Mg*cos(Ph2),Mg*sin(Ph2),'Bingo~','FontSize',9,'FontUnits','normalized');
hold on;

%function Display_Marker_And_Text(Mg, Ph, label)
%hold on;
%plot(Mg*cos(Ph),Mg*sin(Ph),'k.', 'MarkerSize',6);
%text(Mg*cos(Ph),Mg*sin(Ph),label,'FontSize',9,'FontUnits','normalized');

function Dist = Dist_From_Load(Z_Load, Z_In)
if(Z_In==Inf)
    Dist=0.25;
else
Dist = real(atan((Z_In - Z_Load) / j / (1 - Z_In*Z_Load)) / 2 / pi);
end
if (Dist < 0)
    Dist = Dist + 0.5;
end

function [Y_Re, Y_Im] = ConvertZ2Y(Z_Re, Z_Im)
%ConvertY2Z can also use this one
if (complex(Z_Re, Z_Im) == 0)
    errordlg('Load impedance should not be zero.','input', 'model');
end
Y = 1/complex(Z_Re, Z_Im);
Y_Re = real(Y);
Y_Im = imag(Y);

function [Z_Re, Z_Im] = ConvertY2Z(Y_Re, Y_Im)
[Z_Re, Z_Im] = ConvertZ2Y(Y_Re, Y_Im);

% hObject    handle to sin_stub_cal (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



% --- Executes on selection change in double_d2.
function double_d2_Callback(hObject, eventdata, handles)
% hObject    handle to double_d2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns double_d2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from double_d2


% --- Executes during object creation, after setting all properties.
function double_d2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to double_d2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function double_d1_Callback(hObject, eventdata, handles)
% hObject    handle to double_d1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of double_d1 as text
%        str2double(get(hObject,'String')) returns contents of double_d1 as a double
l = str2double(get(hObject, 'String'));
if isnan(l)
    errordlg('You must input a numerical value.','input', 'model');
end

% --- Executes during object creation, after setting all properties.
function double_d1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to double_d1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on button press in calculate_double.
function calculate_double_Callback(hObject, eventdata, handles)
% hObject    handle to calculate_double (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Z_Real = str2num(get(handles.real, 'String'));
Z_Image = str2num(get(handles.image, 'String'));
Z=complex(Z_Real,Z_Image);
T=(Z-1)/(Z+1);
Yx=-real(T);
Yy=-imag(T);

ht1=findobj('color','m');
ht2=findobj('color','y');
ht3=findobj('color','k');
delete(ht3);
delete(ht1);
delete(ht2);
pause(0.001);

text(-Yx+0.02,-Yy+0.02,'Xin','HitTest','off','color',[0 0 0]);
text(Yx+0.02,Yy+0.02,'Yin','HitTest','off','color',[0 0 0]);
plot(Yx,Yy,'+','color',[0 0 0]);


double_index=get(handles.double_d2,'Value');
switch double_index
    case 1
        d2 = 0.125;
    case 2
        d2 = 0.25;
    case 3
        d2 = 0.375;
end 

d1=str2num(get(handles.double_d1,'string'));
a=str2num(get(handles.real,'string'));
b=str2num(get(handles.image,'string'));
Z_Load=complex(a,b);
[Mg, Ph] = ConvertZ2Mg_Ph(a, b);
Y_Load=1/Z_Load;
x=real(-(Y_Load-1)/(Y_Load+1));
y=imag(-(Y_Load-1)/(Y_Load+1));

[x1,y1]=Rotate_Point(x,y,d1);

if((d2 == 0.125) & ((x1+1/3)^2+y1^2< 1/9)) |((d2 == 0.25) & ((x1+0.5)^2+y1^2<1/4))|((d2 == 0.375) & ((x1+1/3)^2+y1^2< 1/9))
    set(handles.double_realy1,'string','0');
    set(handles.double_imagey1,'string','0'); 
    set(handles.double_imagey31,'string','0');
    set(handles.double_imagey32,'string','0');
    set(handles.double_l21,'string','0');
    set(handles.double_l22,'string','0');
    set(handles.double_l11,'string','0');
    set(handles.double_l12,'string','0');
    errordlg('Blind Area!!!');
else
    Y1=(1-x1-j*y1)/(1+x1+ j*y1);
    g=real(Y1);
    set(handles.double_realy1,'string',g);
    set(handles.double_imagey1,'string',imag(Y1));
end
g=real(Y1);

if d2==0.125
    ya(1)=(-(g^2+1)+((g^2+1)^2-(1+2*g+5*g^2)*(g-1)^2)^(0.5))/(5*g^2+2*g+1);
    xa(1)=-(-ya(1)^2-ya(1))^(0.5);
    ya(2)=(-(g^2+1)-((g^2+1)^2-(1+2*g+5*g^2)*(g-1)^2)^(0.5))/(5*g^2+2*g+1);
    xa(2)=(-ya(2)^2-ya(2))^(0.5);
    [x3 y3]=Rotate_Points(xa, ya, pi/2);
elseif d2==0.375
    ya(1)=((g^2+1)+((g^2+1)^2-(1+2*g+5*g^2)*(g-1)^2)^(0.5))/(5*g^2+2*g+1);
    xa(1)=-(-ya(1)^2+ya(1))^(0.5);
    ya(2)=((g^2+1)-((g^2+1)^2-(1+2*g+5*g^2)*(g-1)^2)^(0.5))/(5*g^2+2*g+1);
    xa(2)=-(-ya(2)^2+ya(2))^(0.5);
    [x3 y3]=Rotate_Points(xa, ya, -pi/2);
elseif d2==0.25
    xa(1)=(1-g)/(3*g+1);
    xa(2)=(1-g)/(3*g+1);
    ya(1)=(xa(2)-xa(2)^2)^(0.5);
    ya(2)=-(xa(2)-xa(2)^2)^(0.5);
    [x3 y3]=Rotate_Points(xa,ya, pi);
end
    
Ya(1)=(1-xa(1)-j*ya(1))/(1+xa(1)+ j*ya(1));
Ya(2)=(1-xa(2)-j*ya(2))/(1+xa(2)+ j*ya(2));
Y3(1)=(1-x3(1)-j*y3(1))/(1+x3(1)+j*y3(1));
Y3(2)=(1-x3(2)-j*y3(2))/(1+x3(2)+j*y3(2));
b(1)=imag(Y3(1));
b(2)=imag(Y3(2));
l2(1)=1/(2*pi)*atan((1+2*(b(1)^2))/(b(1)*(1+b(1)^2)));
l2(2)=1/(2*pi)*atan((1+2*(b(2)^2))/(b(2)*(1+b(2)^2)));
if l2(1)<0
    l2(1)=l2(1)+0.5;
elseif l2(2)<0
    l2(2)=l2(2)+0.5;
end
l1(1)=1/(2*pi)*atan(1/(Ya(1)-Y1));
l1(2)=1/(2*pi)*atan(1/(Ya(2)-Y1));
if l1(1)<0
    l1(1)=l1(1)+0.5;
elseif l1(2)<0
    l1(2)=l1(2)+0.5;
end
set(handles.double_imagey31,'string',b(1));
set(handles.double_imagey32,'string',b(2));
set(handles.double_l21,'string',l2(1));
set(handles.double_l22,'string',l2(2));
set(handles.double_l11,'string',l1(1));
set(handles.double_l12,'string',l1(2));

if d2==0.125
    Draw_Solid_Circle(-2/3, 0, 1/3,'y');
    Draw_Dash_Circle(0, -0.5, 0.5,'m');
elseif d2==0.25
    Draw_Solid_Circle(-0.5, 0, 0.5,'y');
    Draw_Dash_Circle(0.5, 0, 0.5,'m');
else
    Draw_Solid_Circle(-2/3, 0, 1/3,'y');
    Draw_Dash_Circle(0, 0.5, 0.5,'m');
end


function [xr,yr] = Rotate_Point(x, y, theta)
xr = x*cos(theta) +  y*sin(theta);
yr = y*cos(theta) -  x*sin(theta);

function [xr,yr] = Rotate_Points(x, y, theta)
xr = x.*cos(theta) +  y.*sin(theta);
yr = y.*cos(theta) -  x.*sin(theta);


function Draw_Dash_Circle(cx, cy, radius,color)
for i=0:360;
theta = i*pi/180;
x = [radius*cos(theta)+cx;radius*cos(theta+pi/180)+cx];
y = [radius*sin(theta)+cy;radius*sin(theta+pi/180)+cy];
if(rem(i,15)==0)
    pause(0.00001);
end;
if(theta~=2*pi)
plot(x,y,color,'LineWidth',1.5,'LineStyle','--');
end;
end;
text(cx+0.02,cy+0.02,'Ancillary Circle','HitTest','off','color',color);

function Draw_Solid_Circle(cx, cy, radius,color)
for i=0:360;
theta = i'*pi/180;
x = [radius*cos(theta)+cx;radius*cos(theta+pi/180)+cx];
y = [radius*sin(theta)+cy;radius*sin(theta+pi/180)+cy];
if(theta~=2*pi)
   plot(x,y,color);
end;
end;
text(cx+0.02,cy+0.02,'Blind Area','HitTest','off','color',color);


function Draw_Dash_Arch(cx, cy, radius, theta1, theta2, color)
N=fix( abs(theta2-theta1)/pi*180 );
for i=0:N;
theta = theta1+i*(theta2-theta1)/N;
x = [radius*cos(theta)+cx;radius*cos(theta+(theta2-theta1)/N)+cx];
y = [radius*sin(theta)+cy;radius*sin(theta+(theta2-theta1)/N)+cy];
if(rem(i,15)==0)
    pause(0.001);
end;%insert a delayed effect
if(theta~=theta2)
    plot(x,y,color,'LineWidth',2,'LineStyle','--');
end;
end;




⌨️ 快捷键说明

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