Monday, February 4, 2013

Installing OpenCV on Ubuntu

To find out what version of ubuntu you have, type this at the command prompt
> lsb_release -a

For me, the answer is Ubuntu 12.04.1. Here are the sequence of steps that led to a successful OpenCV install (using terminal )

1. Download OpenCV 2.4.3 from here http://opencv.org/downloads.html
2. Unpack tar file and create a directory called release
~/OpenCV-2.4.3/release
3. Make sure packages are installed using the command
> sudo apt-get install [package-name]

where packages I installed were (these may not be required but I installed them anyways)
build-essential cmake pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev
zlib1g-dbg zlib1g zlib1g-dev
libjasper-dev libjasper-runtime libjasper1
pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools
libjpeg8 libjpeg8-dev libjpeg8-dev libjpeg8-dbg libjpeg-progs libjpeg-dev
ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev
libgstreamer0.10-dev libgstreamer0.10-0 libgstreamer0.10-0-dbg
libv4l-dev
yasm
libtbb-dev libqt4-dev libtbb2

You may need some other things like numpy, python etc. which I already had.

4. Run cmake command with following flags
> cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_EXAMPLES=ON -D BUILD_DOCS=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_TBB=ON -D WITH_CUDA=OFF -D WITH_QT=ON ..

5. 'make' and then 'sudo make install'

Oh one thing I forgot to mention which may or may not make a difference, is that I installed ffmpeg from source by downloading from ffmpeg.org. The configure script had a few flags that were enabled... again not sure if this makes a big difference to the success of the build/install of opencv.

How to get apt-get to work behind a proxy in Ubuntu

Add the following line (you need to modify to your situation)
Acquire::http::proxy "http://[username]:[password]@[www.proxy.net]:[port_number]/";
to this file /etc/apt/apt.conf

Thursday, June 9, 2011

(How not to) Install IT++ and USRP

Let us start with a rhetorical question: Why is installing anything from source code so complicated?

With that in mind, this post goes about documenting my experience of trying to install the C++ communication library IT++ found here. Why am I installing it? Just to see what it can do and to see if it is easy to use. I am exploring the possibility of a IT++ plus UHD USRP software radio. Why am I taking this approach over GNU Radio? Go and try sending a short packet at a particular moment in time using GNU Radio, and then tell me how you did it and then and only then I'll tell you why :).

After downloading and unpacking the archive into a local directory, one has to first install prerequisites. The prerequisites are blas, lapack, fftw3, gfortran-4.4 and perhaps some others. Those can be installed using an "sudo aptget install " command. Now come the tricky parts. 


