File Exchange

image thumbnail

3D Ray Tracing For Indoor Radio Propagation

version (414 KB) by Salaheddin Hosseinzadeh
3D Ray Tracing To Estimate Signal Strength in Indoor Environment and Estimate Propagation Loss


Updated 15 May 2019

View Version History

View License

This is a 3D ray tracing algorithm for indoor radio propagation based on reflecting image method. This accounts for transmission, primary and secondary reflection of a wave(signal) through and off the walls(panels).
PLEASE USE "RayTracing3D_v02.m" TO RUN THE CODE.
Two examples are included to get you running. In the comments at the beginning of the file it's explained how it works and how to define the geometry or building. Make sure you have as few walls as you can to make the computation less cumbersome. There is no limit on the number of walls (or panels). You can even define windows if you want but have to change the current way the structure is defined (based on 2D model, explained in the code).

"RayTracing3D_v02.m" is only makes the variables and the parameters that needs to be passed to the "RayTracingEng_v02.m". You don't need to change the RayTracingEng_v02.m unless you want to change the algorithm.

You need all the other functions that are provided in the submission to run this. There are few additional tools in the folder "Additional Tools" that helps along further analysis of the generated signal strength map.

Feel free to contact if you've any questions.
All the best

Cite As

Salaheddin Hosseinzadeh (2021). 3D Ray Tracing For Indoor Radio Propagation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (69)

Arigye Wilford

Solved by change the SingleWal.CSV file to SingleWal.xls and modifying the function call similarly

Arigye Wilford

Dear Salaheddin,

Greetings!, I have tried to run the code but I get this error, I have previewed the csv file and they are separated with the ; and in one cell, but I still get the below error, Running Matlab 2016b on MacBook Pro with Microsoft 2011 office pack.
Error using xlsread (line 249)
Unable to read XLS file /Users/wilfordarigye/Documents/MATLAB/MATLAB
2019_2020/3D Ray Tracing/3D Ray Tracing/SingleWal.CSV. File is not in
recognized format.

Error in CSV23D_V1 (line 15)
[~,~,pointData] = xlsread([fileAddress,fileName]);

Error in RayTracing3D_v20 (line 218)
[wallxyz1, wallxyz2, wallxyz3, wallxyz4,wallX,wallY,wallZ] =

Need help!
Regard Wilford

Reza Irannejad


Hello, thank you very much for your code. How to consider the thickness of the wall in the program?


Dear Salaheddin,thanks for the code very much!Can you give us a brief calculation formula before you write the code? We want to go deeper into this code.

tenna An

How can i add the rx antenna? I want to confirm the received power

Achraf Mallat

Dear Salaheddin
Thank you very much for the code.
Can we use it to find the complex channel gain "h=r*e^j*phi" between Tx and Rx?


Do anybody know how to add diffraction module?

Ed Sykes

Thank you Dr. Hosseinzadeh! Your code is amazing! Kind Regards, Ed

Please drop me an email (use my gmail) and explain a little more about what is your intention and what are you trying to do.
@everyone leaving comments here or emailing me
Thanks for your email and for showing appreciation. I'm sorry I sometime don't find time to be very responsive on the MATLABCENTRAL. I'll usually reply to my emails within a few days or so (sometimes a week). I try my best to provide some sort of support for this code. I have received some good feedback from some of you which I really appreciate, and if there will be a future update, I will certainly consider them. Thanks for understanding.


Dear Dr. Hosseinzadeh, Now I have an individual problem, which is how to modify the code if I want to get different height walls in the simulation again. Because I want to use it for outdoor simulation, the height of some buildings is usually different. Sorry to disturb you again, thank you very much.

Ed Sykes

Dear Dr. Hosseinzadeh,

If you would be so kind to point me in the right direction to solve this problem, I would be very appreciative.

I am running Matlab R2019B on macOS

Thank you so much!!

Kind Regards,

Ed Sykes

Dear Salaheddin

