MATLAB Codes.docx

上传人:b****7 文档编号:10428597 上传时间:2023-02-11 格式:DOCX 页数:14 大小:20.22KB
下载 相关 举报
MATLAB Codes.docx_第1页
第1页 / 共14页
MATLAB Codes.docx_第2页
第2页 / 共14页
MATLAB Codes.docx_第3页
第3页 / 共14页
MATLAB Codes.docx_第4页
第4页 / 共14页
MATLAB Codes.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

MATLAB Codes.docx

《MATLAB Codes.docx》由会员分享,可在线阅读,更多相关《MATLAB Codes.docx(14页珍藏版)》请在冰豆网上搜索。

MATLAB Codes.docx

MATLABCodes

MATLABCode

MATLABPropagationSimulation

TheMATLABpropagationsimulationexistsasamainfunction(Propagation_Simulation.m)thatcallsanumberofsub-functionstoperformsimpletasks.Includedbelowisthemainfunction,aswellasthesub-functionsthatwerewrittenforthisproject.

PropagationModelingFunction

functionRSS=Propagation_Simulation(wap,walls,fname)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%wap.positx-ycoordinatesofWAP%wap.powermeasuredpowerofWAPat1m%wap.MACMACaddressofWAP%wallslistofwallelements(startx-y,endx-y,WAF)%fnamefilenameforoutput%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%start=clock;%Starttimertomeasureanddisplayexecutiontime%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%AdjustableParameters%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n1=2.5;%Pathlossexponent(PLE)withinthebreakpointdistance

n2=3.33;%Pathlossexponent(PLE)outsidethebreakpointdistance

Dbp=10;%BreakpointdistanceinmetersRes=8;%Resolutionofsimulation(inpointspermeter)

thresh_min=-100;%ValueindBmbelowwhichdatawillnotbeplottedthresh_max=0;%ValueindBmabovewhichdatawillbeclipped%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Setup%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%locatemapcorrectlyonXYplane

walls=wall_list_prep(walls,Res);%calculatelengthofeachwall

wall_length=((walls(:

1)-walls(:

3)).^2...+(walls(:

2)-walls(:

4)).^2).^.5;

wap.posit=round(wap.posit*Res)/Res;%determinebuildingdimensionsbuilding_size=[ceil(Res*max([walls(:

1);walls(:

3)]))/Res...ceil(Res*max([walls(:

2);walls(:

4)]))/Res];

%determinenumberofwallelements

num_walls=size(walls,1);%determinsdimensionsofmatricesneededforcalculations

mat_size=[num_wallsbuilding_size

(1)*Res+1building_size

(2)*Res+1];%expandwallvectorinformationintomatrices

WALL_X1=expand2fit(walls(:

1),mat_size);WALL_Y1=expand2fit(walls(:

2),mat_size);

WALL_X2=expand2fit(walls(:

3),mat_size);WALL_Y2=expand2fit(walls(:

4),mat_size);WALL_AF=expand2fit(walls(:

5),mat_size);%createcoordinatematricesx=repmat(0:

1/Res:

building_size

(1),building_size

(2)*Res+1,1)';y=repmat(0:

1/Res:

building_size

(2),building_size

(1)*Res+1,1);X=expand2fit(x,mat_size);Y=expand2fit(y,mat_size);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Calculations%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%calculatedistancefromWAPtoeachpointinbuilding

path_dist=((x-wap.posit

(1)).^2+(y-wap.posit

(2)).^2).^.5;%calculateslopeofpathfromWAPateachpointpath_m=make_finite((y-wap.posit

(2))./(x-wap.posit

(1)));

PATH_M=expand2fit(path_m,mat_size);%calculate(finite)inverseofpathslopeateachpoint

path_m_inv=make_finite(1./path_m);%calculate(finite)wallslopeateachpoint

wall_m=make_finite((walls(:

2)-walls(:

4))./(walls(:

1)-walls(:

3)));

WALL_M=expand2fit(wall_m,mat_size);%calculate(finite)inverseofwallslopeateachpoint

wall_m_inv=make_finite(1./wall_m);%calculatexandyinterceptsofallwallsandpaths

WALL_X_INT=expand2fit(walls(:

1)-walls(:

2).*wall_m_inv,mat_size);WALL_Y_INT=expand2fit(walls(:

2)-walls(:

1).*wall_m,mat_size);PATH_X_INT=expand2fit(wap.posit

(1)-wap.posit

(2).*path_m_inv,mat_size);PATH_Y_INT=expand2fit(wap.posit

(2)-wap.posit

(1).*path_m,mat_size);%calculatefreespacelosses,includingbreakpoint(Cheunget.al.)

