31 August 2014

Brain to brain communication

I have long held the belief that any technology that you can imagine, is actually possible to create. As for wives who expect their husbands to read their minds, the appropriate tech is on it's way :) Something like the ideal UI which I wrote about.

Researchers and technologists from the University of Barcelona, Neurodynamics lab, Starlab, Axilum robotics, Neuroelectrics Barcelona, Cognition and brain plasticity unit, Berenson Allen center for non invasive brain stimulation and Havard medical school, Boston, have successfully transmitted a message directly from one human brain in Kerala to another human brain in France. Check it out!

This is done "non-invasively". Which means, that there are no wires inserted into your brain. All machines are outside (and it took more than 15 years of research to bring it to this stage).

The Brain to Computer Interface (BCI)
Uses an ElectroEncephaloGram (EEG) connected to the internet. The volunteer imagines moving his feet to stimulate the motor cortex of the brain which is captured by the EEG at a certain spectral power (voltage/frequency) and translated into the number 0. The volunteer imagines moving his hands and that's translated into the number 1.

To accomplish this, the volunteer was shown the sequence of 0's and 1's as a 0 on the bottom-right corner of the screen or a 1 on the top-right corner. When the volunteer saw the number, he had to imagine a leg movement or a hand movement so that the EEG picks up the signal.

They confirmed the correctness of whether to transmit the imagined data or not, using a ball which moves from left to right on the screen, at constant speed. Only if the number shown on the screen matches with what the volunteer imagines, will the ball hit the rectangular target on the right of the screen. Othewise, the ball moves vertically.

The Computer to Brain Interface (CBI)
Uses a Transcranial Magnetic Stimulation (TMS) that receives BCI data transmitted through the internet. The TMS machine stimulates bi-phasic pulses on the cortex area in the occipital lobe of the brains of three volunteers. They had to separately identify the phosphene (the feeling of seeing light although no light enters the eye. I wonder if this is the 'light' that NDE people see) producing area in the right visual occipital cortex area of each volunteer's brain.

The visual occipital cortex area of the brain

The intensity of the pulses can be adjusted such that the induced electric field can be oriented in two different angles; one angle representing the number 1 and the other perpendicular angle representing the number 0. Only the angle representing 1, produced phosphenes in the brain.

Sending and receiving
Using these techniques, on March 28th 2014, 140 numbers (called bits) were sent from Thiruvananthapuram by the BCI machine which used email to transmit the data, and were received by the CBI at Stratsbourg. The message was "hola" which was translated into bits. The second message sent was "ciao" (many people misspell it as 'chao').

The words were encoded using a 5 bit Bacon cipher and replicated for redundancy 7 times, randomized with random ciphers selected to produce balanced pseudo-random sequences of 0's and 1's. These were transmitted by the BCI at 3 bits per minute. The CBI received it at 2 bits per minute and the bits were de-cyphered and majority voting from the 3 volunteers was used to decode the message. For "hola", the transmission error rates were 6%, 5% and 11% for each volunteer. For "ciao", it was 2%, 1% and 4%.

Ensuring that the volunteers weren't guessing
Since these were 0's and 1's being transmitted, it's pretty-much like a coin being tossed. This technique of randomizing had to be used to ensure that the volunteers weren't guessing which bits were being received by the CBI. The probability of guessing 140 random bits with an error rate of 20% (28 errors out of 140) is very low (similar to the probability of ending up with 112 Heads for 140 coin tosses. The probability of it being 0.0000000000001).

The code
MATLAB was used for the programming. The code is from the plosone website.

