📄 smith.m
字号:
% Smith vision 1.0 by 王永栋,黄继翔
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
% Edit the above text to modify the response to help smith
% Last Modified by GUIDE v2.5 26-Mar-2006 14:12:44
% 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)
% Choose default command line output for smith
global pic1 pic2 edit1 input text5 text6 flag1;
handles.output = hObject;
edit1=handles.edit1;
text5=handles.text5;
text6=handles.text6;
flag1=1;
pic1=handles.wave;
pic2=handles.smith;
handles.current_d2=0.125;
handles.current_type = 'u';
input = 'z';
background
set(gcf,'WindowButtonMotionFcn',@draw)
set(gcf,'WindowButtonDownFcn',@button)
% 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;
function wave_u(zl)
%函数wave_u画出电压图像
global pic1;
aida = (zl-1)/(zl+1);
abs_a = abs(aida);
angle_a = angle(aida);
x = [0:0.01:2];
u = sqrt(1+abs_a^2+2*abs_a*cos(4*pi*x-angle_a));
subplot(pic1);
h = plot(x, u);
set(gca,'XDir','reverse')
set(gca,'YAxisLocation','right')
function wave_i(zl)
%函数wave_i画出电流图像
global pic1;
aida = (zl-1)/(zl+1);
abs_a = abs(aida);
angle_a = angle(aida);
x = [0:0.01:2];
u = sqrt(1+abs_a^2-2*abs_a*cos(4*pi*x-angle_a));
subplot(pic1);
h = plot(x, u);
set(gca,'XDir','reverse')
set(gca,'YAxisLocation','right')
function wave_z(zl)
%函数WAVE_Z画出阻抗图像
global pic1;
x = [0:0.01:2];
z = (zl+j*tan(2*pi*x))./(1+j*zl*tan(2*pi*x));
real_z = real(z);
imag_z = imag(z);
subplot(pic1);
h = plot(x,real_z,x,imag_z)
set(h,{'Color'},{'r';'b'})
set(gca,'XDir','reverse')
set(gca,'YAxisLocation','right')
function wave_m(zl)
%函数wave_movie画出动态电压图
global pic1;
aida = (zl-1)/(zl+1);
n = 100;
m = moviein(n);
t = 0:10*pi/n:10*pi;
x = 0:.01:2;
nj = length(x);
for i=1:n
for a=1:nj
if t(i)<4*pi
if (2-x(a))<t(i)/2/pi
u(a)=cos(t(i)+2*pi*x(a));
else
u(a)=0;
end;
else
if x(a)<(t(i)-4*pi)/2/pi
u(a)=real(exp(j*t(i))*exp(j*2*pi*x(a))+exp(j*(t(i)-4*pi))*aida*exp(-j*2*pi*x(a)));
else
u(a)=cos(t(i)+2*pi*x(a));
end;
end;
end;
subplot(pic1);
plot(x,u)
axis([0 2 -2 2])
set(gca,'XDir','reverse')
set(gca,'YAxisLocation','right')
m(:,i)=getframe;
end;
function circle(x0,y0,r,color,linetype)
%画圆
t=0:0.01:2*pi;
x=x0+cos(t)*r;
y=y0+sin(t)*r;
plot(x,y,linetype,'LineWidth',1,'color',color);
function arch_x(x0,color)
%画弧
if x0>0
if x0>=1
theta=pi-asin(2*x0/(x0^2+1));
else
theta=asin(2*x0/(x0^2+1));
end;
t=0:0.01:theta;
x=1-sin(t)*abs(1/x0);
y=1/x0-cos(t)*abs(1/x0);
plot(x,y,'-','LineWidth',1,'color',color);
elseif x0<0
if x0<-1
theta=pi+asin(2*x0/(x0^2+1));
else
theta=-asin(2*x0/(x0^2+1));
end;
t=0:0.01:theta;
x=1-sin(t)*abs(1/x0);
y=1/x0+cos(t)*abs(1/x0);
plot(x,y,'-','LineWidth',1,'color',color);
end
function background
%原图背景
global pic2;
subplot(pic2);
axis([-1,1,-1,1]);
axis off;
box off;
circle(0,0,1,'k','-');
hold on;
circle(0,0,0.75,'k','--');
hold on;
circle(0,0,0.5,'k','--');
hold on;
circle(0,0,0.25,'k','--');
hold on;
circle(2/3,0,1/3,[0.3,0.4,0.3],'-');
hold on;
circle(1/2,0,1/2,[0.3,0.4,0.3],'-');
hold on;
circle(1/3,0,2/3,[0.3,0.4,0.3],'-');
hold on;
circle(1/5,0,4/5,[0.3,0.4,0.3],'-');
hold on;
arch_x(4,[0.3,0.4,0.3]);
hold on;
arch_x(-4,[0.3,0.4,0.3]);
hold on;
arch_x(2,[0.3,0.4,0.3]);
hold on;
arch_x(-2,[0.3,0.4,0.3]);
hold on;
arch_x(1,[0.3,0.4,0.3]);
hold on;
arch_x(-1,[0.3,0.4,0.3]);
hold on;
arch_x(0.5,[0.3,0.4,0.3]);
hold on;
arch_x(-0.5,[0.3,0.4,0.3]);
hold on;
text(1.05*cos(pi/7),1.05*sin(pi/7),'x=4');
text(1.05*cos(pi/7),-1.05*sin(pi/7),'x=-4');
text(1.05*cos(pi/2),1.05*sin(pi/2),'x=1');
text(-1.05*cos(pi/2),-1.05*sin(pi/2),'x=-1')
text(1.05*cos(pi/3.5),1.05*sin(pi/3.5),'x=2');
text(1.05*cos(pi/3.5),-1.05*sin(pi/3.5),'x=-2');
text(-0.78,0.83,'x=0.5');
text(-0.78,-0.83,'x=0.5');
hold on;
axis off;
function d = distance(zl, z)
%函数distance返回输入阻抗为z的点距负载zl的距离
if(z==Inf)
d=0.25;
else
d = real(atan((z - zl)/j/(1-z*zl))/2/pi);
end
if (d<0)
d = d+0.5;
end
function single_stub_match(r,x)
global pic2;
subplot(pic2);
background;
hold on;
gamma=abs((r+x*i-1)/(r+x*i+1));
circle(0,0,gamma,'b','-');
pause(0.5);
circle(0,0,gamma,'w','-');
pause(0.5);
circle(0,0,gamma,'b','-');
pause(0.5);
circle(0,0,gamma,'w','-');
pause(0.5);
circle(0,0,gamma,'b','-');
pause(1);
circle(0.5,0,0.5,'r','-');
pause(0.5);
circle(0.5,0,0.5,'w','-');
pause(0.5);
circle(0.5,0,0.5,'r','-');
pause(0.5);
circle(0.5,0,0.5,'w','-');
pause(0.5);
circle(0.5,0,0.5,'r','-');
plot(gamma^2,sqrt(gamma^2-gamma^4),'kx', 'MarkerSize',10,'LineWidth',2);
plot(gamma^2,-sqrt(gamma^2-gamma^4),'kx','MarkerSize',10,'LineWidth',2);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
global input;
if input == 'z'
zl = str2double(get(hObject,'String'));
if isnan(zl)
errordlg('You must input a number.');
set(handles.edit1, 'string', '');
elseif real(zl<0)
errordlg('The real part cannot be negative.');
set(handles.edit1, 'string', '');
end
else
zl = 1/str2double(get(hObject,'String'));
if isnan(zl)
errordlg('You must input a number.');
set(handles.edit1, 'string', '');
elseif real(zl<0)
errordlg('The real part cannot be negative.');
set(handles.edit1, 'string', '');
end
end
function button(hObject, eventdata, handles)
global flag1;
if flag1 == 1
flag1 = 0;
else
flag1 = 1;
end;
function draw(hObject, eventdata, handles)
global pic2 edit1 input text5 text6 flag1;
if flag1 ==1
p = get(gca,'CurrentPoint');
x = p(1);
y = p(3);
if x^2+y^2 < 1
background;
hold on;
axis([-1,1,-1,1]);
aida = x+y*j;
angle_a = angle(aida);
if angle_a<0
angle_a = angle_a+2*pi;
end;
zmax = angle_a/4/pi;
if angle_a<pi
zmin = (angle_a+pi)/4/pi;
else
zmin = (angle_a-pi)/4/pi;
end;
set(text5,'string',zmax);
set(text6,'string',zmin);
r1 = abs(aida);
zl = (1+aida)/(1-aida);
if(input == 'z')
set(edit1,'string',num2str(zl));
else
set(edit1,'string',num2str(1/zl));
end
r2 = 1/(1+real(zl));
plot(x,y,'x');
circle(0,0,r1,'r','-');
circle(real(zl)/(1+real(zl)),0,r2,'g','-');
arch_x(imag(zl),'b');
hold off;
end
end
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
zl = str2double(get(handles.edit1,'string'));
switch handles.current_type;
case 'u'
wave_u(zl)
case 'i'
wave_i(zl)
case 'z'
wave_z(zl)
case 'm'
set(handles.pushbutton2,'Enable','off');
wave_m(zl)
set(handles.pushbutton2,'Enable','on');
end;
background
guidata(hObject,handles)
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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 popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
val = get(hObject,'Value');
str = get(hObject, 'String');
zl = str2double(get(handles.edit1,'string'));
switch str{val};
case '电压波形'
handles.current_type = 'u';
case '电流波形'
handles.current_type = 'i';
case '阻抗波形'
handles.current_type = 'z';
case '动态图'
handles.current_type = 'm';
end
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -