Saturday, April 23, 2011

Plot graphs: gnuplot

I am doing my final year project on network simulator. I had to plot my results in Ubuntu. I found "Gnuplot"; a free, command-driven, interactive, function and data plotting program. We can easily plot graphs of common functions like sine, cosine, sinc, and many more. We can also plot the tabulated data. Gnuplot on my terminal looks like as shown below.
figure: terminal window

Interesting feature about this program is that you don't have to define x-range, x-scale and y-scale. Just type "sin(x)" and you have plotted graph of sin(x). The ranges are suitably defined unlike Matlab, and other languages where you have to define x range from 0 to pi or something like that. I have plotted sin(x) and sin(x)/x as shown in figure below.

figure: plot of sine function
 figure: plot of sinc function

Important commands:
Create a title:                    > set title "title"
Put a label on the x-axis:   > set xlabel "xlabel"
Put a label on the y-axis:   > set ylabel "ylabel"
Change the x-axis range:   > set xrange [x1:x2]
Change the y-axis range:   > set yrange [y1:y2]
For notes and documentation, click here.

Monday, April 4, 2011

Free Space Propagation Model

In any wireless communication system power received by receiver and the path loss are important parameters to be considered. There are several models to calculate these parameters, but the general and easiest one is the free space propagation model. This model is able to calculate power received and path loss for far field. The mathematics of this model is Friss’s free equation which is as follows:
Pt is transmitted power. Pr is received power. Gt is gain of transmitter. Gr is gain of receiver. λ is wavelength. d is distance between transmitter and receiver. Similarly the path loss is 
I have created a Matlab GUI that calculates power received and path loss using above two formulas. It also plots them in dBm amplitude with respect to distance in x-axis. It looks like as follows:
figure: GUI of free space model

It takes input parameters as: Tx power (Pt), frequency (f), transmitter gain (Gt), Receiver gain(G­r) and distance(d). From calculation, it shows Rx power (Pr), path loss (PL) in dBm. It has graph scheme which plots graph of received power vs tx-rx distance and path loss vs tx-rx distance respectively.

Interested can download freespace.m and freespace.fig files, click here.
(Reference: Wireless Communication by Theodore S. Rappaport)

Tuesday, March 29, 2011

Snakes and Ladders: Java Work

Snakes and Ladders was one of the favorite indoor games of my childhood. We called it LUDO. I have made LUDO in NetBeans IDE 6.9(Java). It tested my programming skill. It required concept of classes, objects (OOP); which were completely different than other simple programming languages(C, Matlab). I cant help thanking my friend Pranav, for setting up the groundwork. I faced lots of problems, but at last i made it. Truly writing, i hadn't ever written the codes in such depth. 
(For detail information about LUDO, click here).

My LUDO GUI looks as shown below.
 
My Gui is a simple model of LUDO. I have made it just for fun. It has 2 player scheme, one player red and one player blue. To roll, you have to click on “Click” button. Your rolled number from 1 to 6 is shown above the “Click” button. Similarly the turn of players is shown below that button. Snakes and ladders do their work on the way of gotties. First player reaching "100 place" wins.

Interested viewers can access my source codes/NetBeans files from here.
You can download *.jar file from here.

Thursday, March 17, 2011

MATLAB: Radiation pattern of Thin Linear Antenna


Radiation pattern refers to the plot of radiation properties of any antenna. Thin linear antennas are similar to dipole antennas with symmetric fed source at the center by a balanced two wire transmission line. Moreover linear antennas have sinusoidal current distribution. We consider the diameter of the antenna d<λ/100, which provides good natural approximation to the current distribution. Current distributions for various antennas are as shown in figure below.

Fig. Current distribution (source: JD kraus, Antenna and propagation, Thanks Gaurav for this photo)


I have plotted the radiation patterns of these antennas with the help of Matlab GUI. The pattern is of electric field is in theta direction. The equation is 


This GUI is as shown in the figure below.


Fig. λ/2 antenna

The GUI has facility to choose the antenna size (i.e. length of the antenna, L) = λ/2, 3λ/4, λ, 3λ/2 and 2λ. It plots 3D pattern of chosen antenna as shown in figure above; which is field pattern of λ/2 antenna. The plots of patterns for other antennas are as follows:



Fig. 3λ/4 antenna

Fig. λ antenna

Fig. 3λ/2 antenna
Fig. λ antenna
You can view the source code from here.
(Reference: Antennas and Wave Propagation, JD Kraus, 4th edition)
 

Tuesday, March 15, 2011

Our first year project: Clap Switch

“Clap Switch” simply refers to a switching system whose switching mechanism depends on clapping of our hand. At one clap switch is on and at another clap switch is off. We can turn on or off any electrical equipment with a simple clap. Clap Switch project has been very famous project for first year Electrical and Electronics students of Kathmandu University since it is very simple but requires knowledge of lots of components. One has to use sensor, operational amplifier, filp flop, timer, relay, transistor, etc; looks like whole electronic knowledge is required. The block diagram of our project was as follows.


