Saved by my past self

Wiped Arch, put on Ubuntu 14.04 on laptop. Everything works fine, except for the speaker makes nonstop whine/beeping sound after unplugging power cord. Went through a bunch of results that didn’t help.

The one that did was this one, and the solution was posted by yours truly. Turns out I had this same problem with Arch before.

Posted in Uncategorized | Leave a comment

Compiling against manually installed packages

I’m trying to compile the openEphys GUI on Ubuntu 14.04. The program requires libhdf5 of version greater than 1.8.12.

Unfortunately Ubuntu 14.04 only has libhdf5-1.8.11 in the repository. The openEphys wiki suggest compiling from source, but I’m afraid doing that might break gtkclient, my wireless neural recording PC client.

Steps I took:

1. sudo apt-get remove libhdf5-dev
This removed “libhdf5-dev”, “libmatio-dev”, “hdf5-helpers”, “libhdf5-serial-dev”, and “hdf5-tools”

2. Next I searched for libhdf5-dev on Ubuntu package directory, and downloaded it and all its dependencies.

I choose the version 1.8.13 whenever possible. These packages include “hdf5-helpers”, “libhdf5-8”, “libhdf5-cpp-8”, “libhdf5-dev”, “libmatio-dev”, “libhdf5-serial-dev”, and “hdf5-tools”. Then install all these packages with

sudo dpkg -i packageName.deb

3. We can check that they are indeed installed via
dpkg -l "*hdf5*".

4. These steps are already enough to compile openEphys GUI. However, it indeed breaks my gtkclient build, with the linker unable to find “-lhdf5”. This is most likely because proper environment variable settings aren’t set, so the linker can’t find the “libhdf5.a” file. Setting “LD_LIBRARY_PATH”  by creating and editing a ld_config file in this way did not work.

5. Instead, I edited my gtkclient Makefile flags to include:

HDF5INCLUDE := -I/usr/include/hdf5/serial

in the CPPFLAGS, and
HDF5LD := -L/usr/lib/x86_64-linux-gnu/hdf5/serial -lhdf5 -lhdf5_cpp

in the linker flags.The first directory name is because all the hdf5 header files are included there. The second directory name is there because the .a and .so library files are in there.

This information is found by executing dpkg -L "libhdf5-dev"

Now everything compiles successfully!

Posted in Uncategorized | Leave a comment

Adding Matlab to launcher in Ubuntu

I screwed up my Matlab2013b installation on Ubuntu 14.04, so decided to re-install. Upgraded to Matlab2014b in the process.

Installation was straight forward – download linux 64-bit from Mathworks site, install to /usr/local/MATLAB and have the installer make the symbolic links to the executable binaries for me. Matlab has really polished that process.

2014b no longer gives me problems with tab-complete menus.

One little thing – while searching for Matlab in the Unity menu (invoked by pressing the Meta or Windows key), the Matlab icon comes up. Dragging it to the launcher menu also works, but instead of getting the same icon, it’s simply a picture of a question mark. Cosmetically very unpleasing and confusing.

The fix:

The launcher icon is specified in

#!/usr/bin/env xdg-open
[Desktop Entry]
Comment=Start MATLAB - The Language of Technical Computing
#Uncomment the following line and comment the line after to
#force matlab to use the 32 bits architecture
#Exec=matlab -arch=glnx86 -desktop
Exec=matlab -desktop
#Uncomment the following line if you've got several matlab icons in the launcher

The value of the Icon field specifies what image to use as launcher icon. It seems the default path is not valid.

The Matlab icon in the Unity search menu is configured by (I think..):

[Desktop Entry]

Exec=matlab -desktop
Comment=Scientific computing environment


The value for the Icon field actually refers to
/usr/share/app-install/icons/_usr_share_icons_hicolor_48x48_apps_matlab.png. It’s good to change field value to that to better reflect this.

So, we can either take
/usr/share/app-install/icons/_usr_share_icons_hicolor_48x48_apps_matlab.png and give it to the Icon field in the first config file, or copy that image to the location specified by the default path in the first config file.

After this, Matlab has a nice icon in the launcher menu.

Posted in Uncategorized | Leave a comment

Ubuntu 14.04: Auto-mounting internal HDDs to named folders

I dual-boot Ubuntu 14.04 and Windows 7, though I’ve only used Windows once. Both ‘/’ and windows are installed on my SSD.

For data, I have two 2TB internal HDDs. The file-system is NTFS. By default, to access the data within these HDDs, one have to mount them first, either via `mount` or through the file-manager (“Files” in the case of Unity).

Through file-manager the HDDs are then mounted in ‘/media/username/UUID’, where UUID denotes that of the HDD.

To auto-mount these HDDs every time on boot, to named folders (e.g /media/data_drive1) I did the following:

1. Mount the HDD through the file-manager. Then you would know which HDD contains which files, in terms of their UUID. This is useful because say you switched the SATA cables to the HDD, their device name (e.g. /dev/sdb1, /dev/sdc1) would change, but UUID won’t.

