?? smith.m
字號:
function varargout = Smith(varargin)
% SMITH M-file for Smith.fig
% SMITH, by itself, creates a new SMITH or raises the existing
% singleton*.
%
% H = SMITH returns the handle to a new SMITH or the handle to
% the existing singleton*.
%
% SMITH('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SMITH.M with the given input arguments.
%
% SMITH('Property','Value',...) creates a new SMITH or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Smith_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Smith_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help Smith
% Last Modified by GUIDE v2.5 13-Mar-2006 16:18:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Smith_OpeningFcn, ...
'gui_OutputFcn', @Smith_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
% End initialization code - DO NOT EDIT
% --- Executes just before Smith is made visible.
function Smith_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Smith (see VARARGIN)
global h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 I X Y pic1 pic2 distance Z0 hv hi hvi him;
I=1;
h1=handles.real;
h2=handles.image;
h3=handles.absolute;
h4=handles.phase;
h5=handles.K;
h6=handles.p;
h7=handles.min_real;
h8=handles.max_real;
h9=handles.min_len;
h10=handles.max_len;
pic1=handles.Smith;
pic2=handles.wave;
set(handles.Dis_slider,'value',2);
distance=0;
hv=handles.V_amp;
hi=handles.I_amp;
hvi=handles.VI_amp;
him=handles.impedance;
set(gcf,'WindowButtonMotionFcn',@Mouse);
Draw_Background;
set(handles.Smith,'Color',get(handles.figure1,'color'));
set(handles.Smith,'XColor',get(handles.figure1,'color'));
set(handles.Smith,'YColor',get(handles.figure1,'color'));
subplot(pic2);
hold on;
t=0:0.01:2;
plot(t,sin(2*pi*t),'-');
hold on;
axes(pic2);
if strcmp(get(hObject,'Visible'),'off')
Draw_Voltage_Amplitude(Mg, Ph);
end
% Choose default command line output for Smith
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Smith wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Smith_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% Draw a circle with the pole at (x0,y0) and a radius r
function Draw_Circle(x0,y0,r,color)
t=0:0.01:2*pi;
x=x0+cos(t)*r;
y=y0+sin(t)*r;
plot(x,y,'-','color',color,'HitTest','off');
% Draw an arch
function Draw_Arch(x0,y0,color)
if(x0 == 1)
if y0>0
a=2*atan(-(y0+1)/(y0-1));
if a>0
t1=a;
else
t1=2*pi+a;
end
t2=1.5*pi;
else
t1=0.5*pi;
t2=pi-2*atan((y0+1)/(y0-1));
end
t=t1:0.01:t2;
x=x0+cos(t)*abs(y0);
y=y0+sin(t)*abs(y0);
plot(x,y,'-','color',color,'HitTest','off');
elseif(x0 == -1)
if y0>0
a=2*atan(-(y0+1)/(y0-1));
if a>0
t1=a;
else
t1=2*pi+a;
end
t2=1.5*pi;
else
t1=0.5*pi;
t2=pi-2*atan((y0+1)/(y0-1));
end
t=t1:0.01:t2;
x=x0-cos(t)*abs(y0);
y=y0+sin(t)*abs(y0);
plot(x,y,'-','color',color,'HitTest','off');
end
function Draw_Background
global pic1;
subplot(pic1);
hold on;
plot([-1 1],[0 0],'-','color',[0.4 0.4 0.4],'HitTest','off');
hold on;
Draw_Circle(0,0,1,[0.4 0.4 0.4]);
hold on;
Draw_Circle(0.25/(0.25+1),0,1/(0.25+1),[0.4 0.4 0.4]);
hold on;
Draw_Circle(0.5/(0.5+1),0,1/(0.5+1),[0.4 0.4 0.4]);
hold on;
Draw_Circle(1/(1+1),0,1/(1+1),[0.4 0.4 0.4]);
hold on;
Draw_Circle(2/(2+1),0,1/(2+1),[0.4 0.4 0.4]);
hold on;
Draw_Circle(-0.25/(0.25+1),0,1/(0.25+1),[0.7 0.7 0.7]);
hold on;
Draw_Circle(-0.5/(0.5+1),0,1/(0.5+1),[0.7 0.7 0.7]);
hold on;
Draw_Circle(-1/(1+1),0,1/(1+1),[0.7 0.7 0.7]);
hold on;
Draw_Circle(-2/(2+1),0,1/(2+1),[0.7 0.7 0.7]);
hold on;
Draw_Arch(1,1/0.5,[0.4 0.4 0.4]);
hold on;
Draw_Arch(1,1/1,[0.4 0.4 0.4]);
hold on;
Draw_Arch(1,1/2,[0.4 0.4 0.4]);
hold on;
Draw_Arch(1,1/4,[0.4 0.4 0.4]);
hold on;
Draw_Arch(1,-2,[0.4 0.4 0.4]);
hold on;
Draw_Arch(1,-1/1,[0.4 0.4 0.4]);
hold on;
Draw_Arch(1,-1/2,[0.4 0.4 0.4]);
hold on;
Draw_Arch(1,-1/4,[0.4 0.4 0.4]);
hold on;
Draw_Arch(-1,1/0.5,[0.7 0.7 0.7]);
hold on;
Draw_Arch(-1,1/1,[0.7 0.7 0.7]);
hold on;
Draw_Arch(-1,1/2,[0.7 0.7 0.7]);
hold on;
Draw_Arch(-1,1/4,[0.7 0.7 0.7]);
hold on;
Draw_Arch(-1,-2,[0.7 0.7 0.7]);
hold on;
Draw_Arch(-1,-1/1,[0.7 0.7 0.7]);
hold on;
Draw_Arch(-1,-1/2,[0.7 0.7 0.7]);
hold on;
Draw_Arch(-1,-1/4,[0.7 0.7 0.7]);
hold on;
X=[0.5 1 2 5];
R=[0.25 0.5 1 2];
Text_Color=[0.5 0 0];
for rr=R
xc=rr/(1+rr); % x position of the center
rd=1/(1+rr); % radius of the circle
text(xc-rd,0,num2str(rr,'%.2f'), ...
'horizontalalignment','left','VerticalAlignment','bottom',...
'color',Text_Color,'Rotation',90,'HitTest','off');
end;
for xx=X
alpha_xx= 2*atan(1/xx);
text(1.1*cos(alpha_xx),1.1*sin(alpha_xx),num2str(xx,'+%.1f'), ...
'horizontalalignment','center','VerticalAlignment','middle',...
'color',Text_Color,'HitTest','off');
text(1.1*cos(alpha_xx),-1.1*sin(alpha_xx),num2str(xx,'-%.1f'), ...
'horizontalalignment','center','VerticalAlignment','middle',...
'color',Text_Color,'HitTest','off');
end;
text(-1.1,0,'0.0', ...
'horizontalalignment','center','VerticalAlignment','middle',...
'color',Text_Color,'HitTest','off');
text(1.1,0,'\infty', ...
'horizontalalignment','center','VerticalAlignment','middle',...
'color',Text_Color,'HitTest','off');
axis image;
function real_Callback(hObject, eventdata, handles)
% hObject handle to real (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 real as text
% str2double(get(hObject,'String')) returns contents of real as a double
Z_Real = str2double(get(hObject, 'String'));
if isnan(Z_Real)
errordlg('You must input a number.','input', 'model');
set(handles.real, 'string', '');
elseif (Z_Real<0)
errordlg('Real part of Zin cannot be negative.');
set(handles.real, 'string', '');
end;
% --- Executes during object creation, after setting all properties.
function real_CreateFcn(hObject, eventdata, handles)
% hObject handle to real (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function image_Callback(hObject, eventdata, handles)
% hObject handle to image (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 image as text
% str2double(get(hObject,'String')) returns contents of image as a double
Z_Image = str2double(get(hObject, 'String'));
if isnan(Z_Image)
errordlg('You must input a number.','input', 'model');
set(handles.image, 'string', '');
end
% --- Executes during object creation, after setting all properties.
function image_CreateFcn(hObject, eventdata, handles)
% hObject handle to image (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Z_set.
function Z_set_Callback(hObject, eventdata, handles)
% hObject handle to Z_set (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see UIDATA)
global h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 I X Y pic1 distance Z0;
subplot(pic1);
cla;
Draw_Background;
Z_Real = str2num(get(handles.real, 'String'));
Z_Image = str2num(get(handles.image, 'String'));
Z=complex(Z_Real,Z_Image);
Z0=((Z-j*tan(2*pi*distance))/(1-j*Z*tan(2*pi*distance)));
absolute=sqrt(((1-Z_Real)^2+Z_Image^2)/((1+Z_Real)^2+Z_Image^2));
phase=atan(Z_Image/(Z_Real-1))-atan(Z_Image/(Z_Real+1));
if (phase>=pi/2)
phase=phase-pi;
elseif(phase <= -pi/2)
phase=phase+pi;
end
p=(1+absolute)/(1-absolute);
K=1/p;
if(Z_Image==0)
Zc1_min=sqrt(Z_Real);
Zc1_max=0;
min_length=0;
max_length=0;
else
Zc1_min=1/sqrt(p);
Zc1_max=sqrt(p);
max_length=phase/4/pi;
if(max_length>0.25)
min_length=max_length-0.25;
else
min_length=max_length+0.25;
end
end
T=(Z-1)/(Z+1);
x=real(T);
y=imag(T);
text(x+0.02,y+0.02,'Zin','HitTest','off','color',[0 0 0]);
plot(x,y,'+','color',[0 0 0]);
Draw_Circle(0,0,abs(T),[1 0 0]);
Draw_Circle((Z_Real/(Z_Real+1)),0,(1/(1+Z_Real)),[0 1 0]);
if Z_Image == 0
plot([-1 1],[0 0],'color',[0 0 1]);
else
Draw_Arch(1,1/Z_Image,[0 0 1]);
end
set(h3,'string',absolute);
set(h4,'string',phase);
set(h5,'string',K);
set(h6,'string',p);
set(h7,'string',Zc1_min);
set(h8,'string',Zc1_max);
set(h9,'string',min_length);
set(h10,'string',max_length);
mode_set_Callback(hObject, eventdata, handles);
function distance_Callback(hObject, eventdata, handles)
% hObject handle to distance (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 distance as text
% str2double(get(hObject,'String')) returns contents of distance as a double
% --- Executes during object creation, after setting all properties.
function distance_CreateFcn(hObject, eventdata, handles)
% hObject handle to distance (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 mouse press over axes background.
function Smith_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to Smith (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global I X Y h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 pic1 distance Z0;
subplot(pic1);
T=X+j*Y;
Z_Re=real((1+X+j*Y)/(1-X-j*Y));
Z_Im=imag((1+X+j*Y)/(1-X-j*Y));
Z=complex(Z_Re,Z_Im);
Z0=((Z-j*tan(2*pi*distance))/(1-j*Z*tan(2*pi*distance)));
absolute=sqrt(((1-Z_Re)^2+Z_Im^2)/((1+Z_Re)^2+Z_Im^2));
phase=atan(Z_Im/(Z_Re-1))-atan(Z_Im/(Z_Re+1));
if (phase>=pi/2)
phase=phase-pi;
elseif(phase <= -pi/2)
phase=phase+pi;
end
p=(1+absolute)/(1-absolute);
K=1/p;
if(Z_Im==0)
Zc1_min=sqrt(Z_Re);
Zc1_max=0;
min_length=0;
max_length=0;
else
Zc1_min=1/sqrt(p);
Zc1_max=sqrt(p);
max_length=phase/4/pi;
if(max_length>0.25)
min_length=max_length-0.25;
else
min_length=max_length+0.25;
end
end
if(I==1)
I=0;
else
I=1;
ht5=findobj('color','y');
ht4=findobj('color','m');
ht6=findobj('color','c');
delete(ht6);
delete(ht5);
delete(ht4);
end
if (I==1)
if(X^2+Y^2<=1)
if(isempty(findobj('color',[1 0 0])))
text(X+0.02,Y+0.02,'Zin','HitTest','off','color',[0 0 0]);
plot(X,Y,'+','color',[0 0 0],'HitTest','off');
Draw_Circle(0,0,abs(T),[1 0 0]);
Draw_Circle((Z_Re/(Z_Re+1)),0,(1/(1+Z_Re)),[0 1 0]);
if Z_Im == 0
plot([-1 1],[0 0],'color',[0 0 1]);
else
Draw_Arch(1,1/Z_Im,[0 0 1]);
end
else
ht1 = findobj('color',[1 0 0]);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -