Category Archives: Fundamentals

Al Khwarizmi’s Method of Solving Equations in One Variable

Al Khwarizmi was a Muslim scholar who worked under the patronage of emperor Al Mamun in the 9th century in Baghdad. Al Mamun like his father was interested in supporting learning and formed the House of Wisdom of which Al Khwarizmi was a part. It was here that Greek philosophical and scientific works were translated into Arabic. In recognition of his support Al Khwarizmi dedicated two of his works on algebra and astronomy to the great emperor. His treatise known as Hisab al-jabr w’al-muqabala was the most famous and important one and was translated into several other languages. Over the years al-jabr came to be known as algebra and Al Khwarizmi (Algoritmi  in Latin) became algorithm.

According to Al Khwarizmi equations are linear or quadratic and are composed of units, roots and squares. To Al Khwarizmi a  unit was a number, a root was x and a square was x2. He defined two basic operations to solve equations namely al-jabr (the process of removing negative terms from an equation) and al-muqabala (the process of reducing positive terms of the same power when they occur on both sides of an equation). All Al Khwarizmi mathematics was done entirely in words and no symbol was used e.g. he solves an equation x2+10x=39 as follows:

“… a square and 10 roots are equal to 39 units. The question therefore in this type of equation is about as follows: what is the square which combined with ten of its roots will give a sum total of 39? The manner of solving this type of equation is to take one-half of the roots just mentioned. Now the roots in the problem before us are 10. Therefore take 5, which multiplied by itself gives 25, an amount which you add to 39 giving 64. Having taken then the square root of this which is 8, subtract from it half the roots, 5 leaving 3. The number three therefore represents one root of this square, which itself, of course is 9. Nine therefore gives the square”

Al Khwarizmi Graphical Method for Solving an Equation
Al Khwarizmi Graphical Method for Solving an Equation

One of his masterpieces is his method of solving equations using simple geometry, as shown above. For example to solve the equation x2+10x = 39 he first creates a square with length of each side equal to x and area x2. He then adds 10x to it by creating four rectangles of area 10x/4 = 5x/2 each. Thus the lightly shaded area in figure (c) above represents x2+10x or 39. Now we add the areas of the four corners (darkly shaded) to get  x2+10x+25 or 64 (39+25). So we find out that the side of the larger square is of length 8 (square root of 64). But we already know that the length  of a side is 5/2+x+5/2 = x+5. So we have the final equation x+5 = 8 or x = 3.

Al Beruni’s Method for Calculation of Radius of Earth

Al Beruni was a great Muslim scientist of the eleventh century who had knowledge of many diverse fields such as astronomy, astrology, mineralogy etc. He was member of Mahmud of Ghazni’s court from 1017 to 1030. It is here that he had the opportunity to travel to India (as well as present day Pakistan) and write about it in his books. It is claimed that he even learned Sanskrit during his stay in India. However, Al Beruni is most well known for his experiment to calculate the radius of the earth at a location close to Katas Raj in Kallar Kahar region of Pakistan. Some claim that the location of his measurements was in fact Nandana fort which is about 40 km east of Katas Raj temples.

His method of calculation involved two steps.

Step 1: Calculate the inclination angle of a mountain at two locations with known separation between them. We can then use simple trigonometry to find the height of the mountain. The trick here is to realize that there are two right angled triangles with the same height, which is an unknown, and base lengths which are also unknown but can be factored out (the reader is encouraged to do the math himself).

Calculating the Height of a Mountain

Figure 1: Calculating the Height of a Mountain

Step 2: The second step involves calculating the angle of depression that the horizon makes as viewed from top of the mountain. Then with the height of the mountain already known the radius of the earth can be easily calculated as shown below.

Calculating Angle of Depression

Figure 2: Calculating the Radius of the Earth

As the reader might have noticed there are three angular calculations and one distance calculation involved. Distance is easy to measure but angle is not and an accurate Astrolabe is required for this purpose. The Astrolabe that Al Beruni used was accurate to two decimal places of a degree. The radius that he calculated was within 1% of the accepted radius of the earth today.

PS: The writer has been to Katas Raj temples several times and it his desire to go there again to find more information about the location of the experiment and to possibly re-enact the experiment.


  1. A polymath is a person whose expertise spans a significant number of different subject areas; such a person is known to draw on complex bodies of knowledge to solve specific problems.
  2. An astrolabe is an elaborate inclinometer, historically used by astronomers and navigators to measure the inclined position in the sky of a celestial body, day or night.
  3. Nandana was a fort built at strategic location on a hilly range on the eastern flanks of the Salt Range in Punjab Pakistan. Its ruins, including those of a town and a temple, are present. It was ruled by the Hindu Shahi kings until, in the early 11th century, Mahmud of Ghazni expelled them from Nandana.


Open Signal Coverage Maps for Pakistan

Open Signal is a mobile application that collects the data about your wireless network (2G/3G/4G) and generates coverage maps and host of other reports. The data is collected in the background while the user is busy in his daily routines. But data can also be collected on the request of the user. This is much better than drive testing since the data is collected in real life scenarios and on thousands of different devices that are in use.

The app works while the user is indoor or outdoor, at rest or in motion, on land or on water, at sea level or on a mountain, in dry weather or in rain. Basically anywhere and anytime there are wireless signals available. There are currently 20 million users of the app (both Android and iOS combined) and this number is increasing. In Pakistan all major networks are supported including Jazz, Telenor, Zong and Ufone (both 2G/3G and 4G networks are supported).

JAZZ Islamabad Coverage Map

Telenor Islamabad Coverage Map

Zong Islamabad Coverage Map

Ufone Islamabad Coverage Map

Rayleigh Fading Envelope Generation – Python

When wireless signals travel from a transmitter to a receiver they do so after reflection, refraction, diffraction and scattering from the environment. Very rarely is there a direct line of sight (LOS) between the transmitter and receiver. Thus multiple time delayed copies of the signal reach the receiver that combine constructively and destructively. In a sense the channel acts as an FIR (finite impulse response) filter. Furthermore since the transmitter or receiver may be in motion the amplitude and phase of these replicas varies with time.

There are several methods to model the amplitude and phase of each of these components. We look at one method called the “Smiths Fading Simulator” which is based on Clark and Gans model. The simulator can be constructed using the following steps.

1. Define N the number of Gaussian RVs to be generated, fm the Doppler frequency in Hz, fs the sampling frequency in Hz, df the frequency spacing which is calculated as df=(2*fm)/(N-1) and M total number of samples in frequency domain which is calculated as M=(fs/df).
2. Generate two sequences of N/2 complex Gaussian random variables. These correspond to the frequency bins up to fm. Take the complex conjugate of these sequences to generate the N/2 complex Gaussian random variables for the negative frequency bins up to -fm.
3. Multiply the above complex Gaussian sequences g1 and g2 with square root of the Doppler Spectrum S generated from -fm to fm. Calculate the spectrum at -fm and +fm by using linear extrapolation.
4. Extend the above generated spectra from -fs/2 to +fs/2 by stuffing zeros from -fs/2 to -fm and fm to fs/2. Take the IFFT of the resulting spectra X and Y resulting in time domain signals x and y.
5. Add the absolute values of the resulting signals x and y in quadrature. Take the absolute value of this complex signal. This is the desired Rayleigh distributed envelope with the required temporal correlation.

The Matlab code for generating Rayleigh random sequence with a Doppler frequency of fm Hz is given below.

Fourier Transform in Python

Fast Fourier Transform or FFT is a powerful tool to visualize a signal in the frequency domain. Shown below is the FFT of a signal (press the play button) composed of four sinusoids at frequencies of 50Hz, 100Hz, 200Hz and 400Hz. The sampling frequency is set at 1000Hz, more than twice the maximum frequency of the composite signal. The amplitude of the sinusoids diminishes with increasing frequency and this is also reflected in the frequency domain. Play with the code, decrease the frequencies, increase the power, visualize the FFT output on logarithmic scale!

Alamouti – Transmit Diversity Scheme – Implemented in Python

We have already seen in previous posts that the BER of BPSK increases significantly when the channel changes from a simple AWGN channel to a fading channel. One solution to this problem, that was proposed by Alamouti, was to use Transmit Diversity i.e. multiple transmit antennas transmit the information over multiple time slots increasing the likelihood of receiving the information. We have considered the simplest case of two transmit antennas and BPSK modulation (QPSK modulation would give the same BER with twice the throughput). Given below is the Python code for this, feel free to modify it and run it from the console given below.

Implementation on Trinket

Implementation on REPL