proploss_near=(10*log10((path_dist).^n1));proploss_far=(10*(log10((Dbp).^n1)+log10((path_dist/Dbp).^n2)));proploss_near(path_dist>Dbp)=proploss_far(path_dist>Dbp);proploss_combined=proploss_near;

%calculateanglebetweeneachpathandeachwall

THETA=abs(atan((WALL_M-PATH_M)./(1+WALL_M.*PATH_M)));%calculatexandycoordinatesofallintersectionsbetweenpathandwall

X_INTSCT=(PATH_Y_INT-WALL_Y_INT)./(WALL_M-PATH_M);Y_INTSCT=WALL_M.*PATH_M.*(PATH_X_INT-WALL_X_INT)./(PATH_M-WALL_M);Y_INTSCT(PATH_M==0&WALL_M==-intmax)=wap.posit

(2);%forwalls||or|_tox-axis,fixintercepterrorscausedbyinf.slopes

X_INTSCT(walls(:

1)==walls(:

3),:

:

)=...repmat(walls(walls(:

1)==walls(:

3),1),...[1building_size

(1)*Res+1building_size

(2)*Res+1]);Y_INTSCT(walls(:

2)==walls(:

4),:

:

)=...repmat(walls(walls(:

2)==walls(:

4),2),...[1building_size

(1)*Res+1building_size

(2)*Res+1]);%determinedBminterferencevalueforeachwallatallpointsINTERFERENCE=WALL_AF./(.5*(1+max(sin(THETA),.1)));%determinewhichwallsinterferewithpathtowhichpoints

INTERFERE_PATH=order_test(wap.posit

(1),X_INTSCT,X)&...order_test(wap.posit

(2),Y_INTSCT,Y);INTERFERE_WALL=order_test(WALL_X1,X_INTSCT,WALL_X2)&...order_test(WALL_Y1,Y_INTSCT,WALL_Y2);INTERFERE=INTERFERE_PATH&INTERFERE_WALL;%setinterferencevaluesforwallsthatdon'tinterferetozeroINTERFERENCE(~INTERFERE)=0;%addwalllossestofreespacelosses

proploss_combined=proploss_combined+squeeze(sum(INTERFERENCE,1));pl_new=10.^(-proploss_combined/10);%%%%%%%%%%%Diffraction%%%%%%%%%%%%initializevectorthatwillholdlistofdiffractedcorners

diffracted=wap.posit;%displaytimetocompletenonmultipathsimulation

