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.

Friday, March 11, 2011

Installing network simulator (ns-allinone-2.34) in Ubuntu 10.04

NS (Network Simulator) is a very useful open source network simulation software tool for communication and computer science engineers. As the name suggests, it is very helpful for the real time simulation of network nodes, channels and their various parameters. We (Me and Gaurav) have chosen our final year project as "Study and simulation of S-Mac protocol" which we are doing in NS. The installation of NS was a difficult task since we didn't get the proper help files. Among the few files we got, some of them were incomplete and some were wrong, so we were in trouble. Later with the help of my friends Pranav, Narayan (They were from Computer Engineering dept with sound knowledge of Ubuntu), i finally installed NS.

I am going to describe the procedures to install NS as follow:

1. Install necessary tools for building:
sudo apt-get install build-essential autoconf automake libxmu-dev gcc-4.3
2. Now follow the following steps for installation of nsallinone 2.34 and it will work with your machine. (copy ns-allinone-2.34.tar.gz) Suppose that there is "ns-allinone-2.32.tar.gz" in current directory (e.g. "~/" for me is"/home/sudip"). All steps are done in Terminal, so open a terminal in Accessories/Terminal. To extract the file:  
tar xvfz ./ns-allinone-2.34.tar.gz

3. It turns out that otcl does not like the version of gcc installed by default in Lucid. So go ahead and
change ns-allinone-2.34/otcl-1.13/Makefile.in. Find the line that says:
CC= @CC@
and change it to:
CC= gcc-4.3

4. Change your directory within terminal as following way(directory for you may be different than mine):
$ cd /home/sudip
$ cd /home/sudip/ns-allinone-2.34

5. Download & install some packages from repository if needed (Now its optional)
$ sudo apt-get install build-essential autoconf automake libxmu-dev

6. Install the ns2
$ cd ns-allinone-2.34
$ ./install

7. Edit some paths
$ gedit ~/.bashrc
Put these lines on that file in the last. Remember that the path for me is "/home/sudip". Replace these lines by your own path directory.

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/sudip/ns-allinone-2.34/bin:/home/sudip/ns-allinone-2.34/tcl8.4.18/unix:/home/sudip/ns-allinone-2.34/tk8.4.18/unix

LD_LIBRARY_PATH=/home/sudip/ns-allinone-2.34/otcl-1.13:/home/sudip/ns-allinone-2.34/lib

TCL_LIBRARY=/home/sudip/ns-allinone-2.34/tcl8.4.18/library

8. Save and reboot

9. Validate it (take very long time compare to install process)
$ cd ns-2.34
$ ./validate

10. Let it take effect immediately
$ source ~/.bashrc

11. Try to run it as following way, by just typing ns with terminal
$ ns
12. If the installation is successful, then you will be able to see % at the command prompt. Type following command to exit
% exit
Hope this may be helpful for you.

Thursday, March 10, 2011

Picture of Universe


Human thought and perception about the picture of universe has a long history from the starting of human colonization to the today’s twenty first century. The time before 0001 BC, which I like to call ancient era, the perception of people toward earth was a flat surface supported on the back by giant tortoise. Actually there was tower of tortoise, mathematically calling, an infinite tower of tortoise, and on the top our earth lies. Today’s people may think this as a ridiculous idea but what can we do for the great thinking of our forefathers of that era?

Among those great people, we shouldn’t forget the name Aristotle, a Greek philosopher (340 BC), wrote a book “On the Heaven” and became first to give a satisfactory picture of Universe. He was the first philosopher to give the revolutionary idea about the earth that earth is round, rather than flat. To support his idea, he gave example of eclipses of moon on which shadow of earth falls by blocking light coming from sun. The fact was the shape of shadow seemed curved rather than flat, which would be only possible if the earth was spherical. Another idea was the position of the north (pole) star, which used to appeared north in the sky. Greek people noticed that the position of north star appeared lower in the sky while they travel to the south. Obviously Aristotle was right about the earth, but wasn’t right about the universe. At his time, people knew about Sun, Moon, Stars and beside that the five planets: Mercury, Venus, Mars, Jupiter and Saturn. He believed that the earth was stationary and at the center of the universe. Sun, moon, planets and stars revolves around the earth. 