Cipher used for word transmission:
To encode the 4-letter words we used a Bacon cipher (Matlab code follows):
%% First we encode the letters using the Bacon cypher:
h = [0 0 1 1 1];
o = [0 1 1 0 1];
l = [0 1 0 1 0];
a = [0 0 0 0 0];
% now we form the word bit string:
word=[ h o l a ];
% and the resulting strings repeated 7 times,
%% Encrypting and balancing (for later stat analysis)
% Repeat this block till you get a sum of 50% of the length for the sum.
% First, create the randomizing cipher
cypher = round(rand(length(repword),1)');
% Encrypt the word
transmit= mod(cypher+repword,2);
% check that we have 50% 1s and 0s:
sum(transmit) % should be 70=?10/2
%check we can decode after reception! This shoudl be zero:
sum(repword - mod(transmit+cypher,2))
%% Summarizing.
% Message to transmit:
% decoding cipher

E.g, the second 140 string transmitted was

transmit= [1 1 0 0 1 0 1 1 1 1 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 0 1 0 0 0 1 1 1 1 0 1 1 0 0 0 0 1 1 1 1 0 1 0 11 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 1 1 0 1 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 0 1 0 0 0 1 1 1 1 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1].

Decoding was done again by addition of the cipher mod 2. The resulting 140 bit string was then split into 7 blocks, and each block into 4 letters of 5 bits each. Majority voting from each block was used to fix the final bit value for the 20 bit encoded word.

Awesome! Isn't it? We're still a very long way to being able to use a device on our head which will allow us to communicate with others without even having to talk.

Just imagine:
  • You'll be able to transmit an image of a movie scene you watched (but forgot the name), into your friend's brain and ask your friend what the name of the movie was.
  • You'll be able to communicate with people who don't know your language.
  • You might even be able to communicate with animals (if mosquitoes could be made to wear the device, you could warn them to stop buzzing in your ear :) just kidding)
  • You'd be able to control devices just by imagining it!
  • People might eventually be able to read into other's thoughts (hacking), but by then there would be ways to block that too.

The internet would have to change significantly to adapt to this kind of a technology. A nice future is in store for human-kind.

The research paper which shares this technology, is here.

22 August 2014

Applying for a passport

My first suggestion to a person who asked me about applying for a passport was, "Google it" :) Turns out that the info on the internet is out-dated, so here's my help page:

The process of applying for a passport was a very tedious process earlier. Thankfully, now a lot seems to have changed. You can fill in your details online, make your payment online, you'll be given the option to choose which passport center you want to go to and on what date (long back, people had to go through a funny process of typing a captcha, clicking a button on the website at 6pm and hoping the server registers their request before the days quota expired; it usually expired within a few minutes) and simply turn up at the Passport Seva Kendra (the Passport Office) with the application form printout, the necessary documents in original and photocopies of those documents (they give you the option of scanning and uploading the documents, but that's not compulsory). Once you enter, you'll be out of the passport office in about four and a half hours. There's absolutely no need of getting it done through an agent.

Make sure you type the full expansion of your name in the application form. For references, you'd be better off giving references of your neighbours instead of your relatives (although relatives references are also accepted).

Here's a checklist and guideline for anyone going to the passport office:

  • Take a printout of the application form submitted online (if you end up with a very wide web page form which is difficult to print, you can use one of Mozilla Firefox's add-on's to convert the web page into a PDF file which will be easy to print).
  • Read the instructions given at the end of the application form.
  • The originals of the documents which provide your date of birth proof, address proof etc. (register yourself on the passport website and login. You'll be shown the list of documents you can produce)
  • Two photocopies of all those documents (put your signature on all the photocopies. That's what self-attested means)
  • A file or two for holding all those documents.
  • A bottle of water (you'll surely feel thirsty while waiting)
  • A sandwich or two (the food counter there is over-priced and not necessarily good)
  • A book or video-games or videos on your smartphone (cameras aren't allowed, but smartphones with cameras seem to be allowed. Just don't click photos of the place or you might get into trouble) or something to keep you occupied while waiting for hours.
  • A comb (a webcam will capture your photo for the passport, and you'd want to look good :-) )
  • A pen (not really necessary, but can come in handy)

If you're going to the Marathalli passport office at Sai Arcade, Bangalore, there's ample parking space at the basement, and if you prefer bus, you'll get bus number 500D from under the Hebbal flyover and from Silkboard junction (near the bridge). You'll have to disembark near Bangalore Central mall (just ask the bus conductor where to disembark).

What happens in the passport office:
You'll have to show a printout of the application form submitted online, to the guard standing outside. Only then you'll be let in. It has to look exactly like the printout page that's shown online (when I went to apply, there was a person with a printout of the application with the GMail logo; which means he emailed it to himself and printed the email. He wasn't allowed into the passport office).

The passport office is actually quite a small place.

Initial counter: Once you're in, search for the queue for new passport applications. The person at the counter will check the documents you brought and the photo-copy, and put it into a file and hand it over to you. They also give you a printout of a token number.

Then you move into a waiting area with just enough chairs to seat 80% of the applicants, and wait until your token number is called out (the numbers will appear on a display screen too). Moving to counter A happens within around 15 min.

Counter A: For every such so-called-counter, there are a bunch of 'cubicles' where officers process your documents.  At counter A, a person scans the necessary documents, scans your signature, takes your fingerprints and takes a photo of you with a webcam. Then you have to go back with your file, to the same waiting room and wait for around 1.5 to 2 hours until your name is called out again for your trip to counter B (that's when it's shown on the display).

Counter B: An officer verifies all your documents. If your documents are ok, this process won't even take two minutes. After this, you have to go to a separate waiting section near the C counters. You may have to wait here for another hour. When your name is called and displayed on another TV screen, you go to the C counter.

Counter C: Another officer has a look at your documents. This process doesn't even take 30 seconds if your documents are ok.

That's it. Once you're out of the C counter, there's a printer near the exit, where you'll be given a printout of an acknowledgement and you'll be given a feedback form which you can fill if you wish. Then you can walk out of the passport office.

Now, the process of sending applications from the passport office to the police station is no longer done by manually dispatching the physical files. It's instantly sent to the police station online, so you can get a call from the police station within 24 hours, with a policeman asking when he can visit for a verification (and an email stating that the police verification is pending. You won't receive an email about when the verification is completed though. I guess the reports are sent to the passport office manually).

Once the police verification is done, you'll receive an email and an sms on the 10th day, stating that your passport is printed and has been dispatched by speed-post. The next day you'll receive your passport. You have to be there to collect it. It won't be handed over to your family members. If you don't collect it, it'll go back to the post office and if not collected in 5 days, it'll go back to the passport office from where you will have to collect it.

I've heard of some people waiting for months to get their passport. Now it takes just eleven days! All the best!

17 August 2014

The Ugly Indian. Underground Festival

If you're an employed citizen, you're already doing your bit for society by contributing your skills to an industry. But what would you have to do to be a more responsible citizen? A citizen who actually improves situations, rather than just complain about it and say that nothing is going to improve?

Three years back, a little group of people took things into their hands and started cleaning up filthy areas with a simple motto "Mooh bandh. Kaam chalu" (meaning mouth shut; begin work). They did no activism, no awareness drives. Just a humble cleanup activity. Today, people across the world are asking them about their technique (I heard that news has even reached Canada). They're the Ugly Indians.

I wrote to them sometime ago about my views on volunteering and got a simple reply 
"Kaam chalu mooh bandh is the motto. Just come and work on a spotfix sometime. There is no talking in this initiative."
Makes sense. It speaks a lot about how they were able to move forward. Debating about things causes a lot of politics. Here, you just join in and clean up your city. Simple! 

How they do it

What we get to hear and see through the newspapers and social networking sites, is just the cream of the cake. There's a lot of hard-work and planning that goes into a spotfixing activity.
Where does the money come from? Once the garbage is collected, where is it dumped? Who supervises the cleaning and painting when it's clear that it's a bunch of amateurs who are painting?
Firstly, as a citizen, you can't simply start a spotfixing activity. You might accidentally cut a wire or break a water pipe. Every activity takes place with the permission of the BBMP and help from the BBMP people who help you to clear the garbage. I hear that the BBMP has issued an official circular across Bangalore, stating that they're working with TUI. Every new person is free to pay Rs.200 (or more) to financially assist a spotfixing activity. To know more, register for a spotfixing with this form (if you're in Bangalore) and this form if you're outside Bangalore. There's more info in the book.

The Underground Festival today: Heritage Walk

The objective was to make the subways around K.R.Circle worth walking through. Basically, it's possible to go all across K.R.Circle without once having to face the traffic on the road, because there are subways you can use. 
After a walk from Victoria statue, Mr. Arun Pai took us on a Bangalore Walk around K.R.Circle. I was amazed at the historic information he shared. King Krishna Raja Wadiyar's 25th year of reign (he ruled for 40 years) was when they built the K.R.Market, the K.R.Circle and the K.R. institutions. We owe a lot to the king, as he encouraged the advancement of Mysore and Bangalore.
K.R.Circle, the roads there and the buildings there were designed and built in the 1930's by visionaries. No building there was built after 1940. When India became independent, we built the largest building in Independent India - The Vidhana Soudha. Construction began in 1952 and took just 4 years to complete (now-a-days even flyovers take more time than that). Thousands of workers including prisoners worked on it. At this point our mayor mentioned that it was Mr. Kengal Hanumanthaiah who contributed to the construction of the Vidhana Soudha (double road is named after him, and is called double road because that's when the first concept of a road-divider came). It is said that the dome and the arch of the Vidhana Soudha are an Islamic structure, the pavilions are like those of the Hindu temples and the emblem is a Buddhist icon. It created a representative building of India. At that time, they didn't know where to build it, as there was so much land. So they said, Mr.Cubbon has a big house (Raj Bhavan), so let's build it in the back-yard of his house.

Did you know that there was a time when all watches that India used, were manufactured by HMT in Bangalore? In the 1950's every telephone made in India was manufactured in Bangalore (ITI). India got BEL and BEML. Asia's biggest hydroelectric plant was created with the help of GE engineers, and Bangalore was one of the first cities in India to get electrified. KEB and BESCOM are historic centers for Bangalore. 

HAL is the biggest aerospace complex in Asia. It was setup with the encouragement of the Mysore king. Sea planes used to land on Bellandur lake. That's the kind of technology we had at that time! In 1945 the world war ended and Mr.Nehru said that India would be non-aligned, so the British took all their planes and left ; except for a few planes, the engines of which they put sugar into so that the engine corrodes and it becomes unusable. Some very smart engineers from Bangalore reverse-engineered and repaired those planes in Kanpur, and flew them from Kanpur to Bangalore. A German man Kurt Tank, came to help us. He became an employee of HAL and in 1953, India's first fighter jet was made in Bangalore and we had air-power which prevented us from possibly being swallowed up by another country. One of those first fighter jets made in Bangalore is still visible at the Airforce mess at Trinity circle.
The space-race began when Russia launched the Sputnik. We built ISRO in Bangalore just three years after that.

As we kept walking in and out of the sub-ways, Mr.Arun told us more. The IISc was setup because of Mr.Jamshedji Tata. At that time the British opposed it saying that India was a land of superstitions and there was no place for scientific research. But Mr.Tata had kept aside some money which was meant only for the creation of a research institute, and although many cities were evaluated for the creation of the institute, eventually Bangalore was chosen. With the setting up of so many industries, came the need for educated individuals. Colleges were setup for this. Bangalore has the most number of Engineering colleges. UVCE was one of the earliest such colleges.

During the days of the Perl Harbour attack, something many don't know, is that Madras and Calcutta were also bombed by the Japanese. Bangalore was one of the safe havens for the British, and they quickly used HAL as their air force base. Fighter pilots used to relax in Cubbon Park while their planes were being serviced at HAL. Cubbon park was created in the 1860's at approximately the same time the grand central park was created in New York, and with the same objective. For citizens to have a place of leisure.

Bangalore had almost all of the firsts in industrialization in the country, and that too before World War I. Only a nuclear plant couldn't be setup in Bangalore because it required sea water. Else, Bangalore would have had that too :)

The Underground Festival today: Walk through the subways at K.R.Circle

It was amazing to see how the filthy subways were cleaned up (by 300 people) and setup as art centers. You could stroll along and look at photographs and paintings and even pose for photographs which would be emailed to you for free. Have a look!

Even our dear Mayor was present (white shirt). He himself had participated in painting some of the walls! Way to go Mr.Mayor!

This subway was one foot underwater just a few days ago. Was also used as a urinal. The Ugly Indians put in two weeks of work to get it cleaned and pumped out all the water.

Some lovely abstract paintings

The pic on the right is what it looked like. The left shows the Ugly Indians doing the cleaning

Art on display at the subway. They plan to hope to retain it like the boulevard at M.G.Road

All the hard-work

Three cheers!

Pose for a free portrait

Aaaandddd Cheese!

The Underground Festival today: The music, mime and painting

We had some nice bands play music to entertain the audience. Personally, I felt the percussion instruments and Beatboxing were the best! I've even recorded some of the sound.

Some sweet songs

Awesome percussion!

These rappers sang to the beat of 50 cent

Some awesome beatboxing

Some of the paintings created on the walls by volunteers (including me) today

It definitely beats sitting at home, strolling in a mall or going for a movie on a Sunday. You get to meet new people, learn something new and expand your skills. I learnt something new about wall painting.

I also noticed how people tend to get demotivated easily when they see somebody else making a much better piece of work. A person painting with me simply gave up because our painting didn't seem as good as the one opposite us. I continued and made our painting look good.

But remember, the event you see here is the cream of the cake. If you want to replicate it, don't just replicate the parts that look nice. Make sure you do all the necessary hard-work that makes such an activity the real success that it is.

There were no snacks, juice or water (there were free brushes, paint, masks and turpentine though). Everyone who came, came with the intention to volunteer, and that was the best part of it. Only the most genuine people come forward to volunteer when there's no other incentive.

After returning from the event, a person asked me "So they didn't give any food in the end?"
Me thinking: * Oh man! You just don't get the point, do you? :-) *

16 August 2014

Mutex tutorial and example

It began while being asked to watch one of Yashwant Kanetkar's slow video tutorials at my workplace. He explained every concurrency concept with an example, but for mutexes, he said "I leave it to you as an assignment". *groan*. To add to the difficulty, there weren't any decent tutorials on the internet either.

So one day when a lightbulb lit up in my head, I decided to create my own mutex example.

Here it is

A lot of people run to a lone phone booth (no mobiles) to talk to their loved ones. The first person to catch the door-handle of the booth, is the one who is allowed to use the phone. He has to keep holding on to the handle of the door as long as he uses the phone, otherwise someone else will catch hold of the handle, throw him out and talk to his wife :) There's no queue system as such. When the person finishes his call, comes out of the booth and leaves the door handle, the next person to get hold of the door handle will be allowed to use the phone.
A thread is : Each person
The mutex is : The door handle
The lock is : The person's hand
The resource is : The phone
Any thread which has to execute some lines of code which should not be modified by other threads at the same time (using the phone to talk to his wife), has to first acquire a lock on a mutex (clutching the door handle of the booth). Only then will a thread be able to run those lines of code (making the phone call).
Once the thread has executed that code, it should release the lock on the mutex so that another thread can acquire a lock on the mutex (other people being able to access the phone booth).

Blue is the protected area of code.
Red is where the locking happens.
Green is where the unlocking happens.

#include <iostream>
#include <thread>
#include <mutex>

std::mutex m;//you can use std::lock_guard if you want to be exception safe 
int i = 0; 
void makeACallFromPhoneBooth() 
    //The other men wait outside 
    m.lock();// one man gets a hold of the phone booth door and locks it. 
      //man happily talks to his wife from now....
      std::cout << i << " Hello Wife" << std::endl;
      i++;//no other thread can access variable i until m.unlock() is called
      //...until now, with no interruption from other men
    m.unlock();//man unlocks the phone booth door 

int main() 
    //This is the main crowd of people uninterested in making a phone call

    //man1 leaves the crowd to go to the phone booth
    std::thread man1(makeACallFromPhoneBooth);
    //Although man2 appears to start second, there's a good chance he might
    //reach the phone booth before man1
    std::thread man2(makeACallFromPhoneBooth);
    //And hey, man3 also joined the race to the booth
    std::thread man3(makeACallFromPhoneBooth);

    man1.join();//man1 finished his phone call and joins the crowd
    man2.join();//man2 finished his phone call and joins the crowd
    man3.join();//man3 finished his phone call and joins the crowd
    return 0;
Compile and run it using  
g++ -std=c++0x -pthread -o thread thread.cpp

Memory fencing
Do you know that while processing instructions, threads recognize that an area of code is protected by a mutex, through the concept of memory fencing.
A memory barrier, also known as a membar, memory fence or fence instruction, is a type of barrier instruction which causes a central processing unit (CPU) or compiler to enforce an ordering constraint on memory operations issued before and after the barrier instruction. This typically means that operations issued prior to the barrier are guaranteed to be performed before operations issued after the barrier.

It's basically some CPU instructions that inform a CPU that a region of code should not be accessed for a while.

Lockless programming
Did you also know that it's possible to design your algorithm in a way that it might use shared memory, and yet not need to use mutexes? Typically, such instructions are processed in such a way that a group of load and store instructions are executed atomically (transactional memory). This is achieved by using hardware intrinsic atomic operations.
An algorithm is lock-free if there's a system-wide progress regardless of scheduling, and an algorithm is wait-free if there's also a per-thread progress.

If you'd like to say thank you, a chocolate from my Amazon WishList would be nice :-)

Calculating perspective projection

All those motivational talks and sayings about one being able to achieve what they really want, is actually true. You just have to know how. While programming my games, I had for a very long time wanted to create a game in 3D. Whenever a vehicle would move through a tunnel or narrow area, I'd observe carefully, how every point moved with respect to each other. The 3D feeling!

As I learnt trigonometry and geometry, my ability to understand dimensions got better, and I tried plotting points on paper, imagining 3D situations and using the laws of geometry to try and derive an equation which would be able to plot and erase (creating the effect of an animation) on a 2D screen, the points I observed in the tunnel.

All this was long before I had internet access or access to a good library.

The first attempt ended up in a long equation which didn't work when I wrote a program to plot points in 3D:

I guess I was just about crazy enough to derive these when in twelfth standard :-)
And then I tried again:

