Implementation on Trinket

Implementation on REPL

Windows 8.1 Pro

**System**

Processor Intel(R) Core(TM) i7-5500U CPU @ 2.4GHz

Installed Memory 8.00 GB

System Type 64 Bit Operating System, x64 Based Processor

**Integrated Development Environment (IDE)**

Enthought Canopy

Version 2.1.3.3542 (32 bit)

Operation |
Time in sec (MATLAB) |
Time in sec (PYTHON) |

10 million uniform random variable generation | 0.10 | 0.15 |

10 million normal random variable generation | 0.13 | 0.40 |

for loop counting up to 100 million | 0.40 | 11.60 |

Comparing two vectors of length 10 million each | 0.39 | 0.55 |

Plotting a histogram of 10 million values | 0.89 | 0.76 |

Plotting a scatter plot of 1 million values | 0.30 | 0.23 |

Bit error rate calculation of BPSK for 10 values of SNR | 2.49 | 4.51 |

Although Python is a bit slower than MATLAB for most of the cases but the real difference is in implementation of “for loop” where the speed of MATLAB is 29x that of Python. Another surprising result was that the plot functions for Python were somewhat faster than MATLAB.

]]>There are various IDEs available for writing your code but I have used Enthought Canopy Editor (32 bit) which is free to download and is also quite easy to use [download here]. So as it turns out that there is life beyond MATLAB. In fact there are several advantages of using Python over MATLAB which we will discuss later in another post. Lastly please note the indentation in the code below as there is no “end” statement in a for loop in Python.

from numpy import sqrt from numpy.random import rand, randn import matplotlib.pyplot as plt N = 5000000 EbNodB_range = range(0,11) itr = len(EbNodB_range) ber = [None]*itr for n in range (0, itr): EbNodB = EbNodB_range[n] EbNo=10.0**(EbNodB/10.0) x = 2 * (rand(N) >= 0.5) - 1 noise_std = 1/sqrt(2*EbNo) y = x + noise_std * randn(N) y_d = 2 * (y >= 0) - 1 errors = (x != y_d).sum() ber[n] = 1.0 * errors / N print "EbNodB:", EbNodB print "Error bits:", errors print "Error probability:", ber[n] plt.plot(EbNodB_range, ber, 'bo', EbNodB_range, ber, 'k') plt.axis([0, 10, 1e-6, 0.1]) plt.xscale('linear') plt.yscale('log') plt.xlabel('EbNo(dB)') plt.ylabel('BER') plt.grid(True) plt.title('BPSK Modulation') plt.show()

]]>

The electromagnetic field in the shadowed region can be calculated by combining vectorially the contributions of all of these secondary sources, which is not an easy task. Secondly, the geometry is usually much more complicated than shown in the above figure. For example consider a telecom tower transmitting electromagnetic waves from a rooftop and a pedestrian using a mobile phone at street level. The EM waves usually reach the receiver at street level after more than one diffraction (not to mention multiple reflections). However, an approximation that works well in most cases is called knife edge diffraction, which assumes a single sharp edge (an edge with a thickness much smaller than the wavelength) separates the transmitter and receiver.

The path loss due to diffraction in the knife edge model is controlled by the Fresnel Diffraction Parameter which measures how deep the receiver is within the shadowed region. A negative value for the parameter shows that the obstruction is below the line of sight and if the value is below -1 there is hardly any loss. A value of 0 (zero) means that the transmitter, receiver and tip of the obstruction are all in line and the Electric Field Strength is reduced by half or the power is reduced to one fourth of the value without the obstruction i.e. a loss of 6dB. As the value of the Fresnel Diffraction Parameter increases on the positive side the path loss rapidly increases reaching a value of 27 dB for a parameter value of 5. Sometimes the exact calculation is not needed and only an approximate calculation, as proposed by Lee in 1985, is sufficient.

Fresnel Diffraction Parameter (v) is defined as:

v=h*sqrt(2*(d1+d2)/(lambda*d1*d2))

where

d1 is the distance between the transmitter and the obstruction along the line of sight

d2 is the distance between the receiver and the obstruction along the line of sight

h is the height of the obstruction above the line of sight

and lambda is the wavelength

The MATLAB codes used to generate the above plots are given below (approximate method followed by the exact method). Feel free to use them in your simulations and if you have a question drop us a comment.

```
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculation of the path loss based on the value of
% Fresnel Diffraction Parameter as proposed by Lee
% Lee W C Y Mobile Communications Engineering 1985
% Copyright www.raymaps.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
v=-5:0.01:5;
for n=1:length(v)
if v(n) <= -1
G(n)=0;
elseif v(n) <= 0
G(n)=20*log10(0.5-0.62*v(n));
elseif v(n) <= 1
G(n)=20*log10(0.5*exp(-0.95*v(n)));
elseif v(n) <= 2.4
G(n)=20*log10(0.4-sqrt(0.1184-(0.38-0.1*v(n))^2));
else
G(n)=20*log10(0.225/v(n));
end
end
plot(v, G, 'b')
xlabel('Fresnel Diffraction Parameter')
ylabel('Diffraction Loss (dB)')
```