xyz@ubuntu-laptop:~/work/itpp-4.2$ ./configure --with-blas=atlas --with-lapack=atlas --with-fft=fftw3
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU Fortran 77 compiler... yes
checking whether /usr/bin/gfortran-4.4 accepts -g... yes
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking dependency style of g++... (cached) gcc3
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU Fortran 77 compiler... (cached) yes
checking whether /usr/bin/gfortran-4.4 accepts -g... (cached) yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for ld used by g++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for /usr/bin/gfortran-4.4 option to produce PIC... -fPIC
checking if /usr/bin/gfortran-4.4 PIC flag -fPIC works... yes
checking if /usr/bin/gfortran-4.4 static flag -static works... yes
checking if /usr/bin/gfortran-4.4 supports -c -o file.o... yes
checking if /usr/bin/gfortran-4.4 supports -c -o file.o... (cached) yes
checking whether the /usr/bin/gfortran-4.4 linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether ln -s works... yes
checking for a sed that does not truncate output... (cached) /bin/sed
checking whether to use explicit library dependencies... no
checking for doxygen... yes
checking for latex... yes
checking for dvips... yes
checking for gs... yes
checking for perl... /usr/bin/perl
checking for gdiff... no
checking for gnudiff... no
checking for diff... /usr/bin/diff
checking whether time.h and sys/time.h may both be included... yes
checking cmath usability... yes
checking cmath presence... yes
checking for cmath... yes
checking complex usability... yes
checking complex presence... yes
checking for complex... yes
checking ieeefp.h usability... no
checking ieeefp.h presence... no
checking for ieeefp.h... no
checking whether signgam is declared... yes
checking whether isfinite is declared... no
checking whether isinf is declared... yes
checking whether isnan is declared... yes
checking for std::isfinite... yes
checking for std::isinf... yes
checking for std::isnan... yes
checking for asinh... yes
checking for acosh... yes
checking for atanh... yes
checking for cbrt... yes
checking for erf... yes
checking for erfc... yes
checking for expm1... yes
checking for finite... yes
checking for fpclass... no
checking for isfinite... no
checking for isinf... yes
checking for isnan... yes
checking for lgamma... yes
checking for log1p... yes
checking for log2... yes
checking for rint... yes
checking for tgamma... yes
checking how to get verbose linking output from /usr/bin/gfortran-4.4... -v
checking for Fortran 77 libraries of /usr/bin/gfortran-4.4...  -L/usr/lib/sse -L/usr/lib/gcc/i486-linux-gnu/4.4.3 -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../.. -L/usr/lib/i486-linux-gnu -lgfortranbegin -lgfortran -lm
checking for dummy main to link with Fortran 77 libraries... none
checking for Fortran 77 name-mangling scheme... lower case, underscore, no extra underscore
checking for sgemm_ in -latlas... no
checking for sgemm_ in -latlas -lgfortranbegin -lgfortran -lm... no
checking for sgemm_ in -lmkl_core... no
checking for dgemm_ in -lmkl_core... no
checking for sgemm_ in -lacml... no
checking for sgemm_ in -lacml_mp... no
checking for dgemm_ in -lacml... no
checking for dgemm_ in -lacml_mp... no
checking for ATL_xerbla in -latlas... yes
checking for sgemm_ in -lf77blas... yes
checking for cblas_dgemm in -lcblas... yes
checking for cheev_ in -latlas... no
checking for cheev_... no
checking for cheev_ in -lmkl_lapack32... no
checking for cheev_ in -lmkl_lapack... no
checking for cheev_ in -llapack... yes
checking for DftiComputeForward in -lfftw3... no
checking for zfft1dx in -lfftw3... no
checking for fftw_plan_dft_1d in -lfftw3... yes
checking fftw3.h usability... yes
checking fftw3.h presence... yes
checking for fftw3.h... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating itpp/Makefile
config.status: creating itpp/base/Makefile
config.status: creating itpp/base/algebra/Makefile
config.status: creating itpp/base/bessel/Makefile
config.status: creating itpp/base/math/Makefile
config.status: creating itpp/comm/Makefile
config.status: creating itpp/fixed/Makefile
config.status: creating itpp/optim/Makefile
config.status: creating itpp/protocol/Makefile
config.status: creating itpp/signal/Makefile
config.status: creating itpp/srccode/Makefile
config.status: creating itpp/stat/Makefile
config.status: creating doc/Makefile
config.status: creating doc/images/Makefile
config.status: creating doc/tutorial/Makefile
config.status: creating doc/tutorial/src/Makefile
config.status: creating doc/local/Makefile
config.status: creating doc/local/index.doc
config.status: creating doc/doxygen_html.cfg
config.status: creating extras/Makefile
config.status: creating tests/Makefile
config.status: creating win32/Makefile
config.status: creating win32/itpp_acml_tests/Makefile
config.status: creating win32/itpp_mkl_tests/Makefile
config.status: creating itpp.pc
config.status: creating itpp_debug.pc
config.status: creating itpp-config
config.status: creating itpp/config.h
config.status: executing depfiles commands
config.status: executing libtool commands
configure: displaying configuration summary

------------------------------------------------------------------------------
itpp-4.2 library configuration:
------------------------------------------------------------------------------

Directories:
  - prefix ......... : /usr/local
  - exec_prefix .... : ${prefix}
  - includedir ..... : ${prefix}/include
  - libdir ......... : ${exec_prefix}/lib
  - datarootdir .... : ${prefix}/share
  - docdir ......... : ${datarootdir}/doc/${PACKAGE_TARNAME}

Switches:
  - debug .......... : no
  - exceptions ..... : no
  - html-doc ....... : yes
  - shared ......... : yes
  - static ......... : no
  - explicit deps .. : no

Documentation tools:
  - doxygen ........ : yes
  - latex .......... : yes
  - dvips .......... : yes
  - ghostscript .... : yes

Testing tools:
  - diff ........... : yes

Optional modules:
  - comm ........... : yes
  - fixed .......... : yes
  - optim .......... : yes
  - protocol ....... : yes
  - signal ......... : yes
  - srccode ........ : yes