and again and again until I finally, I decided that it was far simpler if I didn't consider all four quadrants, and instead considered the computer screen to be a single quadrant where x and y were positive. That simplified the calculation and I also got it right!

And when used in a C program like Unipar, would look like this:
(note how the function is declared first and the datatypes are declared in the next two lines. This is legal C)

void perspective(x,y,z,x2,y2,z2,tx,ty,tz)
int x,y,z,x2,y2,z2;
float tx,ty,tz;
int Z=500,XC=240,YC=250;
float i,j,k;
float r,c,X,Y;
if (z>=Z) {printf("move the observation point farther");getch();return(0);}
if (beam.perspective==1)
else {r=j+YC;c=i+XC;}
if (beam.perspective==1)
else {X=i+XC;Y=j+YC;}

/*to rotate in 3D*/
void rot3d(a,b,c,T,axis)
float *a,*b,*c,T;
int axis;
float x,y,z;
case 1: /*-- x axis rotn --*/
case 2: /*-- y axis rotn --*/
case 3: /*-- z axis rotn --*/
}/* end of 3d rotn */

Had found these derivations in one of my old notebooks, and I thought I'd put it up here for my own reference and perhaps even in case it inspires any bright kid to try some brain-work magic of their own :)

09 August 2014


Continued from the previous LOL page.

Turning left
share with this link

Store bills
share with this link

Continued in the next LOL page.