📄 tongxin.m
字号:
function varargout = tongxin(varargin)
% TONGXIN M-file for tongxin.fig
% TONGXIN, by itself, creates a new TONGXIN or raises the existing
% singleton*.
%
% H = TONGXIN returns the handle to a new TONGXIN or the handle to
% the existing singleton*.
%
% TONGXIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TONGXIN.M with the given input arguments.
%
% TONGXIN('Property','Value',...) creates a new TONGXIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before tongxin_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to tongxin_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 tongxin
% Last Modified by GUIDE v2.5 19-May-2006 19:48:26
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tongxin_OpeningFcn, ...
'gui_OutputFcn', @tongxin_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 tongxin is made visible.
%The building selected is of 20 floors and 100m long.Every 5m there is a
%partition.Each floor is 5m high.Certainly between two floors there is a
%wall.
%The wall and the partition are the obstacles that make signal has path
%loss.We suppose all the path loss is made by the obstacles referred above.
%The path loss is the same as "914 MHz Path Loss Prediction Models for
%Indoor Wireless Communications in Multifloored Buildings".The path loss of
%this model is accorded with the formula described below.
%The transceiver is "single-chip radio transceiver for the 433/868/915 MHz
%ISM band" whose Typical Sensitivity is -100dBm and Maximum transmit output
%power is 10dBm.
%We simulink the system to check if we can commmunicate wirelessly between
%any two sites.What's more, we can plot the curve of the path loss varying
%with the distance d.
%The fomular is PL(d)[dB]=20.0*log10(4*pi*d/ranta)+p*AF(soft partition)[dB]
%+q*AF(concrete wall)[dB]
%把整栋楼看成一个二维平面,收发端看成是坐标系里有x轴y轴坐标值来描述的点,依此仿真
%这两点间能否进行通信
function f=my(x0,y0,x1,y1)
Pmax=-20;%Maximum transmit output power is 10dBm,that is -20dB
Pmin=-130;%Typical Sensitivity is -100dBm,that is -130dB
ranta=0.328;%电磁波长ranta=3*10^8/(914*10^6)=0.328
AF1=1.39;%the soft partition Attenuation Factor is 1.39dB
AF2=2.38;%the concrete wall Attenuation Factor is 2.38dB
d1=abs(y1-y0);%收发之间的垂直距离。依实际,y的值都是5的倍数
d2=abs(x1-x0);%收发之间的水平距离
d=sqrt(d1^2+d2^2);%收发端的距离
p=floor(d2/5);%收发之间的软隔墙数
q=d1/5;%收发之间的混凝土墙数
PL=20.0*log10(4*pi*d/ranta)+p*AF1+q*AF2;%收发之间的路径损耗
Pr=Pmax-PL;%收端的功率
%检测收发端能否进行通信
if Pr>=-130
f=1;%代表能通信
else
f=0;%代表不能通信
end
function tongxin_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 tongxin (see VARARGIN)
% Choose default command line output for tongxin
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes tongxin wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tongxin_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x0=str2num(get(handles.edit1,'String'));
y0=str2num(get(handles.edit2,'String'));
x1=str2num(get(handles.edit3,'String'));
y1=str2num(get(handles.edit4,'String'));
f=my(x0,y0,x1,y1)
set(handles.edit5,'String',f);
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
% --- 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
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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 edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (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 edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (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 edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ranta=0.328;%电磁波长ranta=3*10^8/(914*10^6)=0.328
AF2=2.38;%the concrete wall Attenuation Factor is 2.38dB
q=0:20;%依楼层数的混凝土墙数
d=q*5;%隔的楼层数决定距离
PL=20.0*log10(4*pi*d/ranta+eps)+q*AF2;%收发之间的路径损耗
plot(q,PL)
axis([0,20,min(PL),max(PL)])
xlabel('混凝土墙数')
ylabel('衰减功率随混凝土墙数的变化(dB)')
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ranta=0.328;%电磁波长ranta=3*10^8/(914*10^6)=0.328
AF1=1.39;%the soft partition Attenuation Factor is 1.39dB
p=0:20;%软隔层数
d=p*5;%软隔层数决定距离
PL=20.0*log10(4*pi*d/ranta+eps)+p*AF1;%收发之间的路径损耗
plot(p,PL)
axis([0,20,min(PL),max(PL)])
xlabel('软隔层数')
ylabel('衰减功率随软隔层数的变化(dB)')
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (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 axes1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -