Archive for the ‘KnowHow’ Category

Kubuntu 15.04 Playback Control Media Keys not working

July 24th, 2015 No comments

For some reason, while the other 2nd functions keys were working fine, the Play/Pause, Previous & Next keys stopped working in Kubuntu 15.04 since the clean installation. Volume buttons were working fine.  Upon lot of digging, finally the solution was just a workaround by using MPRIS-remote.

sudo apt-get install mpris-remote

Goto System Settings->Shortcuts->Custom Shortcuts

Edit -> New Group -> “Media Player”

Edit -> New -> Global Shortcut -> Command/URL

Enter “Media Play” for the command name.

On the right pane, Click on “Trigger” -> Set the shortcut key;

Click on “Action”-> “/usr/bin/mpris-remote pause”.

Likewise create commands “Media Next” : “/usr/bin/mpris-remote next”

and “Media Previous” : “/usr/bin/mpris-remote previous”.

Clementine is a MPRIS compatible player, which means this hack solves the problem!


How to make Kate remember last opened files

October 22nd, 2014 No comments

Kate allows document editing to be grouped under separate sessions.  Although there is no direct configuration setting to make Kate auto-open last opened files during startup, the Sessions features come handy.  The workaround is; given that Kate remembers last opened file paths in the File -> Open Recent menu item, you may select files one by one to continue editing.  But, this is so boring.

The procedure is the following:

  1. Open all the files that you want to be remembered by Kate for reopening during next restart of Kate.
  2. Click on Sessions->Save Session As->[give a session name here to save the session]
  3. Close your Kate application.
  4. Open it again, you would see no files reopened automatically, Don’t Panic!
  5. Click on Sessions->Quick Open Session->[session name].
  6. Aha… all the files that you had put into the session will reappear.

How fast is integer arithmetic than floating point arithmetic?

June 19th, 2013 No comments
You may already know that integer arithmetic is faster than floating point arithmetic. But how fast? I had the same question in my mind. So created the following script to test the “fastness” for each data type.

#include <vector>
#include <iostream>
#include <cstdlib>
#include “Stopwatch.hpp”

template <typename T>
void test( size_t inArraySize, size_t inCorpusSize )
    typedef std::vector<T> array_t;
    typedef std::vector<array_t> arrays_t;

    std::cout << “constructing the corpus…”;

    Stopwatch sw;
    arrays_t corpus( inCorpusSize + 1);
    for ( size_t i = 0; i < inCorpusSize+1; ++i )
        array_t &array = corpus[i];
        array.resize( inArraySize );
        for ( size_t j = 0; j < inArraySize; ++j )
            array[j] = (T)( rand() );

    std::cout << sw.Elapsed() << ” secs” << std::endl;

    std::cout << “scored in … “;
    array_t scores( inCorpusSize );
    const array_t &query = corpus[0];
    for ( size_t i = 1; i < inCorpusSize+1; ++i )
        const array_t &array = corpus[i];

        register T &score = scores[i1];
        score = 0;
        for ( size_t j = 0; j < inArraySize; ++j )
            score += array[j]*query[j];

    std::cout << sw.Elapsed() << ” secs” << std::endl;


int main( int argc, char **argv )
    if ( argc < 2 )
        return 1;

    int csize = atoi(argv[1]);
    int asize = atoi(argv[2]);

    std::cout << “testing float..” << std::endl;
    test<float>( asize, csize );

    std::cout << “testing double..” << std::endl;
    test<double>( asize, csize );

    std::cout << “testing long double..” << std::endl;
    test<long double>( asize, csize );

    std::cout << “testing int..” << std::endl;
    test<int>( asize, csize );

    std::cout << “testing unsigned int..” << std::endl;
    test<unsigned int>( asize, csize );

    std::cout << “testing short..” << std::endl;
    test<short>( asize, csize );

    std::cout << “testing unsigned short..” << std::endl;
    test<unsigned short>( asize, csize );

    std::cout << “testing char..” << std::endl;
    test<char>( asize, csize );

    std::cout << “testing unsigned char..” << std::endl;
    test<unsigned char>( asize, csize );

    std::cout << “testing long long..” << std::endl;
    test<long long>( asize, csize );

    std::cout << “testing unsigned long long..” << std::endl;
    test<unsigned long long>( asize, csize );

    return 0;

Syntax highlighting done by: /usr/bin/highlight -O html -t 4 -I -S cpp Main.cpp –inline-css -o /tmp/m.html

The result of running this script with vector size = 100 and corpus size = 1 million is shown below:
sudar@kiriya /opt/testing/bin $ ./tester 1000000 100
testing float..
constructing the corpus…1.447 secs
scored in … 1.731 secs

testing double..
constructing the corpus…1.543 secs
scored in … 1.836 secs

testing long double..
constructing the corpus…2.135 secs
scored in … 2.614 secs

testing int..
constructing the corpus…1.454 secs
scored in … 1.657 secs

testing unsigned int..
constructing the corpus…1.41 secs
scored in … 1.615 secs

testing short..
constructing the corpus…1.394 secs
scored in … 1.59 secs

testing unsigned short..
constructing the corpus…1.347 secs
scored in … 1.542 secs

testing char..
constructing the corpus…1.313 secs
scored in … 1.507 secs

testing unsigned char..
constructing the corpus…1.328 secs
scored in … 1.522 secs

testing long..
constructing the corpus…1.553 secs
scored in … 1.767 secs

testing unsigned long..
constructing the corpus…1.548 secs
scored in … 1.761 secs

  1. If you observe carefully, floating point calculations have taken more time than the fixed point calculations.
  2. Long Double took the longest time and it is the slowest.
  3. The reverse climax is that 64bit fixed calculation is slower than single-precision arithmetic.  An interesting read on multiplication is here.  The reason could be overflow due to the size of product register being 64 bits.
  4. The fastest is 8 bit calculation.  But unsigned 8 bit arithmetic is slower than signed.  Can’t explain why!
  5. For fixed point, unsigned calculations take less time than signed calculations, which can be understood by the additional time taken for 2’s complement arithmetic.
  6. Results can be different with different CPUs / Operating Systems, so infer accordingly.

Upgrade version of the testing application.
#include <vector>
#include <iostream>
#include <cstdlib>
#include “Stopwatch.hpp”
#include <string>
#include <map>

template <typename T>
double test( size_t inArraySize, size_t inCorpusSize )
     typedef std::vector<T> array_t;
     typedef std::vector<array_t> arrays_t;

     arrays_t corpus( 2 );
     for ( size_t i = 0; i < 2; ++i )
          array_t &array = corpus[i];
          array.resize( inArraySize );
          for ( size_t j = 0; j < inArraySize; ++j )
               array[j] = (T)( rand()%1000 );

     Stopwatch sw;
     const array_t &query = corpus[0];

     array_t scores( inCorpusSize );
     for ( register size_t i = 0; i < inCorpusSize; ++i )
          const array_t &docu = corpus[1];
          T & score = scores[i];
          score = 0;
          for ( register size_t j = 0; j < inArraySize; ++j )
               score += docu[j]*query[j];

     return sw.Elapsed();

int main( int argc, char **argv )
     typedef double (*fun_t)( size_t, size_t );

     typedef std::pair < std::string, fun_t > named_fun_t;
     std::vector< named_fun_t > functions;

     functions.push_back( named_fun_t( “float”, test<float>) );
     functions.push_back( named_fun_t( “double”, test<double>) );
     functions.push_back( named_fun_t( “long double”, test<long double>) );
     functions.push_back( named_fun_t( “int”, test<int>) );
     functions.push_back( named_fun_t( “unsigned int”, test<unsigned int>) );
     functions.push_back( named_fun_t( “short”, test<short>) );
     functions.push_back( named_fun_t( “unsigned short”, test<unsigned short>) );
     functions.push_back( named_fun_t( “long long”, test<long long>) );
     functions.push_back( named_fun_t( “unsigned long long”, test<unsigned long long>) );
     functions.push_back( named_fun_t( “char”, test<char>) );
     functions.push_back( named_fun_t( “unsigned char”, test<unsigned char>) );

     if ( argc < 4 )
          std::cout << argv[0] << ” <corpus_size> <array_size> <repeats>” << std::endl;
          return 1;

     int csize = atoi(argv[1]);
     int asize = atoi(argv[2]);
     int iters = atoi(argv[3]);

     typedef std::map<std::string, double> timings_t;
     timings_t timings;

     for ( size_t j = 0; j < iters; ++j )
          std::cout << \niteration #” << j+1 << std::endl;
          for ( size_t i = 0; i < functions.size(); ++i )
               std::string name = functions[i].first;
               double timetaken = functions[i].second(asize, csize);

               timings[name] += timetaken;
               std::cout << “testing “ << name << “….” << timetaken << std::endl;

     std::string minstring;
     double minvalue = 99999.9;
     std::cout << \naverages” <<std::endl;
     for ( timings_t::iterator iter = timings.begin(), end = timings.end(); iter != end; ++iter )
          iter->second /= (double)iters;
          std::cout << “average time for “ << iter->first << “: “ << iter->second << std::endl;

          if ( iter->second < minvalue )
               minvalue = iter->second;
               minstring = iter->first;

     std::cout << “minimum timing is for “ << minstring << “: “ << minvalue << std::endl;

The result of running this script with vector size = 500 and corpus size = 1 million with 20 iterations is shown below:

iteration #1
testing float….1.473
testing double….1.469
testing long double….2.025
testing int….1.024
testing unsigned int….1.069
testing short….0.996
testing unsigned short….0.993
testing long long….1.004
testing unsigned long long….1.004
testing char….0.991
testing unsigned char….0.991

iteration #2
testing float….1.449
testing double….1.459
testing long double….2.011
testing int….1.002
testing unsigned int….1
testing short….0.985
testing unsigned short….0.99
testing long long….0.993
testing unsigned long long….0.993
testing char….0.983
testing unsigned char….0.992

iteration #20
testing float….1.448
testing double….1.45
testing long double….1.975
testing int….0.99
testing unsigned int….0.991
testing short….0.989
testing unsigned short….0.986
testing long long….0.997
testing unsigned long long….0.992
testing char….0.992
testing unsigned char….0.988

average time for char: 0.99575
average time for double: 1.4665
average time for float: 1.4676
average time for int: 1.0046
average time for long double: 2.00115
average time for long long: 1.00585
average time for short: 0.99985
average time for unsigned char: 0.9945
average time for unsigned int: 1.0085
average time for unsigned long long: 1.0025
average time for unsigned short: 0.9963
minimum timing is for unsigned char: 0.9945

So, even in this test, char is the best choice!!

1KWp Solar Power Plant

January 30th, 2013 22 comments

Phew! What a relief!

I have just finished installing a 1KWp solar power plant in my apartment.  It was an wonderful and tiring experience getting everything to work together, ofcourse with the help of several kind people who helped moving on with the work.  I think, my installation is the first domestic installation for a capacity >1KWp in my entire area, that is Thirumullaivoyil; may be the first in Ambattur + Avadi townships.  Whatever be it, I am very happy that I could get it up and running as per the plan.  The power plant can produce upto 4-5KWh everyday in winter+sunny and may be 5-6KWh in summer.  I have been able to attach everything in my home except for Fridge, Ovens, Water heater, A/C and washing machine.  Yeah! Mixie, Coffee Maker, Wet Grinder, Computers, Water purifier run in solar at my home!  I tried attaching Fridge to the unit, but the backup time in the nights drastically reduced.  By the way, the solar power supply is 24hours through out.  The secret is that the excess power produced in the day are backed up in huge batteries, so that the saved energy is dispensed through out the night for powering my bed room and other low power night utilities.

