The age old debate

January 19, 2010

Yes…. Macs vs PC, and now that I own both I can pass a judgement.

The debate is the most over-rated debate of all.

Here is what put it in perspective.

PCs + Windows:


  • Ranging from dirt cheap to bloody expensive.
  • Windows Vista SUCKED, Windows 7 ROCKS.
  • You can find stuff very easily
  • You can find help easily
  • Engineer’s Heaven
  • Gamer’s Heaven


  • A bitch to Configure.
  • Shit screws up more readily. Though Windows 7 Rarely does.
  • Viruses…. Get Malwarebytes anti-Malware and update and run it once a week. DUH?!

Mac OS X


  • Works great with hardware,
  • Looks fabulous
  • Its a fashion statement
  • Great Applications
  • Great UI


  • OLD version of word, Word 2008 for mac amounts to Word XP!
  • Apps are slightly harder to find and harder to get.
  • Windows 7 is almost as great in UI.
  • Hardware is bloody expensive.

So now that we have that out of the way, lets talk reality, I mean more reality than this. Well Mac is like a ferrari, its a rich man’s way of saying I work too. It works great out of the box, sure but you still have to install Office, and you, Sure You get nifty gadgets but you pay loads to get em.

PCs are the poor man’s workhorse, or rather a mule.Sure, they crash, they are bloody hard to use, You want to bang your head on them and shove them out of the window… or just simply chuck the windows bit, if you can use Linux (Kubuntu/Ubuntu ROCKS), and sure You dont feel a connection with them. But when you need shit done, you need to run simulations, you need to develop games or anything for that matter, you use a PC, or rather windows. And finally Since Windows 7, its getting a whole lot easier to use a PC too.

But yes, You ll always love your mac, There is something personal about it. Its the culmination of hardware and software at their very best. You can use them for hours and hours and you still want to keep using them. But they are bloody expensive, the cheapest one costs about a thousand bucks US, and a comparable PC laptop would be almost as good, But the “almost” is the bit where the difference lies, with a PC lappy you get a standard single touch pad, a cluncky keyboard with a lot of stickers, a big screen and loads of USB slots and a display port, a carry bag and what not. This a mac, you dont even get a display port, you get a multipurpose firewire thing to which you need to put in adapter cables to connect to a projector, and if you include the price of all these accessories that make it comparable to a PC lappy, it ll cost you dearly (about 1300 bucks US dearly!), you get few USB slots, a smaller screen and a very plain looking keyboard and not mouse buttons, with a prehistoric office suite if you can a) afford it or b) criminal enough to get a pirate copy and equally prehistoric games…. and you know what? Thats what is brilliant about it. you use that small screen so efficiently combined with that awesome multitouch pad you do the same amount of work in shorter time, its does nt hang up, and dont pop stupid messages every now and then, the interface is uncluttered and accessible, even that old word feel good to use. You dont have to do stupid configurations and dont even have to go to stupid forums to get your problems sorted out, the iLife suit is awesome, and iWork has brilliant looking templates.

So it all comes down to money, if you have it, go buy a mac, if you dont, stick to a PC

Or if you are an engineer like me, buy a PC and get kubuntu…. Thats the way the rock stars do it! Or better yet, get both, then you ll have one big happy family!


Its clunky, and crude, BUT IT WORKS!

December 22, 2009

These videos are from the first runs, so you can see quite many false detections and what not. By the time I had tweaked the system to my best, I did nt want to record any more videos. But hey something is better than nothing, so here is nothing!

Kalman Filter’s Daddy!

November 13, 2009

Aaaaah! Research! Oh how much I love thee, and how much I HATE thee!

Khair… I have been trying to understand how actually Kalman filters work for a while now and Believe me when I tell you they aint easy! I went through hell to get the knots in my brain straightened out! I read a book called Introduction to Random Signals and Applied Kalman Filtering in about two days, at least the first 6 chapters! I reference a gazillion papers and other material online, talked to a mathematician, run simulations and what not… the list goes on. Heck I was so frustrated and unsure of myself that I had to relearn my 4th semester signals and systems course (the state spaces part).

Who knew in the end good old fashioned tinkering would make it work. So! I have decided that I would nt let the other people looking for a quick KF fix roam around aimlessly like particles in Brownian motion in the dark…