I Hope you are well. Thank you very much for creating and sharing this MATLAB "3D Ray Tracing For Indoor Radio Propagation”
I am trying to run 'RayTracing3D_v20.m'. When I run it, it prompts me to enter in CSV file. I navigate to the one provided: ‘SimpleTest.CSV’ but I seem to be getting an error:

Error using xlsread (line 257)
Unable to read XLS file /Users/sykes/OneDrive - Sheridan College/CMI_Beacons_and_Security_paper/MATLAB/3D
Ray Tracing/3D Ray Tracing/SimpleTest.CSV. File is not in recognized format.

Error in CSV23D_V1 (line 15)
[~,~,pointData] = xlsread([fileAddress,fileName]);

Error in RayTracing3D_v20 (line 218)
[wallxyz1, wallxyz2, wallxyz3, wallxyz4,wallX,wallY,wallZ] =

If you could provide any suggestions to correct the problem, I would be very grateful.

Thank you so much!

Kind Regards,

sohaib bakr

Very good job mr. sal and you are very helpful <<I wish you good luck


@Salaheddin Hosseinzadeh thank you very much,you give me a lot of help,regards.

@ Kai "can you tell me how can I set the locationIndex??????"

Apparently you only want to have 1 Rx point. You will get errors when it comes to create an image of the RSSI and map it to the building as you need more Rx pints. However, it will still give the RSSI for that single point.
You need to modify the RayTracingEng_V02.m file which I don't usually suggest people to change that.

This is where the Rx points are defined

if optimizationMode == 1 =,:);
else = [reshape(X,[],1,1),reshape(Y,[],1,1),reshape(Z,[],1,1)];

Change the to the location that you want. Keep the demoMode =1 and then you can see the Rx point on the structure blueprint image.

The code may run into an error and terminate before it finishes, but you probably will be able to get the calculated RSSI. The code will probably just crash as it won't be able to create an image from 1 pixel!!

I hope this help.

@ Kai "can you tell me how can i get the plot of Channel impulse response、path loss、Delay spread、Angle expansion。
thank you very much"

Sorry, but there is not an easy way to get these parameters as I don't keep any of them, they are calculated for each node but not saved, they are overwritten. You can create extra arrays to capture these parameters and process them once code is finished.
You have to modify the code RayTracingEng_V02.m file, and I understand that this is gonna be time taking but there is no other way.


@masoud salehi how can I consider just one point as a receiver point? not a plane as a receiver? I do not understand the locationindex ,who can tell me,regards。


can you tell me how can I set the locationIndex??????


Dear Salahheddin Hosseinzadeh,
can you tell me how can i get the plot of Channel impulse response、path loss、Delay spread、Angle expansion。

thank you very much

Bikalpa Upadhyaya

Dear Salahheddin Hosseinzadeh,
I would like to include local scatteres in the model. can you please explain to me how can i do it?, if possible


@ Valerian Watson yes,you only need to run RayTracing3D_v02.m and choose the single wall。its ok

Valerian Watson

did you solve the problem? I get the same error message: Unable to resolve the name mesh_.xNodeNum.

Error in RayTracingEng_V02 (line 13)
alpha.x = (1 - mesh_.xNodeNum .* imageRSSIScale)./(boundary(1,1) - boundary(1,2));

Kind regards

João Louro

Dear Salaheddin Hosseinzadeh,

I need import structural design from AutoCad. In your explanation in the RayTracing3D_v02.m file you say this is possible, how can i do it?

Best Regards

Huiting Qin

Prasanna Rangarajan


Hi Sir
I have gone through your code but I have difficulties in running. The error code I am getting is as "Error in RayTracingEng_V02 (line 13)
alpha.x = (1 - mesh_.xNodeNum .* imageRSSIScale)./(boundary(1,1) - boundary(1,2));"
Please kindly assist. my email is




Danaisy Prado

Dear @khaled whi,

I have created a new .csv. Then I wrote in A1 0;0;0 and in A2 36;0;0. Doing this, the code run without any error.