Things to procure for this DYI project:

  1. Solar Panels: There are several variety of panels available, but always choose polycrystalline (aka multi-crystalline) panels, as there are very efficiently within 30 degree deviation of sunlight inclination angle.  If you go for monocrystalline, they are efficient only when the sun is right on top of them, so you are forced to install a solar tracking device for an additional cost.  I had procured MNRE approved panels for Rs 46/watt including transportation and taxes from Akshayasolar.  My setup has 12V 150Wp x 6 and 100Wp x 2, put together 1100Wp of bright power.
  2. Inverter: There are several varieties of inverters available in the market. Solar Inverters are the ideal choice here, but for my specification I could not get a solar inverter within my budget.  Typically solar inverters are priced around Rs 30000 for a 1KW capacity.  So, I had decided to go to regular sine-wave inverters and convert that to a solar inverter myself.  To convert an inverter to a solar inverter, I had to get a solar charge controller and fabricate a control circuitry.  I have bought a 24V, 1.4KVA Amaron Inverter for Rs 7000, with 2 years warranty.  A typical inverter has a power-factor of 0.7 to 0.8, so I could load upto 1000W comfortably without frying the inverter.
  3. Batteries: This is the most critical part of any ESU (Energy Storage Unit), where the power is stored during surplus and released when solar incoming reduces.  On the contrary, there are EEU (Energy Export Unit), which directly converts the energy derived by the solar panels into useful power for consumption or resale back to the grid.  TANGEDCO does not buy from installations less than 1MWp, so ESU is my only option.  So storing the power, the popular choice is Exide Solar Tubular batteries.  But, I chose Sharana Batteries because their manufacturing unit is in Ambattur Industrial Estate, and their service guarantee was better than what Exide offered.  While buying batteries, one should be very careful about the capacity rating of the batteries.  By capacity, the common misnomer is the AH rating.  AH rating tells the current limits of a battery, but the capacity rating is mentioned as Cxx (eg: C10, C20, etc).  Typically, a 180AH/C20 battery is same as the 150AH/C10 battery or 100AH/C5.  In C20 rating, if the drain current should be 9A, the battery would supply energy for 20 hours.  The same battery would serve for 8.33 hours only if the drain current is 18A, but you would expect it to serve for 10 hours.  Likewise, the same battery would serve only for 2.77 hours, if the drain current was 36A where you would expect a backup time of 5 hours (see here the capacity has halfed!!).  I have purchased 2x180AH @C20 tall tubular batteries from Sharana with 2 years warranty for Rs 26000.
  4. Charge Controller: There are two types of charge controllers available namely PWM, MPPT. Solar panels, although rated as 12V, they generate voltages upto 21.6V (open-circuit).  They are optimal at around 16.4-17.4V, which is called the maximum power point.  In order to leverage the maximum power from the controller, I used MPPT charge controllers.  For 1.1KW at 24V, the Imax is 50A, but assuming 80% efficiency for panels, 40A MPPT is sufficient.  I got 40A 24V controller from Adaptek India, Adyar for Rs 13600 with 3 years warranty.
  5. Structure Fabrication: This is the messy part of the entire exercise as readymade units were not available.  Since I will be using 8 panels in total and I had to use just 100 sq.ft of space on the roof, I planned to build a two row beam structure to take the load.  The weight of a panel is roughly 10kg, to 40kgs per structure is the setting.  The design shall have a rectangular frame of size 10’x3′ made out of 1.5″ L section of steel.  The rectangular section shall be supported by two 2″x1″ C channel steel of height 1.5′, which I call the legs.  The legs shall rest on a 8″x8″ 6mm plate, which in turn shall be secured to the roof with four 10mm anchor-flush bolts.  I could get raw material and fabrication done in Mannurpet, Ambattur for Rs 8000.  The total weight of steel I had installed is about 50Kg to keep the 70Kg of panel structure load secured.

Solar Power Plant Sizing chart is here.

More to continue..

Solar Panels Orientation for Chennai

December 21st, 2012 No comments
    Chennai’s Lat Lon value is 13° 04′ N 80° 17′ E and Earth’s axis is titled by 23.5°, so for Chennai the maximum Sun’s North-South swing angle is 10°N and 36.5°S.  If you setup the solar panel parallel to the ground, you would see the inclination angle of Sun at 12 noon would be a maximum of 10° to the north during Utthrayanam and a maximum of 36.5° to the south during Dakshinayanam.  So, for stationary solar panel fitments, the panel should be oriented to 13.5° to the south to have an uniform Sun’s inclination angle swing (+23.5° to -23.5°) relative to the solar panel reference line.

