# Line of Sight (LoS) Analysis: Basics (Part 1)

# Introduction

Line of Sight analysis is a commonly used technique in telecommunication industry for A/I (Air Interface) equipment planning and allocation. With the simplest terms LoS is the question whether a point on N-dimensional space is visible by an other observer point. The question can be used to answer where to locate a transceiver on terrain so that it can serve customers on some region A.

Before relatively more complicated problems, let’s start with an easy example focusing on two dimensional terrains. Throughout the post, we will use R for coding which is my favorite option for any mathematical problem (statistics, plotting, linear algebra, optimization, etc.). But you can easily adapt coding material to Mathlab, Python,or your favorite language.

We will start by defining a mathematical function to be used to generate our pseudo terrains. For this purpose trigonometric functions (*sin*, *cos*) and polynomial functions are the best ones because of their wavy shapes. Here is an example of trigonometric terrain

**Figure 1 Trigonometric Terrain
**

In order to generate this two dimensional one use the following code piece

x <- seq(from=4,to=10,by=0.01) y <- sin(x)+cos(2*x)+sin(3*x)+cos(4*x)+3 windows() plot(x,y,'l', main="y=sin(x)+cos(2x)+sin(3x)+cos(4x)+3", ylab="height",col="blue")

**Figure 2 Polynomial Terrain
**

To obtain this terrain, use the following R script piece

x <- seq(from=0,to=6,by=0.01) y <- x*(x-1)*(x-2)*(x-3)*(x-4)*(x-5)*(x-6)+100 windows() plot(x,y,'l', main="y=x(x-1)(x-2)(x-3)(x-4)(x-5)(x-6)+100", ylab="height",col="blue")

Combining polynomial terrain functions with trigonometric ones will give you fancier ones.

# What is LoS ?

You can think that we have already answered this question but this was an informal try which is not very useful for solving the problem. In order to solve this problem methodically we need to understand what makes a *target* visible (within LoS) by the *observer*.

As you see on *Figure 3*, **green** point is within line of sight of *observer* (**blue** point). However there is pseudo hill between **red** point and *observer*. The difference is that the line connecting *observer* and **green** point is always greater than the terrain function whereas this is not valid for the line connecting *observer* and **red** point (for x ε [~2.5, ~3.5] red line is under the terrain curve).

**Figure 3 LoS vs non-LoS
**

This was the first point (blocking) we should define. The second one is an easier one related with maximum Euclidean distance between *observer* and *target*. The distance between *observer* and *target* may cause a phase shift in signal if the distance is sufficiently long or depending on weather conditions and terrain properties you may observer diffraction problems (actually there might be more than those). In return this will cause signal quality issues or call drops. On Figure 3, although *blocking* is not an issue between *observer* and **yellow** point, *target* is out of visible range (say 8 units) of *observer*.

You can generate *Figure 3* using the following R script

# Terrain Function height <- function (x) { x*x/3+sin(x)+cos(2*x)+sin(3*x)+cos(4*x)+sin(5*x)+cos(6*x)+3 } # Observer location observer<-c(1.5,8.9) # Generate terrain points with a tolerance of 0.1 x<-seq(from=-0.1,to=6.1,by=0.1) terrainHeight<-height(x) windows() # Draw terrain plot(x,terrainHeight,type='b', xlim=range(x),ylim=range(terrainHeight), main="Line of Sight (LoS)", ylab="Height",xlab="") # Not LoS points(x=c(observer[1],x[41]), y=c(observer[2],terrainHeight[41]), col="red",type='b') # LoS points(x=c(observer[1],x[5]), y=c(observer[2],terrainHeight[5]), col="green",type='b') # LoS but far points(x=c(observer[1],x[length(x)]), y=c(observer[2],terrainHeight[length(x)]), col="yellow",type='b') # Draw Observer points(x=c(observer[1]), y=c(observer[2]), col="blue",pch=10)

# Method to Decide LoS

Finally let’s define a method to find all visible, invisible, and “far” points on any terrain. Since it is not “easy” to decide analytically whether the line connecting *observer* and *target* “is above” the terrain for any terrain function, we will use a simple numeric method.

We will define a *step* size small enough (around *Spatial Tolerance*) to generate all *x* values between *observer* and *target*. *seq* function is a good choice for doing this (Code Lines 33-36). Evaluate these *x* values for line function connecting *observer* and *target *and terrain function. Evaluation is simple for terrain function using *height* function (Code Lines 4-7). Evaluation of line function is held by function *linear* using parametric definition of line function (Code Lines 9-14) . Next step is to search for any *x* value having a line evaluation less than terrain evaluation (Code Line 44-28). The rest is simple as to evaluate euclidean distance and assigning values to *status* variable.

################## # Functions ################## # Terrain Function height <- function (x) { x*x/3+sin(x)+cos(2*x)+sin(3*x)+cos(4*x)+sin(5*x)+cos(6*x)+3 } # Linear Function linear <- function (x, observer, target) { v <- observer - target ((x - observer[1])/v[1])*v[2]+observer[2] } # Linear Function distance <- function (p0,p1) { sqrt(sum((p0-p1)^2)) } ################## # Input ################## # Observer location observer<-c(1.5,9) # Target on terrain target <- c(5, height(5)) # Max visible distance maxVisibleDistance = 4 # Generate points with a step size of 0.1 x <- seq(from=min(observer[1],target[1]), to=max(observer[1],target[1]), by=0.1) # Terrain Height h <- height(x) # y Values y <- linear(x, observer, target) # LoS Analysis aboveTerrain <- round((y-h),2) >= 0.00 # First Rule visible <- !is.element(FALSE,aboveTerrain) if (visible){ # Second Rule d <- distance(observer, target) if(d <= maxVisibleDistance){ status <- "LoS" }else{ status <- "non-LoS due to Distance" } }else{ status <- "non-LoS due to Blocking" }

Posted on September 2, 2011, in Uncategorized and tagged R, Spatial. Bookmark the permalink. 1 Comment.

Pingback: Line of Sight (LoS) Analysis: Part 2 « The great grandson of Husnu Sensoy