Ok first thing I learnt was that you need the theory, I read this fairly complicated and annoying book mentioned above… After reading the chapter like 3 times, I was able to grasp (somewhat) what it was trying to say. But the prolem is (I think that the equations dont directly apply for some reason when implementing the damn thing…. Plus most of the time you would be wondering how to calculate and use most of the variables. So yes in short its not the way to go if you are thinking of applying it in the near future.

But the reading part is very necessary, cuz you definitely need to know the why  part… for the how, go to this fairly good article on Ok this article also get confusing as it does nt tells you a LOT of things… like how will you be calculating the noise covariances and what is the difference between measurement noise and process noise.

To answer these very relevant questions I m writing this article.

First of I m going to show a very simple example…. nothing complicated… What I m going to do is collect data from a single accelerometer and filter its output rather than the position data calculated from it. This reduces most of our state space matrices to 1. The commonly used system eqs are

x_hat_dot     =     A_mat * x    +    B_mat * u     +     w

y              =               C_mat * x        +        z

Ok…. to explain what these are you ll need to read some basic text on state spaces, I would recommend Signals, Systems, and Transforms by C.L.Phillips, J.M.Parr and E.A.Riskin. I am not going to go through that over here… NO CHANCE IN HELL!

So moving on to Kalman filters and our simple filtering app…. What I did was simply record a lot of data from the accelerometer and calculate the mean and variance/standard deviation parameters for the data. There is a small problem where that needs to be address. most sensors give the zero force point by Vcc/2, and since the filter parameters require the mean to be near zero and the SD to be around it, a transformation is in order.The easiest say is to subtract the average and divide by the gravity value. So thats that…. Now we have our sensor data and its parameters. the measurement and process noise are supposed to be different for the system. But while playing around with the values I found that if you Q as SD ^ 2 and R as SD you get an awesomely filtered result. Now dont ask me why the works. But theoretically R should be the SD and Q should be calculated from the A matrix and some other info about the process.

So the simple program that I ran in MATLAB is:


phi_k = 1;
H_k = 1;
R_k = (7.29738/(3113.08-2131.33));
P_min_k (1) = 0;
Q_k = R_k ^ 2;
P_k(1) = 1;
x_hat (1) = 0;
n = size1/NumberOfColumns;
for i = 1:n -1
%     K_k(i) = P_min_k (i) * H_k * inv(H_k * P_min_k (i) * H_k + R_k);
%     x_hat(i) = x_hat_min + K_k(i) * (da1(i,1) - H_k*x_hat_min);
%     x_hat(i+1) = phi_k * x_hat(i);
%     P_k (i) = (1 - K_k(i) * H_k) * P_min_k(i);
%     P_min_k(i+1) = phi_k * P_k(i) * phi_k + Q_k;
K_k(i) = phi_k * P_k (i) * H_k * inv(H_k * P_k (i) * H_k + R_k);
x_hat(i+1) = phi_k * x_hat(i) + K_k(i) *(da1(i,1) - H_k*x_hat(i));
P_k(i+1) = phi_k * P_k(i) * phi_k + Q_k - phi_k * P_k(i) * H_k * inv(R_k + P_k(i)) * H_k * P_k(i) * phi_k;
hold on;
plot(K_k, '-r');
plot(P_k, '-b');
plot(P_min_k, '-g');
hold on;
plot(da1(:,1), '-g');
% plot(x_hat_min, '-r');
plot(x_hat, '-b');


phi_k = 1;H_k = 1;R_k = (7.29738/(3113.08-2131.33));P_min_k (1) = 0;Q_k = R_k ^ 2;P_k(1) = 1;

x_hat (1) = 0;n = size1/NumberOfColumns;
for i = 1:n -1%     K_k(i) = P_min_k (i) * H_k * inv(H_k * P_min_k (i) * H_k + R_k);%     %     x_hat(i) = x_hat_min + K_k(i) * (da1(i,1) - H_k*x_hat_min);%     x_hat(i+1) = phi_k * x_hat(i);%     %     P_k (i) = (1 - K_k(i) * H_k) * P_min_k(i);%     P_min_k(i+1) = phi_k * P_k(i) * phi_k + Q_k;    K_k(i) = phi_k * P_k (i) * H_k * inv(H_k * P_k (i) * H_k + R_k);        x_hat(i+1) = phi_k * x_hat(i) + K_k(i) *(da1(i,1) - H_k*x_hat(i));        P_k(i+1) = phi_k * P_k(i) * phi_k + Q_k - phi_k * P_k(i) * H_k * inv(R_k + P_k(i)) * H_k * P_k(i) * phi_k;
figure;hold on;
plot(K_k, '-r');plot(P_k, '-b');plot(P_min_k, '-g');xlabel('Time/sample');ylabel('Bits');title(strFileName);
figure;hold on;
plot(da1(:,1), '-g');% plot(x_hat_min, '-r');plot(x_hat, '-b');xlabel('Time/sample');ylabel('Bits');title(strFileName);



Keep in mind that the Data was already loaded into the MATLAB workspace. The figure of interest is

kalmanWorks like a charm.


Dont ask me how or why though… I m just happy it does!

Accelerometer Data

February 28, 2009

After a lot of toil and time (or not), I finally got my data from the accelerometers, and it does nt look bad at all! (Maybe good even!). I can now proceed towards analysis and make a scheme out of these. But there is a catch that I see in the preliminary results, I may need a better ADC and a much much better processor than the itty bitty ATMega168 on an Arduino board that I m using currently.

I need to write a report and submit it within this week about my results. Results are pretty much as I expected, I learned that I definitely need to filter my signals, which means computational power, (Kalman Filter maybe?) and that I can give a good estimation of tilt with the current sensors. I have nt been able to see forces, and partly because of the ADC. Forces are very very short in duration and I need a faster sampling to get some good data. Maybe 10, 20 times better sampling rate would give me better results. This would mean new components and new components would in turn mean a learning curve. I m swamped with assignments so I ll be putting this off for a little later, or maybe just slow down my pace so I can compensate.

Of Gyroscopes And Accelerometers

January 25, 2009

These days I have nothing much to do about my project, since I have ordered parts and waiting for them to arrive. I have always hated waiting, I m an impatient and impulsive person tending to have more than one obsessive compulsive disorders. But thats not what the post is about, so my current objective is to make a remote unit which can be used to determine the relative position of the user.

Now relative position may mean a lot of things and therefore in this context it means the current position with respect to the previous position. Now what I have decided is to do this use inertial sensors.

What are inertial sensors? They are sensors used to measure the change in inertia applied to the sensor, in lay man’s terms, if you apply a force and the object STARTS or stops to move, these sensors would give a corresponding voltage value. Now this is also not for the complete lay man (Read ouff) but I dont know any way simpler to explain this.

Ok, anyone who’s worked on this stuff would say big deal, This is old old technology and people have been using IMU (inertial Measurement Units) and INS (Inertial Navigation Systems) for a while now so whats new here. Well to tell the truth, nothing is really new here… Hell some people have also used this for smaller applications too like for determining orientation of an object. So there is nothing new to this… So why am I doing this and why the heck am I writing about it? Well I m thinking up a way to do this just by employing accelerometers! I bet this can be done, I m still working out the theoretical details. Now why would I use only accelerometers and not Gyros.

For that let me first explain what are Gyros and What are accelerometers. So the latter first, accelerometers are devices used to calculate translational acceleration, translational means moving from one point to another in a straight line. Now Gyros are more fun, they are used to measure rotational velocities, Now using the two together is usually the method used by everyone. But Gyros are expensive and difficult to get measurements from, plus you need to implement more household circuitry to maintain an output from them. While accelerometer are much more easier to do. So my motivation is simple. To make it easier for myself. But the more I come to think about it the more discouraged I get about this idea. Cuz the maths involved is way out there.

People, Any bright ideas? Please help!!!

Skittles and Me

January 14, 2009

I m pretty baffled by the size and scale of my project… And the quantity of expectations that my supervisor has of me and thus the proportional work required of me. He probably think I m some unsung under dog wiz kid outta Karachi who is just about to spread his glorious wings and stun the world. In the words of the Great Danny Crane, He wants me to pull a rabbit outta my hat (or ass, cuz I dont really have a hat).

I was lately studying Multi touch screens, I did a post somewhere here. Dont expect me to make it any easy for you and hyperlink that link here, GET IT YOURSELF!!!!. Now I m working on incorporating Gyroscopes and Accelerometers to give a more engrossing feel to the user carrying this remote unit which would be used in the project. Which is supposed to be somewhat familiar territory

Now previously, before the advent of the acclaimed iPhone, accelerometers (and Gyros) were some obscure sensors which only military used. Hell no body probably did nt even know their name and what they were used for.

So Currently I m making a design and a scheme which is used to to give a relative position (from the previous position) of a remote unit which you can currently think of as a 3-dimensional mouse. The idea I have right now is the combined effort (brain storming) of me with a german dude name Micheal Leigsnering (sorry dude if I mispelled your name). Since the idea is nt mature yet, I ll just keep it to myself and work on it, so that I dont give you guys any reason to call me nerd or geek or stupid.

So why am I writing this post??? Cuz I m on an overdose of sugar (read skittles) and my brain is on overdrive. I m at my lab sitting by my workstation with a bag of skittles. I have a habit of keeping a bag of skittles on me while I m working and write down some of my thoughts and ideas so that I can keep them in perspective and make references. So this post is kinda my reference point at the moment.

Project Proposal

October 28, 2008