External libs:
  - BLAS ........... : yes
    * MKL .......... : no
    * ACML ......... : no
    * ATLAS ........ : yes
  - LAPACK ......... : yes
  - FFT ............ : yes
    * MKL .......... : no
    * ACML ......... : no
    * FFTW ......... : yes

Compiler/linker flags/libs/defs:
  - CXX ............ : g++
  - F77 ............ : /usr/bin/gfortran-4.4
  - CXXFLAGS ....... : -DNDEBUG -O3 -pipe
  - CXXFLAGS_DEBUG . : -Wall -ggdb -pipe
  - CPPFLAGS ....... :
  - LDFLAGS ........ : -L/usr/lib/sse
  - LIBS ........... : -lfftw3 -llapack -lcblas -lf77blas -latlas -lgfortranbegin -lgfortran -lm

------------------------------------------------------------------------------
Now type 'make && make install' to build and install itpp-4.2 library
------------------------------------------------------------------------------

These steps worked but make check failed 12 out of 50-odd tests. Most of the tests seemed to have to do with linear algebra stuff like svd, and so forth. I gave up after trying many different things.

Since I only wanted to evaluate IT++, I did that by installing the binaries available on Synaptic. Suffice to say I was able to create a simple BPSK transmitter, connect to USRP and see the waveform on the scope. It was easy to put together since the commands are very MATLAB like.


However, since that time I have played around with "sample tagging" in GNU Radio and have decided to invest my time towards a GNU Radio route.

Thursday, May 26, 2011

O2 sensor Honda Civic LX

This is a post related to car troubles I recently had.

I turn on my car at 7p leaving work for home -- the check engine turns on. I was a bit concerned since I have not been to the service center in a while. This light has turned on in the past before where I had to replace an O2 sensor -- I don't remember but I think I have replaced it twice in this car's 11 year history. I don't know what to make of it yet.

In order to read the failure code one needs to get a OPDII (I probably got it wrong) reader. First I went to an EZ Lube in Redondo Beach -- their reader did not work . So then I went to a nearby pepboys where the service advisor was sort of a diva and he said it would take an hour to get a tech to read. ok, I decide I will travel to a honda dealership... where the service advisor says it'll cost 105$ just to read it (which will be used towards fixing the problem). Notice that it was not important for them to find out whether there is or isn't a problem. So I ditch these guys too -- and then go to an quick-lube place where there was one person who just went and got a computer to read the problem right away-- yes, it was an O2 sensor failure. It was reset to see if it would trigger again -- it did not so far. For their help, I rewarded them with a oil service 31$... which I needed anyway.

I got a few estimates while waiting for my car -- one honda dealer asked 537$ which I haggled down to 437$. I asked another dealer for an estimate and got 337$.

I looked online and I think the sensor costs around 50-60$ and 1 hr labor is 70$ which brings the true cost to around 130$.

Summary: the check engine light is not on, the sensor has not triggered it yet. I have only spent 31$ on the car and it runs great. However, they did recommend that my battery be replaced.


Friday, April 1, 2011

Loading firmware on the USRP N210

It seems like whenever I need to update a driver or find firmware files from the Ettus site seems like I have to find it through some really subtle ways. This post simply documents my experiences from start to finish to get a USRP N210 up and running. I am using Ubuntu v10.10 on a laptop that will run the SDR and interface with the USRP.

I received a brand-spanking-new N210 in the mail yesterday, I tried connecting it to the Simulink FM demod demo as a first step -- did not find the device. After some time with Google I found that N210 is a UHD interface device and that the Simulink driver (which worked seamlessly with the USRP2 btw) is not compatible. So this means N210 => linux only!!.

That is not a major issue since I am planning to use Linux anyway -- first thing I did was to download the latest gnuradio (version 3.3.0 I believe), which of course does not have UHD. For this you need to download from the trunk or something like that. I was able to find a .gz file with the UHD source
https://download.github.com/EttusResearch-UHD-Mirror-95b966a.tar.gz


The steps are as follows (make sure you install cmake using Synaptic or apt-get)

cd host
mkdir build 

cd build 
cmake ../ 
make 
make test 
sudo make install 
sudo ldconfig



After all that I see some files /usr/local/share/uhd ... so I guess it worked!?