```
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Exact calculation of the path loss (in dB)
% based on Fresnel Diffraction Parameter (v)
% T S Rappaport Wireless Communications P&P
% Copyright www.raymaps.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
v=-5:0.01:5;
for n=1:length(v)
v_vector=v(n):0.01:v(n)+100;
F(n)=((1+1i)/2)*sum(exp((-1i*pi*(v_vector).^2)/2));
end
F=abs(F)/(abs(F(1)));
plot(v, 20*log10(F),'r')
xlabel('Fresnel Diffraction Parameter')
ylabel('Diffraction Loss (dB)')
```

An interesting video explaining the phenomenon of diffraction.

]]>For this we consider that in the case of specular reflection the power of the ray is reduced by 3dB (that is R=0.5) and the ray continues as it would if there was no interaction with the object (off course direction would be changed with angle of reflection being equal to angle of incidence).

In the case of scattered ray we assume that the point of interaction between the ray and the object is a point source from where the rays are regenerated. Therefore there is a rapid drop in the E-field strength as the ray propagates away from the point of interaction.

```
clear all
close all
Eo=1;
r1=1:100;
r2=101:200;
r=[r1 r2];
R=0.5;
Er1=Eo./r1;
Er2=R*Eo./r2;
Er=[Er1 Er2];
Es1=Eo./r1;
Es2=Es1(end)./(r2-r1(end));
Es=[Es1 Es2];
plot(r,10*log10(Er),'b')
hold on
plot(r,10*log10(Es),'r:')
hold off
legend('Reflection','Scattering')
xlabel('Distance (m)')
ylabel('E-field (V/m)')
```

The simulation code above considers that a ray travels unobstructed for 100 m and at this point comes in contact with an object and is reflected (reflection coefficient of 0.5 is assumed) or scattered. The ray then again travels for another 100 m without coming in contact with an object.

It is observed that there is a rapid decrease in E-field strength of the scattered ray beyond 100 m. This is because the E-field strength at the point of interaction is much lower than that at the source and when this is considered to be a point source, re-generating the rays, the resulting E-field decays quite rapidly.

We assume that the reflection is specular in most of our simulations as this is closer to reality than assuming a fully scattered ray.

]]>y1=b1+m1*x1

y2=b2+m2*x2

Here m1 and m2 are the slopes of the two lines and b1 and b2 are their y-intercepts. At the point of intesection y1=y2, so we have.

b1+m1*x1=b2+m2*x2

But at the point of intersection x1=x2 as well, so replacing x1 and x2 with x we have.

b1+m1*x=b2+m2*x

or

b1-b2=-x*(m1-m2)

or

x=-(b1-b2)/(m1-m2)

Once the x-component of the point of intersection is found we can easily find the y-component by substituting x in any of the two line equations above.

y=b1+m1*x

In future posts we would like to discuss the cases of intersection of two surfaces and the intersection of two volumes.

]]>We know that Shannon Capacity is given as

C=B*log2(1+SNR)

or in the case of CDMA

C=B*log2(1+SINR)

where ‘B’ is the bandwidth and SINR is the signal to noise plus interference ratio. For OFDMA the SNR is given as

SNR=Pu/(B*No)

where ‘Pu’ is the signal power of a single user and ‘No’ is the Noise Power Spectral Density. For CDMA the calculation of SINR is a bit more complicated as we have to take into account the Multiple Access Interference. If the total number of users is ‘u’ the SINR is calculated as

SINR=Pu/(B*No+(u-1)*Pu)

The code given below plots the capacity of CDMA and OFDMA as a function of Noise Power Spectral Density ‘No’.

```
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CAPACITY OF CDMA and OFDMA
% u - Number of users
% Pu - Power of a single user
% No - Noise Power Spectral Density
%
% Copyright RAYmaps (www.raymaps.com)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
u=20;
Pu=1;
No=1e-8:1e-8:1e-6;
B=20e6;
C_CDMA=u*B*log2(1+Pu./(B*No+(u-1)*Pu));
B=1e6;
C_OFDMA=u*B*log2(1+Pu./(B*No));
plot(No,C_CDMA/1e6);hold on
plot(No,C_OFDMA/1e6,'r');hold off
xlabel('Noise Power Spectral Density (No)')
ylabel('Capacity (Mbps)')
legend('CDMA','OFDMA')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
```

We see that the capacity of OFDMA is much more sensitive to noise than CDMA. Within the low noise region the capacity of OFDMA is much better than CDMA but as the noise increases the capacity of the two schemes converges. In fact it was seen that as the noise PSD is further increased the two curves completely overlap each other. Therefore it can be concluded that OFDMA is the preferred technique when we are operating in the high SNR regime.

]]>