Hope this help you.

@Salaheddin Hosseinzadeh, thanks for your code!

khaled whi

khaled whi

THANK YOU for your help

i am trying to run this code and i had the following error and i would like some help. i already did as you answer in your comment (Put/change the format of number in one cell)
when i run it with simpletest.csv

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

Error in CSV23D_V1 (line 26)
Y(i,1) = str2num(strtok(remain{i},';'));

Error in RayTracing3D_v20 (line 218)
[wallxyz1, wallxyz2, wallxyz3, wallxyz4,wallX,wallY,wallZ] = CSV23D_V1(demoMode,groundLevel,ceilingLevel,;

thanks again

Pavel Mezhevov

@Salageddin Hosseinzadeh
Thank you for help

@Pavel Mezhevov
All the walls in your simulation are numbered from 1 to ... n (lets say n is the total number of the walls you have), all the ceilings are numbered as well (from n+1 to m).
the size of wall.relativePerm must be the same size as your total number of walls and ceilings/floor.
You need to manually set the permittivity of each wall. If you activate the demoMode (by setting it to 1, check the code to see how to do it) then you get all the walls and ceilings shown to you during the initialization. So you see whats the number of a particular wall. Once you figured what is your specific wall number and you have its permittivity you can set them manually one by one.
For example wall number 8 has permittivity of 4
wall.relativePerm (8) =4;

or say wall 1 has permittivity of 9
wall.relativePerm(1) = 9;

say your ceiling number 12 has permitttivity of 3
wall.relativePerm(12) = 3;

Do not remove this "wall.relativePerm = 6*ones(size(wall.xyz1,1)+size(ceillFloor.xyz1,1),1);" just add anything that you want to change after this line of code.
wall.relativePerm = 6*ones(size(wall.xyz1,1)+size(ceillFloor.xyz1,1),1);
wall.relativePerm (8) =4;
wall.relativePerm(1) = 9;
wall.relativePerm(12) = 3;

Anything that you don't manually set is going to be defaulted to 6.
Hope this helps.

Pavel Mezhevov

Dear Salaheddin Hosseinzadeh,
Thank you for your answer, but I don’t understand how I can change this line of code
wall.relativePerm = 6*ones(size(wall.xyz1,1)+size(ceillFloor.xyz1,1),1);
Thanks a lot.

@Pavel Mezhevov
The energy of the wave that passes through or reflects depends on the dielectric constant (permittivity), please search for Fresnel equations, and the angle of the incident of the beam on the wall or ceiling.
You can set these parameters within the code depending on the material of walls (there are researches that provide these info one of which is the ITU, I think ITU Chapter 4).

@ sylvere pagna
I hope you're problem is solved by now.
Usually people don't define the new geometry int he format that it should be. Please have a look at the example CSV files. The coordinates MUST be separated by the same delimiter and all be in the 1 cell I believe.
If the example CSV files don't work either then you most likely don't have a compatible microsoft excel installed on your PC.

Pavel Mezhevov

Dear Salaheddin Hosseinzadeh,
Could you explain how it is necessary to set the dielectric constant of a specific wall or ceiling? unfortunately for me it is not trivial from your description in the code.
Thanks a lot.

sylvere pagna

Hello to everyone,

i am trying to test the algorithm with the provided data but i am facing the following problem: Error using xlsread (line 260)
Unable to read XLS file /Users/dannylefeeling/Downloads/3D Ray Tracing/3D Ray Tracing/SimpleTest.csv. File is not in recognized
can someone help?

Thank you.

Komal Masroor

shan bao

This code is really valuable to me,thank you!


jing zhou

Benzakounia Elkhamiss

Thank you for sharing information with us for a better understanding of Raytracing simulation, The problem that I have found after runnig your code on MATLAB2014a is and for solving This error Error in CSV23D_V1 (line 26)
Y(i,1) = str2num(strtok(remain{i},';'));

Error in RayTracing3D_v20 (line 218)
[wallxyz1, wallxyz2, wallxyz3, wallxyz4,wallX,wallY,wallZ] = CSV23D_V1(demoMode,groundLevel,ceilingLevel,;

The CSV file format that you define is not how it should be. The x;y;z coordinates of the end points of the line should be in 1 excel cell (for instant the A1 should have 0;1;0. There is no spacing between the coordinates only ";"
Thanks a lot

Benzakounia Elkhamiss

Hello Ubaid

As the formula for the path loss, you can find it in the 3D ray tracing engine file. the exact name of the file is "RayTracingEng_V02.m".
And the formula looks like this

Rx.LosRssi(k) = Rx.LosRssi(k) + 10.^((Tx.power(i) - (FPSLRefLoss + 20 .* log10(4*pi*((RxTx.dist(k,1,i) >= refDistance) .* RxTx.dist(k,1,i) + (RxTx.dist(k,1,i) < refDistance)*refDistance) .* freq ./ lightVel) ...
- 10.*log10(prod(tempFresnelCoeff))) + (TxAntennaGainAE(round(losBeamAngle.Tx.AziIndex(k,i)),round(losBeamAngle.Tx.ZenIndex(k,i)))) + ...
(RxAntennaGainAE(round(losBeamAngle.Rx.AziIndex(k,i)),round(losBeamAngle.Rx.ZenIndex(k,i)))))/10) .* complex(cos(2*pi*freq*RxTx.dist(k,1,i)./lightVel + pi) , sin(2*pi*freq*RxTx.dist(k,1,i)./lightVel + pi));

This is the overall formula, if you follow the variables, you can see how each individual parameter is calculated in the code as well.
I have also included tons of references in one of my previous comments, you can have a look at those if you wish, thy would clarify the algorithm used to implement this.

Now answering your second question, using it for outdoors.
There are a few things to consider:

1- You need to have a 3D model of the city. At least the buildings in the city. This is not any 3D file, it needs to be in a specific format that I have defined here. So even if you manage to find a 3D model of the city or outdoor environment, you won't be able to use it in this implementation.
2- The 3D ray tracing of this kind is not really used for the outdoor environments to my knowledge due to it being computationally expensive and time taking.

I used the model a few times for indoor propagation modeling and checked it against practical measurements, one of the results is also published (I'll put the links at the end), it yielded respectable results compared to other indoor propagation models.
However, I do NOT recommend this for outdoor at all. You can instead take advantage of hybrid models for outdoors (I put a link to that as well)

I hope this explanation helps.
All the best,

Checked these links for the published results

Hybrid model

Ubaid Ullah

Dear Salaheddin Hosseinzadeh,
Could you please share the propagation loss formula or model on which this code is based?
Can I use this could for outdoor macro path loss?

Sahib Dhanjal

Komal Masroor

Dear Mr. Rashid

Were you able to solve the issue regarding .CSV file? I am facing a similar problem and would appreciate your response on this matter.




Mila Sobetwa

Hi Sir

I have gone through your code but I have difficulties in running it as I am working towards the same space of raytracing but more intending to optimise path loss in an indoor environment. The error code I am getting is as "Error in RayTracingEng_V02 (line 13)
alpha.x = (1 - mesh_.xNodeNum .* imageRSSIScale)./(boundary(1,1) - boundary(1,2));"

Please kindly assist. my email is


Rashid Suleymanov

Salaheddin Hosseinzadeh, look at the mail.

Hello Rashid

I'm sorry that you're facing difficulties running it.
You're not the first one though, and you're problem will be easily solved. I'll explain it here but if you couldn't figure it out feel free to drop me an email, my email address is on the submission and my profile.

Quick answer as I wrote to other people as well and solved their problem is that:

"I'm afraid the data that you defined is not the right format. Not one that is compatible with my code. Pay a bit more attention to how the points in the examples are defined and define your points like that."

The CSV file format that you define is not how it should be! if you open your CSV file with excel, its format should be similar to the comma separated values I've defined in the examples.
That is the x;y;z coordinates of the end points of the line you're defining should be in 1 excel cell (for instant the A1 should have 0;1;0. There is no spacing between the coordinates only ";"
If you define it in a different format then it doesn't work! Just look at the examples that I included, open them in excel and you'll understand.

Please if my explanation is wage or you managed to understand what I mean by the correct format, post it here and should hopefully help other people. I designed this myself so it's quite clear to me and perhaps I can't explain it for other to make them understand.

Thanks a lot,

Rashid Suleymanov

Dear Mohammad Reza, did you solve your problem? The fact is that I faced a similar problem. And I do not know how to solve it.

Rashid Suleymanov


apologies - that should read "intersect" not "interest"

shanshan dong

Hi Salahaddin,
Thank you for the code. But where can I find the formula of propagation loss?


mohammad Reza

dear sir
with the best for you best regard for your efforts
i review your project and i found very useful , but i have a problem in running,as i run the RayTracingEng_v02.m after the plot of antenna radiation, it seems to need introduce a cv file for load of the other data, i confused to itroduce wich one of cv file,after a few moment i have this error :

Error in RayTracing3D_v20 (line 217)
[wallxyz1, wallxyz2, wallxyz3, wallxyz4,wallX,wallY,wallZ] =
please let me know about it.
thanks a lot , more and more.


Thanks Jiayi and Masoud for posting your questions. I have included some of the references that help toward understanding this code better.
Some are about the 3D ray tracing, and some are additional articles that also helped me.

All the best


[1] J. W. McKown and R. L. Hamilton, "Ray tracing as a design tool for radio networks," Network, IEEE, vol. 5, pp. 27-30, 1991.
[2] C.-F. Yang, B.-C. Wu and C.-J. Ko, "A ray-tracing method for modeling indoor wave propagation and penetration," Antennas and Propagation, IEEE Transactions on, vol. 46, pp. 907-919, 1998.
[3] F. Villanese, W. G. Scanlon, N. E. Evans and E. Gambi, "Hybrid image/ray-shooting UHF radio propagation predictor for populated indoor environments," Electronics Letters, vol. 35, pp. 1804-1805, 1999.
[4] R. A. Valenzuela, "A ray tracing approach to predicting indoor wireless transmission," in Vehicular Technology Conference, 1993., 43rd IEEE, 1993.
[5] S. Y. Seidel and T. S. Rappaport, "A ray tracing technique to predict path loss and delay spread inside buildings," in Global Telecommunications Conference, 1992. Conference Record., GLOBECOM'92. Communication for Global Users., IEEE, 1992.
[6] B. D. Seckler and J. B. Keller, "Geometrical theory of diffraction in inhomogeneous media," The Journal of the Acoustical Society of America, vol. 31, pp. 192-205, 1959.
[7] S.-W. Lee and G. Deschamps, "A uniform asymptotic theory of electromagnetic diffraction by a curved wedge," IEEE transactions on antennas and propagation, vol. 24, pp. 25-34, 1976.
[8] M. C. Lawton, R. L. Davies and J. P. McGeehan, "A ray launching method for the prediction of indoor radio channel characteristics," in Personal, Indoor and Mobile Radio Communications., IEEE International Symposium on, 1991.
[9] R. G. Kouyoumjian and P. H. Pathak, "A uniform geometrical theory of diffraction for an edge in a perfectly conducting surface," Proceedings of the IEEE, vol. 62, pp. 1448-1461, 1974.
[10] J. B. Keller, "Geometrical theory of diffraction," JOSA, vol. 52, pp. 116-130, 1962.
[11] T. Holt, K. Pahlavan and J.-F. Lee, "A graphical indoor radio channel simulator using 2D ray tracing," in Personal, Indoor and Mobile Radio Communications, 1992. Proceedings, PIMRC'92., Third IEEE International Symposium on, 1992.
[12] H. Hashemi, "Impulse response modeling of indoor radio propagation channels," Selected Areas in Communications, IEEE Journal on, vol. 11, pp. 967-978, 1993.
[13] S. Hosseinzadeh, H. Larijani, K. Curtis, A. Wixted and A. Amini, "Empirical propagation performance evaluation of LoRa for indoor environment," in Industrial Informatics (INDIN), 2017 IEEE 15th International Conference on, 2017.
[14] S. Hosseinzadeh, H. Larijani and K. Curtis, "An enhanced modified multi wall propagation model," in Global Internet of Things Summit (GIoTS), 2017, 2017.

Jiayi Lin

Hi Salahaddin,
Thank you for your code, could please share with us some related articles about ray tracing?

masoud salehi

Hello Dear Salahaddin
I have some other questions
First would you mind proposing some proper references to help us understand ray tracing algorithm for propagation better?
2nd question is that how can I consider just one point as a receiver point? not a plane as a receiver?
Thanks a lot

Harshavardhana Gowda

Thanks a lot Pang
You are quite right. l believe it is a typo however. You're the first bringing this to my attention. Thanks a lot for this.

The "epsm" needs to be changed to "eps".

I may fix and upload the code again. However this is quite minor and I'm hopping to find more time to improve the code by building the optimization into it and make it run much faster by use of parallel computing.

Haitao Pang

Hi, thank you very much for your work and sharing.

I am using matlab R2017b, and got the following error:

Undefined function or variable 'epsm'.

Error in RayTracingEng_V02 (line 465)
if (reflectPointj2Rxd < 1 && reflectPointj2Rxd > 0 && abs(reflectPointj2Rxd - 1) > eps
&& not(reflectPointj2Rxd < epsm))

This has to do with the obsolete function of epsm after R2014. (
It works perfectly after I changed the epsm for numbers such as 1.0E-6.

Le Vanhuy

Thanks Salaheddin,
Every success in your job.

Thanks for your feedback and question.
You can use this for MMWave frequency, there is no limitation with the algorithm. I'm not 100% sure of what's your project or aim, however, there are few things you may want to consider.
1- To get a visible pattern as how the waves interact you need to put the mesh size to at least half the wavelength, or less. This is just simple Nyquist theory consideration.
This is possible, but I made this code for relatively large environments, if you want to mesh a whole building with less than a few mm, you will have a lot of meshes and computation may last for a very very long time, specially that my code is not optimized for such purposes.
Although there is a great solution for this. You don't need to mesh the whole structure, you can just put probes where you are interested to see the signal strength. I did that for my optimization. However, ray tracing provides the “small scale” fading which varies with order of wavelength, whereas, small scale fading is not predictable for ranges beyond half-wavelengths (see the refs)
As I only took measurements as specific locations and not the whole structure, and I just wanted to see how it works about the same areas.
2- I'm not sure what wall parameters you want to consider in your study, I simply wanted to attenuation caused by the structure, therefore instead of using the thickness of the walls I used what's called effective permittivity, and since the permeability does not make a huge difference I ignored that as I was mainly working in 900 MHz. I'm not sure if this is an important parameter in mmWaves or not.
All the best

Ref#1 - Teal, P. D., & Kennedy, R. A. (2004). Bounds on extrapolation of field knowledge for long-range prediction of mobile signals. IEEE transactions on wireless communications, 3(2), 672-676.
Ref#2- Qiu, L., Jiang, D., & Hanlen, L. (2005, February). Neural network prediction of radio propagation. In communications Theory Workshop, 2005. Proceedings. 6th Australian (pp. 272-277). IEEE.

mohanned ali

Hello Salaheddin Hosseinzadeh,

First of all I would like to congratulate you on this marvelous code. I wanted inquire if it's possible to use the tracer at MMWave frequencies.

Thank you.

Thuan Huu

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: Image overlay, Bresenham optimized for Matlab

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!