2. Edit `/etc/fstab` and add a line such as:

`UUID=0883111D0548716A /media/data_drive1 ntfs defaults 0 1`
where the 1st field is UUID of the device,
2nd field is the named folder you’re mounting it to,
3rd field is the file-system (you can find out via gparted, for example),
4th field is mounting options

For more see Ubuntu fstab

3. Reboot

Posted in Uncategorized | Leave a comment

Handy bash code

Rather than thinking about it every time, I’m collecting all my handy bash things.

for file in $(ls|grep mp3)
ffmpeg -i $file ${file/mp3/wav};

Takes all the foo.mp3 files, use ffmpeg to convert and output foo.wav

for file in *.png
mv "$file" "${file/_h.png/_half.png}"

Regular expression on file names. Change something_h.png to something_half.png

Command to put memory contents in excel spreadsheet (so I can copy paste lol):

Memory content in the form of:


Want to output them out in the form of:

0x31 0x30 0x35 0x34
0x31 0x33 0x2f 0x32
0x31 0x30 0x2f 0x2e

Use the following:

head -256 copyenc | tac | awk '{if (NR%4) {ORS="\t";print " "$0} else {ORS="\n";print " "$0}}' > enc_lut_txt

Posted in Uncategorized | Tagged | Leave a comment

R – Plotting boxplots, with multiple per point

Plotting this took me a while to figure out, after going through a bunch of posts. In my data, I have a control and an experimental group. Multiple measurements are taken for these groups at different time points. I want to boxplot the control and experimental groups at these different points on the same figure, side by side, without extra x-axis labels.

My data looks something like the following:

PN1.Rx age synthesis heart.incorp.uptake ....
1 control PN3 DNA 0.26
2 control PN11 protein ...
3 6OHDA PN3 DNA ...
4 6OHDA PN11 protein ...

I first need to re-order the age-factors so when I plot them according to age, PN11 doesn’t come before PN3:

set1$age = factor(set1$age, levels=c("PN3", "PN5", "PN8", "PN11", "PN15", "PN19"), ordered=TRUE)


c.a = subset(set1, cohort=='a' & synthesis=='dna')
boxplot(heart.incorp.uptake ~ age, data = subset(c.a, PN1.Rx=="control"), xlab="Age",
ylab="Heart Uptake", xaxt='n', style="quantile", ylim=c(0,max(c.a$heart.incorp.uptake)),
col="blue", boxwex=0.3, at=1:6-0.2)
boxplot(heart.incorp.uptake ~ age, data = subset(c.a, PN1.Rx=="6OHDA"), xlab="Age",
ylab="Heart Uptake", xaxt='n', style="quantile", col="red", add=TRUE,
boxwex=0.3, at=1:6+0.2)

The first boxplot makes the boxes for the control groups, the second for experimental groups. I’m plotting heart.incorp.uptake as a function of age (hence the level re-ordering).

The xaxt=’n’ makes the axis label disappear.

The key options are boxwex, which gives the width of the boxplot (I think the default is 1). The “at” option shifts the center of each box with respect to the default one. I have 6 time points, with 2 boxes per time point. Thus the “1:6+/-0.2” shift.

axis(1, at=1:6, labels=levels(set1$age), tick=TRUE)
title("Cohort a: Heart Uptake and DNA Synthesis")
legend("topright", c("Control", "6OHDA"), fill=c("blue","red"))

Finally, I set the axis tickmarks to between the two boxes. The end result is below:


Posted in Uncategorized | Tagged | Leave a comment

New Project: nRF24LE1

Nordic semiconductor makes probably the best commercial ultra-low power, high bandwidth radio transceivers. We have used the nRF24L01 2.4GHz chips in wireless headstages previously.

I’m working on a new project that uses these transceivers. But since I’m too lazy to select a microcontroller, design some kind of communication protocols between the two, and a PCB for it, I decided to use Nordic’s nRF24LE1, which includes the transceiver and a 8051-style microcontroller all on one chip. Pretty sweet!

Further, Brennen Ball from makes a nice breakout board for it, as well as bootloader and a SDK based on SDCC. All very convenient – this way I don’t have to go through Nordic’s own Windows-based toolkit using the Keil compiler, making the cost lower.

First step is to figure out how to use Brennen’s tools. He wrote the PC bootloader in C#, and claims that it works natively in Linux through Mono. For me, however, I keep getting the errors:

Missing method EnableVisualStyles in assembly /home/allenyin/Projects/rat_wireless/nrf24lx1_bootloader_pc/nrf24lx1_programmer/bin/Debug/nrf24lx1_programmer.exe, type System.Windows.Forms.Application
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
File name: 'System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies.
File name: 'System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Solved this by installing Mono libraries: 1) libmono-system-windows4.0-cil; 2) libmono-winforms2.0-cil


Posted in Uncategorized | Leave a comment