now=clock-start;display(['Timeelapsed:

'num2str(now(6)+60*now(5))])%initializevariableforWAPtoedgepathlosses

pl=zeros(2*num_walls);%pre-calculateanglesfordiffractionsimulation

dist_end1=((walls(:

1)-wap.posit

(1)).^2...+(walls(:

2)-wap.posit

(2)).^2).^.5;dist_end2=((walls(:

3)-wap.posit

(1)).^2...+(walls(:

4)-wap.posit

(2)).^2).^.5;theta1_end1=acos(((dist_end1.^2+wall_length.^2-dist_end2.^2))..../(2.*dist_end1.*wall_length));

theta1_end2=acos(((dist_end2.^2+wall_length.^2-dist_end1.^2))..../(2.*dist_end2.*wall_length));%looptotestfordiffractionateachendofeachwall

fori=1:

2*num_walls%determinewhichwallofwhichendtotest

wall=ceil(i/2);wall_end=mod(i+1,2)+1;%determinewhetherornotwallendisacornerfordiffraction[will_diffractdiffracted]=...is_corner(walls,wall,wall_end,wap.posit,Res,diffracted);%ifpointiscorneratwhichdiffractwilloccur

ifwill_diffract%getxandycoord.ofwallends

plx=walls(wall,2*mod(i+1,2)+1);ply=walls(wall,2*mod(i+1,2)+2);plx_alt=walls(wall,2*mod(i,2)+1);ply_alt=walls(wall,2*mod(i,2)+2);%getproplossfromWAPtowallend

pl(i)=proploss_combined(plx*Res+1,ply*Res+1);%getdistancefromWAPtobothwallends

path_dist=((x-plx).^2+(y-ply).^2).^.5;path_dist_alt=((x-plx_alt).^2+(y-ply_alt).^2).^.5;%calculateslopeofpathfromWAPateachpoint

path_m=make_finite((y-ply)./(x-plx));PATH_M=expand2fit(path_m,mat_size);%calculate(finite)inverseofpathslopeateachpoint

path_m_inv=make_finite(1./path_m);%calculatexandyinterceptsofpaths

PATH_X_INT=expand2fit(plx-ply.*path_m_inv,mat_size);PATH_Y_INT=expand2fit(ply-plx.*path_m,mat_size);%calculatefreespacelosses

proploss2=(10*log10((path_dist).^n1));proploss_far=(10*(log10((Dbp).^n1)+log10((path_dist/Dbp).^n2)));proploss2(path_dist>Dbp)=proploss_far(path_dist>Dbp);proploss2=make_finite(proploss2);%calculateanglebetweeneachpathandeachwall

THETA=atan((WALL_M-PATH_M)./(1+WALL_M.*PATH_M));%get/calculateanglesneededtocalculatediffractioncoefficient

theta_1=eval(['theta1_end'num2str(wall_end)]);theta_1=abs(theta_1(wall));theta_2=acos((path_dist.^2+wall_length(wall).^2...

-path_dist_alt.^2)..../(2.*path_dist.*wall_length(wall)));theta_2=theta_2.*(-1).^(squeeze(INTERFERE_PATH(wall,:

:

))-1);theta_2=2*pi-mod(real(theta_2),2*pi);%calculatexandycoord.ofintersectionsbetweenpathandwall

X_INTSCT=(PATH_Y_INT-WALL_Y_INT)./(WALL_M-PATH_M);Y_INTSCT=WALL_M.*PATH_M.*...(PATH_X_INT-WALL_X_INT)./(PATH_M-WALL_M);%forwalls||or|_tox-axis,correctinf.slopeerrorsX_INTSCT(walls(:

1)==walls(:

3),:

:

)=...repmat(walls(walls(:

1)==walls(:

3),1),...[1building_size

(1)*Res+1building_size

(2)*Res+1]);Y_INTSCT(walls(:

2)==walls(:

4),:

:

)=...repmat(walls(walls(:

2)==walls(:

4),2),...[1building_size

(1)*Res+1building_size

(2)*Res+1]);%determinedBminterferencevalueforeachwallatallpoints

INTERFERENCE=make_finite(WALL_AF./max(sin(abs(THETA)),.1));%determinewhichwallsinterferewithpathtowhichpoints

INTERFERE=order_test(plx,X_INTSCT,X)&...order_test(ply,Y_INTSCT,Y)&...order_test(WALL_X1,X_INTSCT,WALL_X2)&...order_test(WALL_Y1,Y_INTSCT,WALL_Y2);%setinterferencevaluesforwallsthatdon'tinterferetozero

INTERFERENCE(~INTERFERE)=0;%addwalllossestofreespacelosses

proploss2=proploss2+squeeze(sum(INTERFERENCE,1));%calculatediffractioncoefficient

D=squeeze(abs(-exp(-j*pi/4)/sqrt(2*pi)....*abs(csc(theta_2-theta_1))....*sqrt(-sin(theta_2)./sin(theta_1))));%removeinfiniteandunnecessaryvaluesfromarray

D(D==Inf|D==-Inf|isnan(D)|theta_2<=pi)=...zeros(size(D(D==Inf|D==-Inf|isnan(D)|theta_2<=pi)));D(D>1)=zeros(size(D(D>1)));D(D<0)=zeros(size(D(D>1)));%calculate,correct,andaddnewpathlossestorunningtotalpl_tmp=10.^(-pl(i)/10)*10.^(-proploss2/10).*D;pl_tmp(isnan(pl_tmp))=zeros(size(pl_tmp(isnan(pl_tmp))));pl_new=pl_new+(pl_tmp);%displayprogressandtimeelapsed

disp([num2str(i)'of'num2str(2*num_walls)'complete'])now=clock-start;display(['Timeelapsed:

'num2str(now(6)+60*now(5))'seconds'])end

end%convertproplosstodecibels

proploss=-10*log10(pl_new);%subtractpropagationlossesfromtransmitpower

RSS=wap.power-real(proploss);%removelowvaluestopreserveplotscaleRSS(RSS>thresh_max)=thresh_max;%cliphighvaluestopreserveplotscaleRSS(RSS

%%%%%%%%%%%%%%%%%%%%%%%%%PlotResults%%%%%%%%%%%%%%%%%%%%%%%%%

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 高中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1