Aristotle’s model of universe (Source: http://csep10.phys.utk.edu/astr161/lect/retrograde/aristotle.html).

At that ancient era, that might be a satisfactory picture of universe and ruled for about 1800 years over human mind, then in the sixteenth century Nicholas Copernicus came with the idea that sun was stationary at the center and other planets moved in the circular orbit around the sun. His idea was supported by Johannes Kepler and Galileo Galilei though they didn’t sure about the orbit of planets. And a revolutionary year came, 1609, when Galileo observed Jupiter with his telescope and found several moons revolving around it. This showed that everything shouldn’t have to orbit earth directly, which leads to the failure of Aristotle’s theory about universe. Then Kepler suggested the orbit of planets to be elliptical rather than circular. And soon the idea that sun was at center and other planets revolves around it came, which was the same idea that we learned in our primary level science course. Similarly each planet had its own satellite or moon, like earth had its moon. 

The father of classical physics, who can forget his name, Sir Isaac Newton published his “Philosphiae Naturalis Principia Mathematica” in which he developed mathematical equations to analyze the motion of planets, moons, sun and even stars. It helped to predict the motion of bodies in space and time. Moreover his postulate of “law of universal gravitation” suggested the reasonable existence of space bodies in the universe. The human conception about universe was taking into shape. Great secrets of universe were being reveled with the advancement of science and technology. The idea that sun wasn’t actually at the center of universe, but it was only a part of it, it revolves round our home galaxy, the Milky Way galaxy. Furthermore people found that there were number of galaxies with interstellar cloud of dust, hydrogen gas, helium gas and other ionized gases forming Nebula. Originally, Nebula was a general name for any extended astronomical object and there were uncountable number of those Nebulae. So the concept of infinite universe came. It leads to the idea that our universe nearly looks like same from all side of the earth. 

Milky Way galaxy (source: http://en.wikipedia.org/wiki/File:Milky_Way_IR_Spitzer.jpg).

A beautiful picture of Nebula (source: http://en.wikipedia.org/wiki/File:Nursery_of_New_Stars_-_GPN-2000-000972.jpg).

Everyone knows something about Big Bang, most of you may have watched “The Big Bang theory”, a famous serial of today’s, but it has nothing to relate with the Big Bang that I am talking about. You may know about death of star forming black hole and other mysterious objects. I introduced the black hole since it has something to do with Big Bang. I want to introduce Penrose (theoretical physicist of todays), who carefully observed the death of star. During its death it increases its gravity in such an extent that it attracts its own mass inside it. This process continues until mass contracts to a point and the density is mathematically infinite. Another physicist of same time, Stephen Hawking analyzed Penrose’s idea and he thought it reversely. What if there was a point with infinite density at the beginning of universe, then big bang and then our entire universe formed. Though this was only a hypothesis, until 1970, when the joint paper by Penrose and Hawking was published. In that paper the hypothesis of big bang singularity was proved using Einstein’s general theory of relativity. Hence if Einstein was correct about relativity, then big bang must be correct. The famous saying of the paper that “there was in fact no singularity at the beginning of the universe” leads us to the starting of time. There was no time before the beginning of the universe and if there was something before big bang (beginning of the universe), that doesn’t affect anything after big bang.

Today, everyone believes that our universe is because of big bang and earth is a luckily formed planet in the continuous expansion of universe. Our scientists, physicists and astrologists are exploring our universe. One day, another general theory of universe might come and that might give us more accurate and more reasonable picture of our universe and answer our existence. 

(This article is inspiration from "A Brief history of time" by Stephen Hawking)

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...