Sony UWA-BR100

October 27th, 2012 2 comments
    Today, I purchased the WiFi adapter for Sony 32EX650 LED TV, which is exclusively built for the Sony HD LED TV with USB connectivity.  When I tried plugging that in my Windows 7 x64 PC, the device was not recognized as there was no Windows driver, but the device showed up as CEWL-1.  While discussing about that with my wife, I had to take the brickbats for wasting the money, while we already have wifi access from the available devices.  Now, I had to prove that my investment is worth, but I have no clue how to. 

    Started my search for unofficial drivers for the device in Linux and Windows, following that gracefully landed at, which said that the device is indeed Atheros chipset based and detectable in Linux as ath9k_htc and moreover they had also provided a free download link for getting the all-windows driver.

    Now, I have installed the windows driver and the wifi device works like a breeze.  I have been testing it against B/G wifi network, so the speed I am seeing is 54Mbps.  I will try this again with A/N/B/G to check whether it goes to higher speeds as claimed in the website.  Interestingly, Windows 8 would support these devices out of the box as per this Sony support page.

Update: I have tested the device against a A/N/B/G router in the 5Ghz spectrum and found that the device is connected at 300Mbps speed 🙂  And, indeed it is using the ath9k_htc driver supplied via compat-wireless package.

Understanding a Fan Motor

August 28th, 2012 4 comments
Have you opened up a fan motor before?  It is a simple brush less A/C induction motor, where the armature remains as the stator.  Look at the exploded image of a typical fan motor. The important parts are C: Ball Bearing, D: Stator, E: Armature/Stator, G: Capacitor, H: Connector. 

Also, look at the other image that shows the cross section of a motor.  You would notice that there are 4 wires coming out the motor.  Two pairs of wire, with one pair as the starting coil and the another pair for the running coil.  In general, all single phases induction motors have two coils (starting coil, running coil).  Using a capacitor, an artificial phase difference is created between the fields created by the starting and running coils.  The phase difference triggers movement of the armature.  When the armature reaches a particular speed, using a centrifugal switch, the connection to the starting coil is disconnected and the entire fans runs with just one coil.

Although there are four terminals, you would notice 3 terminals are emitted out, with the starting and running coils connected back-to-back.  Let’s say S1,S2 are the terminals of starting coil and R1,R2 are the terminals of the running coil.  To get 3 terminals out of the fan motor, S2 and R2 are shorted. 

Now, you just see 3 terminals; how do you find which terminal is starting, which one is ending and which one is shorted?  Easy.  Using a simple multimeter, you can find it out.

Let’s say you see terminals A, B, C. Our aim is to find which one of these are S1, R1, S2R2.  Now, let’s measure the resistance between A-B, call it X.  Likewise measure the resistance B-C as Y and A-C as Z.  If you would notice X < Y < Z, you would also notice that Z = Y+X.  Which mean, A-C is action A-B+B-C, that’s why the resistance was additive, also the terminal B is S2R2.  The challenge now is to find what is A and what is C.   As we’d notice A-B=X < B-C=Y, we can confirm that terminal A is starting coil S1 and terminal C is running coil R1.  The reasoning is that; starting coil resistance will be less than running coil resistance.

Hope, this article helped.

Homemade Momos and Kebabs

June 3rd, 2012 2 comments

Calculating Ampere-Hour AH requirement

May 20th, 2012 No comments
We are in a sorry state of erratic and long power cuts, due to shortage of power production by the nation against the increasing load conditions.  To add fuel to this fire, a wholesome of abled people putting their hard earned money on to power backup solutions, where they store the power during power availability and consume the stored power during outage.  On the whole, this looks simple and elegant, but this is not doing any good to the state, which shed’s power at different locations to balance against shortage in power production.  So theoretically, in a place where a family consumed 1kW per hour, would consume 2.5kW per hour during power availability and generate 1kW during power outage.  Yes, you are right. The equation is not balanced, because atleast 30-50% of power is wasted during the backup-retrieve cycle.