Our system consists of a microphone which is a clap sensor. The sound of the clap detected by the microphone is sent to the comparator (OP-AMP 741) which compares inverting and no inverting voltages and sends the higher signal to the 555 timer. Now, the signal received by the 555 timer (monostable mode) is converted to a single square wave for a certain time interval. The signal from the 555 timer is sent to the flip flop circuit (IC 4013 DUAL D), which gives logic for the switching. It holds the high signal constantly even after discontinuing the clap and holds low signal when clapped again. The constant signal is feed to the relay which is a switching device. Once the switch gets on triggered by the clap we can lit up the lamp and it gets switched off when again clapped.
The circuit diagram is as follows.
 Hope this content may help first year engineering students. 
(Please don't try to copy this circuit, try to understand electronics behind it. If you become able to understand all electronics behind this, you can design you own circuit diagram.)


Monday, March 14, 2011

Time travel to future: How is it possible?

Who don’t want to see future? Like after 50 years or 100 years, how would this world look like? How would people think, eat and live? What would be the technologies? What would be the tradition and culture? Who would be the famous people of those times? And so on. Lots of questions about the future fascinate people and make them search for the possibility of time travel. 

This passion makes people to understand Einstein’s Theory of Relativity. This theory requires sufficiently talented brain, especially to understand the mathematics behind it. However, if we start thinking that the speed of light is unchanged everywhere in space, as Einstein did supporting the idea of Maxwell, then anyone can see the possibility of time travel using their simple concept of classical physics. Human perception about time has been like an unchanged thing, we feel time as if a fixed quantity. We associate time with our perception; like our brain considers one second for heart beat of 70 times. So it is all about our brain who let us feel.




I want to present a case similar to twin’s paradox, consider two people one in earth and another in spaceship. I want to apply just one condition that the time of spaceship is slower than the earth. Obviously, the slow in time results slower in the beat of heart. That means the heart beat rate of spaceman is slower than the earthman. Let us consider the time in spaceship is just half than the time in earth, like for half second in spaceship is whole one second in earth. Then the spaceman’s heart beats only 35 times, while earthman’s should beat whole 70 times. Hence the every action and activity of spaceman is slower than earthman and so the physical growth and development of body. So the growth and development of spaceman is slower than the earthman and spaceman becomes still young while earthman becomes old. 


This whole concept gives us clue for the time travel. We can see the future if our growth and development slows down. If our activities and growth becomes such slower, like for 1 day of our becomes 1 year for normal people; we can reach to 10 years later time in 10 days. It looks like a dream, since how can be our activities slow down? How can be our heart beat slows down to such an extent that we just completed one heart beat while normal people on earth completed their heart beat 360 times? It is may be the nature or maybe god that has given us this facility. It is all about increase in relative mass resulting slower in time.

The first option is going to fast moving vehicles or spaceships as I described earlier. Your velocity must be near to the speed of light (0.99 c). From Einstein’s relativity, as v→c, m→infinite. This mean our relative mass will increase hugely. Our every action performed becomes such slower that we see light still traveling at c, even though we are at a spaceship traveling at c. Using this concept we can travel 80 millions light year distance in our 80 year lifetime. Nature has given us such facility that we can travel half way of our galaxy in our lifetime though it is at 80 million light year distance. Coming to the point, we can have slow in time if we travel near the speed of light(c).  


Second option is gravitation. A high gravity mass object increases the gravitational energy of any small object under its influence. Increase in gravitational energy increase its relative mass and in consequence slow in time. But our earth is not sufficient for such large gravitational field. For this we need a highly strong gravitational field mass object. That object could be a black hole; a good black hole for this purpose is right at the center of our Milky Way galaxy. By some mechanism, we have to reach there and orbit around that black hole so that we might travel in time. But detail calculation shows that even if we orbit round that black hole for fifty years, earth time would have passed by only 100 years. So this provides very slow facility of time travel. Comparing two alternatives, first one look possible, but we can never reach to the speed of light not even near to it. For second option, reaching near to the black hole is dangerous and very risky. So it seems like our dream to travel in the future.

Third option, which is only a hypothesis are warm holes. A wormhole is a theoretical 'tunnel' or shortcut, predicted by Einstein's theory of relativity, which links two places in space-time.


In such warm holes, there is negative energy that pulls space and time into the mouth of a tunnel which emerges out into another universe. Unfortunately, these real-life time tunnels are just billion-trillion-trillionths of a centimeter across and too small for a human to pass through. But some scientists think it may be possible to capture a wormhole and enlarge it many trillions of times to make it big enough for a human or even a spaceship to enter. Anyway it is only hypothesis till now. 

(This article is inspired from a  Discovery documentary show).



Saturday, March 12, 2011

Fun in Matlab: Music player for *.wav file


Matlab is generally used to solve, design or simulate problems but we can make a Music player since Matlab also gives us the facility to handles *.wav sound files. Music player in Matlab looks like a wired idea because we can make a very much better music player in other tools. But just for fun my roommate Sulav (You can visit his nice site, click here) and I decided to make one last year. After coding for about four-five hours, we did that, it was really fun, we enjoyed it. Our music player was only able to play *.wav file since we couldn’t find any facility to access other sound file formats. Anyway, it was a good job, and you can also make one of this. Our music player looked like as shown in figure below.


It has only the facility to “play/stop” and “pause/play”. You can also visualize the spectrum of sound. While clicking file option, there is “open” and “close”, “open” is to open new file to be played and “close” is to close the music player.
You can download the source code, click here.

Visualization of Electromagnetic wave in MATLAB

Wave is imaginary and mysterious thing to us. Many of them are invisible and we even don’t know their pres...