(一)主程序变量说明:输入变量:zo 传输线特性阻抗zl 传输线终端负载阻抗Er 传输线介电常数f 传输电磁波的频率由输入变量计算得出的变量:w 传输电磁波的数字角频率len 传输电磁波的相波长beita 相移常数gama 传输线个点反射系数复值gamal 传输线终端反射系数的模rou 驻波系数k 行波系数Zi 传输线各点输入阻抗的复值Ui 传输线各点输入电压的复值Uo 传输线各点输出电压的复值Uit 传输线各点输入电压的瞬时值Uot 传输线各点输出电压的瞬时值Ii 传输线各点输入电流的复值Io 传输线各点输出电流的复值Is 传输线各点合成电流的复值Us 传输线各点合成电压的复值Ist 传输线各点合成电流的瞬时值Ust 传输线各点合成电压的瞬时值ph 传输线各点合成电压的相位(二)主程序流程说明:本程序的界面中共有三个输入编辑框,三个输出编辑框和五个波形显示窗口,分别用来输入:传输线特性阻抗Z0、传输线终端负载阻抗Z L、传输的电磁波的频率f、传输线传输介质的相对介电常数εr;输出:传输线的终端反射系数ΓL、行波系数ρ、驻波系数K;具体的程序思路如下:1.由输入编辑框获得用户输入的Z0、Z L、f和εr;2.在“开始”按钮的callback函数中进行运算,并控制各个axis的显示;3.图形的动态显示由一个while循环实现,并由全局标记变量flag控制;4.在“停止”按钮的callback函数中令flag = 1,while循环跳出。
(三)程序运行效果1.行波演示中端接匹配负载zo = zl = 50Ω2.驻波演示1)终端短路zo = 50Ωzl = 02)终端开路zo = 50Ωzl = inf3)终端接纯电抗负载zo = 50Ωzl = X * j3.行驻波演示(四)主程序代码function varargout = StatusAnaly(varargin)%********************************************************%% Copyright (C), 2009-2012,Lyric %% FileName: StatusAnaly.m %% Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 %%********************************************************%% STATUSANALY M-file for StatusAnaly.fig% STATUSANALY, by itself, creates a new STATUSANALY or raises the existing% singleton*.%% H = STATUSANALY returns the handle to a new STATUSANALY or the handle to % the existing singleton*.%% STATUSANALY('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in STATUSANALY.M with the given input arguments. %% STATUSANALY('Property','Value',...) creates a new STATUSANALY or raises the % existing singleton*. Starting from the left, property value pairs are% applied to the GUI before StatusAnaly_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to StatusAnaly_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 StatusAnaly% Last Modified by GUIDE v2.5 11-May-2010 14:30:20% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @StatusAnaly_OpeningFcn, ...'gui_OutputFcn', @StatusAnaly_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before StatusAnaly is made visible.function StatusAnaly_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 StatusAnaly (see VARARGIN)% Choose default command line output for StatusAnalyhandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes StatusAnaly wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = StatusAnaly_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 structurevarargout{1} = handles.output;function edit_zo_Callback(hObject, eventdata, handles)% hObject handle to edit_zo (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 edit_zo as text% str2double(get(hObject,'String')) returns contents of edit_zo as a double% --- Executes during object creation, after setting all properties.function edit_zo_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_zo (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');endfunction edit_zl_Callback(hObject, eventdata, handles)% hObject handle to edit_zl (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 edit_zl as text% str2double(get(hObject,'String')) returns contents of edit_zl as a double% --- Executes during object creation, after setting all properties.function edit_zl_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_zl (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 btn_begin.function btn_begin_Callback(hObject, eventdata, handles)% hObject handle to btn_begin (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%获得传输线特性阻抗temp = get(handles.edit_zo, 'string');zo = str2num(temp);%获得传输线负载阻抗temp = get(handles.edit_zl, 'string');zl = str2num(temp);%获得传输介质相对介电常数temp = get(handles.edit_Er, 'string');Er = str2num(temp);%获得传输线上传播的电磁波频率temp = get(handles.edit_f, 'string');f = str2num(temp) * 1000000;w = 2 * pi * f;%获得相波长、相位常数len = GetLen(f, Er);L = 2 * len; %横坐标范围L为两倍的相波长beita = GetBeita(f, Er);z = linspace(0, L, 200);zn = z ./ len; %zn为相对于相波长len归一化的横坐标%获得反射系数[gamal, gama] = GetGama(zo, zl, beita, z);set(handles.edit_gama, 'string', num2str(abs(gamal)));%获得驻波系数rou = GetRou(gamal);set(handles.edit_rou, 'string', num2str(rou));%获得行波系数k = 1 / rou;set(handles.edit_k, 'string', num2str(k));t = 0;Ts = 0.06;fs = 4 * f;%标记变量,当flag = 1 时图像停止,当flag = 0 时图像继续运动global flagflag = 0;while flag == 0%获得传输线输入阻抗Zi = GetZi(zo, gama);%绘制传输线输入阻抗plot(handles.axes_zi, zn, abs(Zi));if max(abs(Zi)) > 500limzL = 0;limzH = 500;elseif (max(abs(Zi)) - min(abs(Zi))) < 1limzL = min(abs(Zi)) - 1;limzH = max(abs(Zi)) + 1;elselimzL = min(abs(Zi));limzH = max(abs(Zi));endaxis(handles.axes_zi, [0, max(zn), limzL, limzH]);title(handles.axes_zi, '输入电阻波形');xlabel(handles.axes_zi, 'z(lamda)');ylabel(handles.axes_zi, 'Zin(ohmic)');%获得传输线输入输出电压[Ui, Uo] = GetUio(beita, gama, z);[Uit, Uot] = GetUiot(Ui, Uo, f, t);%绘制传输线输入输出电压plot(handles.axes_u, zn, Uit, 'b', zn, Uot, 'r');axis(handles.axes_u, [0, max(zn), -1, 1]);title(handles.axes_u, '入射和反射电压波形');xlabel(handles.axes_u, 'z(lamda)');ylabel(handles.axes_u, 'Ui/Uo(V)');legend(handles.axes_u, 'Ui', 'Uo', 2);%获得传输线入射和反射电流[Ii, Io] = GetIio(Ui, zo, gama);%获得传输线合成电压、电流[Is, Us] = GetIUs(Ui, Uo, Ii, Io);[Ist, Ust] = GetIUst(Is, Us, f, t);%绘制传输线合成电压、电流plot(handles.axes_us, zn, Ust);limu = 1 + abs(gamal);axis(handles.axes_us, [0, max(zn), -limu, limu]);title(handles.axes_us, '合成电压波形');xlabel(handles.axes_us, 'z(lamda)');ylabel(handles.axes_us, 'Us(V)');plot(handles.axes_is, zn, Ist);limi = (1 + abs(gamal)) / zo;axis(handles.axes_is, [0, max(zn), -limi, limi]);title(handles.axes_is, '合成电流波形');xlabel(handles.axes_is, 'z(lamda)');ylabel(handles.axes_is, 'Is(A)');%获得并绘制电压相位ph = angle(Us .* exp(1i * 2 * pi * f /fs * t));plot(handles.axes_ph, zn, ph / pi);axis(handles.axes_ph, [0, max(zn), -1.1, 1.1]);title(handles.axes_ph, '合成电压相位波形');xlabel(handles.axes_ph, 'z(lamda)');ylabel(handles.axes_ph, 'thita(pi)');t = t + Ts;pause(Ts);end% --- Executes on button press in btn_stop.function btn_stop_Callback(hObject, eventdata, handles)% hObject handle to btn_stop (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global flagflag = 1;function edit_gama_Callback(hObject, eventdata, handles)% hObject handle to edit_gama (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 edit_gama as text% str2double(get(hObject,'String')) returns contents of edit_gama as a double% --- Executes during object creation, after setting all properties.function edit_gama_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_gama (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');endfunction edit_rou_Callback(hObject, eventdata, handles)% hObject handle to edit_rou (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 edit_rou as text% str2double(get(hObject,'String')) returns contents of edit_rou as a double% --- Executes during object creation, after setting all properties.function edit_rou_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_rou (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');endfunction edit_k_Callback(hObject, eventdata, handles)% hObject handle to edit_k (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 edit_k as text% str2double(get(hObject,'String')) returns contents of edit_k as a double% --- Executes during object creation, after setting all properties.function edit_k_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_k (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');endfunction edit_f_Callback(hObject, eventdata, handles)% hObject handle to edit_f (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 edit_f as text% str2double(get(hObject,'String')) returns contents of edit_f as a double% --- Executes during object creation, after setting all properties.function edit_f_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_f (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');endfunction edit_Er_Callback(hObject, eventdata, handles)% hObject handle to edit_Er (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 edit_Er as text% str2double(get(hObject,'String')) returns contents of edit_Er as a double% --- Executes during object creation, after setting all properties.function edit_Er_CreateFcn(hObject, eventdata, handles)% hObject handle to edit_Er (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 during object creation, after setting all properties.function axes_u_CreateFcn(hObject, eventdata, handles)% hObject handle to axes_u (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate axes_u(五)子程序代码(按照在主程序中出现的顺序排列)function Len = GetLen(f, Er)%********************************************************%% Copyright (C), 2009-2012,Lyric %% FileName: GetLen.m %% Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 %%********************************************************%% Function: GetLen% Description: 获得传输线上所传输的电磁波的相波长% Called By: StatusAnaly.m% Input: f 传输线中所传输电磁波的频率% Er 传输线中传输介质的相对介电常数% Return: Len 传输线中所传电磁波的相波长C = 300000000;Len = C / f / sqrt(Er);function Beita = GetBeita(f, Er)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetBeita.m %% Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 %%********************************************************%% Function: GetBeita% Description: get the phase-shift constant 获得相移常数% Called By: StatusAnaly.m% Input: f the freqency of the wave propagated in the medium % Er the relative permittivity of the medium% Return: Beita the phase-shift constant of the wavepi = 3.1415926;%真空中的电磁波速度,单位:m/sC=300000000;%数字角频率W = 2 * pi * f;Beita = W * sqrt(Er) / C;function [GamaL, Gama] = GetGama(zo, zl, beita, z)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetGama.m % % Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 %%********************************************************%% Function: GetGama% Description: get the reflection coefficient 获得反射系数% Called By: StatusAnaly.m% Input: zo the characteristic impedance of the transmission line % zl the load impedance of the transmission line% beita the phase-shift constant of the transmission line% z 相对于相波长归一化的横坐标% Return: GamaL 反射系数的模值% Gama 反射系数的复值if zl == infGamaL = 1;elseGamaL = (zl - zo) / (zl + zo);endGama = abs(GamaL) .* exp(-1i * 2 .* beita .* z);function Rou = GetRou(gamal)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetRou.m % % Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 % %********************************************************%% Function: GetRou% Description: 获得传输线上的驻波系数% Called By: StatusAnaly.m% Input: gamal 传输线上的反射系数% Return: Rou 传输线上的驻波系数Gamal = abs(gamal);Rou = (1 + Gamal) / (1 - Gamal);function Zi = GetZi(zo, gama)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetZi.m % % Author: Lyric % % Version: 1.0 %% Date: 2010-05-11 %%********************************************************%% Function: GetZi% Description: 获得传输线上各点输入阻抗的复值% Called By: StatusAnaly.m% Input: zo 传输线的特性阻抗% gama 传输线上反射系数的复值% Return: Zi 传输线上各点输入阻抗的复值Zi = zo .* ((1 + gama) ./ (1 - gama));function [Ui, Uo] = GetUio(beita, gama, z)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetUio.m % % Author: Lyric % % Version: 1.0 %% Date: 2010-05-11 % %********************************************************%% Function: GetUio% Description: 获得输入输出电压的复值% Called By: StatusAnaly.m% Input: beita 传输线上电磁波的相移常数% gama 传输线上电磁波的反射系数% z 相对于相波长归一化的横坐标% Return: Ui 输入电压复值% Uo 输出电压复值% 假定输入电压模值为1U = 1;Ui = U * exp(1i * beita * z);Uo = Ui .* gama;function [Uit, Uot] = GetUiot(Ui, Uo, f, t)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetUiot.m % % Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 % %********************************************************%% Function: GetUiot% Description: 获得输入输出电压瞬时值% Called By: StatusAnaly.m% Input: Ui 输入电压复值% Uo 输出电压复值% f 传输线上所传的电磁波的频率% t 当前时刻% Return: Uit 输入电压瞬时值% Uot 输出电压瞬时值%获得输入输出电压瞬时值fs = 4 * f;Uit = real(Ui .* exp(1i * 2 * pi * f / fs * t));Uot = real(Uo .* exp(1i * 2 * pi * f / fs * t));function [Ii, Io] = GetIio(Ui, zo, gama)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetIio.m %% Author: Lyric % % Version: 1.0 %% Date: 2010-05-11 % %********************************************************%% Function: GetIio% Description: 获得输入和输出电流的复值% Called By: StatusAnaly.m% Input: Ui 输入电压的复值% zo 传输线特征阻抗% gama 反射系数复值% Return: Ii 输入电流复值% Io 输出电流复值%获得输入输出电流复值Ii = Ui / zo;Io = - Ii .* gama;function [Is, Us] = GetIUs(Ui, Uo, Ii, Io)%********************************************************% % Copyright (C), 2009-2012,Lyric %% FileName: GetIUs.m % % Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 % %********************************************************%% Function: GetIUs% Description: 获得合成电压电流复值% Called By: StatusAnaly.m% Input: Ui 输入电压复值% Uo 输出电压复值% Ii 输入电流复值% Io 输出电流复值% Return: Is 合成电流复值% Us 合成电压复值%获得合成电压电流复值%I2 = 1;%U2 = Zl * I2;%Us = U2 * cos(beita .* z) + 1i * Zo * I2 * sin(beita .* z);%Is = 1i * U2 /Zo * sin(beita .* z) + I2 * cos(beita .* z);Us = Ui + Uo;Is = Ii + Io;function [Ist, Ust] = GetIUst(Is, Us, f, t)%********************************************************%% Copyright (C), 2009-2012,Lyric %% FileName: GetIUst.m %% Author: Lyric %% Version: 1.0 %% Date: 2010-05-11 %%********************************************************%% Function: GetIUst% Description: 获得合成电压电流瞬时值% Called By: StatusAnaly.m% Input: Is 合成电流复值% Us 合成电压复值% f 电磁波频率% t 当前时间% Return: Ist 合成电流瞬时值% Ust 合成电压瞬时值%获得合成电压电流瞬时值fs = 4 * f;Ust = real(Us .* exp(1i * 2 * pi * f / fs * t));Ist = real(Is .* exp(1i * 2 * pi * f / fs * t));这是在下的大作业,新手编程,颇为拙劣,还望海涵。