Ok, coming to the point.  What is the solution? Go for harvesting solar power, availability in abundance and omni present.  And most interestingly, rationed to perfection based on the amount of un-shadowed free space a family has.  I will just limit this article to calculating the battery provisioning when you go for a solar-inverter solution.  Let’s say I want to have a power backup for 2 hours and my load is 1kW. What would be the ideal inverter solution for this load condition?

Normal Power 1000 Watts
Power Factor 80 %
Inverter Rating 1000W/80% = 1250 VA
Number of Backup Hours 2 Hours
Energy To be Stored 1000×2=2000Wh
Inverter Battery Voltage 24VDC
Battery Amp-Hours 2000/24=83AH
Add @30% AH Margin 83*1.3=108AH~100AH

So, for this configuration you need a 1250VA Inverter with 2x12v 100Ah battery bank.  Let me explain the calculation,

  1. Power Factor: In AC (alternating current), Power = Voltage x Current x Power factor unlike in DC, Wattage = Voltage x Current.  Power factor is measure as the cosine of the phase angle between voltage waveform and current waveform.  For home use, the power factor will be 0>PF<1.  When PF is lower, the efficiency of the system suffers a lot.
  2. Battery Voltage: For 1250VA inverter system, the choice of battery bank is 24V instead of 12V.  The rationale for this choice is to limit the current from the battery to the inverter unit.  If you use a 12V battery bank, at full load there will be a current of 1250/12=104A flowing from the battery to the inverter.  You may have noticed the thickness of the battery wire be very high.  Despite that the power loss on those wires when the current is 100A, would be much higher than it is with 50A on a 24V system.  For a 24V system, the peak current shall be 1250/24=52A.  Also, at 100A, with 1m cable between battery and inverter, the impedance should be 0.00001 ohms.
  3. AH Margin: Although battery AH rating considers absolutely draining of the battery, we will not be able to do that for normal SMF battery.  Meaning, we should not discharge below 10V and likewise should not charge beyond 13.6V per 12V battery.  In order for the AH rating to work, we have to apply atleast 20-30% margin.

Fixing a Hand Remote Control that doesn’t work!

December 4th, 2011 No comments
    It is hard to imagine a television or a multimedia system without remote control now a days. Broken remote control units is an eternal problem. Thanks to China for dumping remote control units, which makes the cost of them affordable between 60-75Rs for television units. But, finding a replacement for multimedia systems is still a problem as no vendor is holding such stocks for its lower sales.
     I have been hit for the same problem when my Altec Lansing 5.1 multimedia system’s remote control broke. In the sense, the remote was functional intermittently. And some time, the key pad mapping got goofed up with + working as – and so on. When I visited my local electronics stores guy, he said the general problem for intermittent remote operation is a conked up crystal that is found inside the remote control unit. 

    Remote control units work with Infrared light communication between the hand-unit and the multimedia system’s base unit.  Commands from the keypad are converted to IR signals, which are received and decoded by the base unit to perform appropriate function.  Since IR light is not visible to human eye, one should use a Camera eye to see the IR light.  The easiest way is to observe the LED mounted in the front of the hand unit through a mobile camera or any camera that’s in working condition.  The cameras bandwidth covers IR and UV apart from the visible spectrum.  You will find that the IR led blinks (carrier frequency is 22khz), when you press any button on the remote control unit.  If you observe that for some keys the IR led is not flashing or intermittently flashing, you may associate the problem to a faulty crystal in the remote control PCB.

    When the remote is opened, you will see a PCB like the one in the picture.  The PCB could be plucked out from the casing by hand.  You will also see a rubber like buttons which are the actual buttons that you press.  The rubber button is placed on the PCB, where the button presses are converted to switching action.  Remember, the buttons will have a conducting coating under it, which indeed closes the circuit when the button touches the PCB. 

    The crystal that comes as a part of the circuitry is shown in the picture.  It is otherwise called a ceramic resonator, which is the crucial component of an oscillator circuitry.  Crystals are typically used against LC, RC tank circuits for its very high stability feature against temperature and humidity. My remote uses a 455Khz crystal named CRB455E ( The cost of this crystal as on today is Rs 2 in Chennai/India.  After replacing the crystal, my remote is working perfectly so far.