So then I plugged in the N210 (via ethernet, my host was 192.168.10.10 and I think the USRP N210 is set to 192.168.10.2)  and then ran a command called uhd_find_devices to which it responded
Warning:
Ignoring discovered device
RuntimeError: Expected protocol compatibility number 9, but got 7: The firware build is not compatible with the host code build. 
No UHD Devices Found

So I figured this meant that the firmware on the newly ordered N210 is stale. Hmm.. I guess I should learn how to do this anyway so why not now. There is no Flash card reader on the N210, so this means the firmware will be downloaded by the ethernet port. After doing a Google search, there appears to be a utility called usrp_n2xx_net_burner.py which I downloaded to my Windows XP machine (since I dont have internet access on the Linux box). I also managed to download what I think is the latest firmware (pls. be number 9, pls.) from here
http://www.ettus.com/downloads/uhd_images/UHD-images-most-recent/

I open up a command prompt on my Windows machine which is now connected to the N210 via ethernet and do the following:

C:\ettus_rsch\UHD>usrp_n2xx_net_burner.py --ip 192.168.10.2 --fw usrp_n2xx_fw.bin
Flash size: 4194304
Sector size: 65536




Begin firmware write: this should take about 1 second...
Erasing 31744 bytes at 3145728
Writing image
Verifying data
Read back 16383 bytes
Success.
Time elapsed: 0.890000 seconds

followed by
C:\ettus_rsch\UHD>usrp_n2xx_net_burner.py --ip
 192.168.10.2 --fpga usrp_n210_fpga.bin
Flash size: 4194304
Sector size: 65536


Begin FPGA write: this should take about 1 minute...
Erasing 1572864 bytes at 1572864
Writing image
Verifying data
Read back 1268576 bytes
Success.
Time elapsed: 30.219000 seconds



 Then I try the uhd_find_devices command on the linux box to see if can find the N210 and voila, it is found.   It says UHD Device 0, type usrp2 and the ip 192.168.10.2. I also ran uhd_usrp_probe and noticed that the daughterboard was found and everything seems in order. I also ran some examples from the uhd directory which were all indicative of an operational state. Now need to figure out some way to use it with the current version of gnuradio. On the following page there are some hints:
http://code.ettus.com/redmine/ettus/projects/uhd/wiki

It says: The gr-uhd component of Gnuradio comes with a set of source and sink blocks for UHD as well as block wrappers for the Gnuradio-Companion. On my windows machine I have installed Cygwin which fortunately has git. I download the master branch by issuing the following command
git clone http://gnuradio.org/git/gnuradio.git

This magically creates a gnuradio tree in the current folder. I proceed to follow the build instructions shown below (may have to issue a 'chmod +x bootstrap')


$ ./bootstrap         # Do NOT perform this step if you are building from a tarball.
$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig 




After this I typed 'sudo gnuradio-companion' at the terminal to bring up GRC which tells me things are working. I would strongly recommend installing gnuradio on a fresh install. When I had some old gnuradio installations lying around I had a lot of trouble.. like messages saying PYTHONPATH was not configured, etc.

Monday, March 7, 2011

Useful MATLAB tips

This is a working post of MATLAB tips
1. Access fields of a structure using a string variable
>> struct_x.(genvarname('R_cdf'))
is equivalent to
>> struct_x.R_cdf

Tennis affirmations

Breathing
1. Stay calm: Try to listen to your breathing rhythm and keep heart rate low at all times
2. Exhale while hitting a shot

Movement
1. Try to get to center of the court as much as possible using economical side steps. Stay relatively still and watch the opponent and try to predict where the shot is going. Start moving in the when you have a good idea.
2. To hit your shot make a lot of little footwork adjustments (may make some squeeky sounds) to get to the optimum hitting distance to the ball. Make sure the ball is at a position where you can get a full-bodied swing -- if you are too close you may jam/constrict your swing.
3. Step in to hit the ball.. identify short balls early and anticipate drop short all the time and get ready to sprint on a dime
4. Maintain court position close to the baseline if the court is fast and low

Groundstrokes
1. Always try to hit low to high with high rackethead speed, this helps get a lot of topspin. Racket preparation should begin as soon as you are moving to hit the shot. A powerful shot results if your take back, swing and follow through are complete, smooth and fast. 
2. When there is time to hit but ball is not short go for the heavy topspin, high margin, depth shot
3. Hit slightly in front of the body, especially the backhand