Blog


Comments Off

Emacs orgtbl-mode export to LaTeX matrix

11.02.11 Posted in Emacs by

Here’s one thing I know: I love Emacs, LaTeX, and matrices.

I often find myself typesetting matrices, and it’s a huge pain. I’m just not good at hitting the ‘&’ character.

To mitigate my suffering (#firstworldproblems), I wrote a few lines of Lisp that will allow me to use orgtbl-mode to typeset matrices. If you’re not familiar with orgtbl-mode and how it can improve your life, check this out for a simple LaTeX table example.

With the below code somewhere in your Emacs init file, you can use the much simpler org-mode table shortcuts to create a table, and then have that immediately exported to a LaTeX bmatrix environment.

Check out the cool behavior with matrices pasted from MATLAB. You’ll definitely want to bump this up to 720p.

To typeset a matrix from MATLAB copy it to your clipboard and do the following:

M-x orgtbl-mode (if you don’t have orgtbl-mode in your LaTeX mode hook)
M-x orgtbl-insert-matrix
Paste your matrix
C-x C-x  (which exchages point and mark to easily select pasted text)
C-c | (orgtbl-create-or-convert-from-region)
C-c C-c (to perform the export)

That’s it!

Here’s the code.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(defun orgtbl-to-latex-matrix (table params)
  "Convert the Orgtbl mode TABLE to a LaTeX Matrix."
  (interactive)
  (let* ((params2
          (list
           :tstart (concat "\\[\n\\begin{bmatrix}")
           :tend "\\end{bmatrix}\n\\]"
           :lstart "" :lend " \\\\" :sep " & "
           :efmt "%s\\,(%s)" :hline "\\hline")))
    (orgtbl-to-generic table (org-combine-plists params2 params))))


(defun orgtbl-insert-matrix ()
  "Insert a radio table template appropriate for this major mode."
  (interactive)
  (let* ((txt orgtbl-latex-matrix-string)
         name pos)
    (setq name (read-string "Table name: "))
    (while (string-match "%n" txt)
      (setq txt (replace-match name t t txt)))
    (or (bolp) (insert "\n"))
    (setq pos (point))
    (insert txt)
    (previous-line)
    (previous-line)))

(defcustom orgtbl-latex-matrix-string  "% BEGIN RECEIVE ORGTBL %n
% END RECEIVE ORGTBL %n
\\begin{comment}
#+ORGTBL: SEND %n orgtbl-to-latex-matrix :splice nil :skip 0

\\end{comment}\n"

  "Template for the latex matrix orgtbl translator
All occurrences of %n in a template will be replaced with the name of the
table, obtained by prompting the user."

  :type 'string
  :group 'org-table)

Comments Off

iOS CoreMotion Data Logger

10.28.11 Posted in iOS by

I just released a project that is an iOS utility to log sensor data so it can be processed offline. I wanted to prototype my algorithms in Python with a consistent dataset. This is the solution to that!

It currently logs all the different types of data that are available in the CoreMotion framework. I’ve included an example Python script that shows how to parse and plot the data that results from using the app. Here’s a figure that results from the script:

***** Check out the project on GitHub here.


Comments Off

Converting from cv::Mat to UIImage

07.25.11 Posted in iOS, Mac OS X by

I’ve been working with OpenCV and iOS development quite a bit recently and this is a handy function for getting an Apple-friendly UIImage from the C++ OpenCV class cv::Mat. Here you go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
- (UIImage *)UIImageFromMat:(cv::Mat)image {

    NSData *data = [NSData dataWithBytes:image.data length:image.elemSize()*image.total()];

    CGColorSpaceRef colorSpace;
   
    if (image.elemSize() == 1) {
        colorSpace = CGColorSpaceCreateDeviceGray();
    } else {
        colorSpace = CGColorSpaceCreateDeviceRGB();
    }

    CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);
   
    // Creating CGImage from cv::Mat
    CGImageRef imageRef = CGImageCreate(image.cols,                                 //width
                                        image.rows,                                 //height
                                        8,                                          //bits per component
                                        8 * image.elemSize(),                       //bits per pixel
                                        image.step.p[0],                            //bytesPerRow
                                        colorSpace,                                 //colorspace
                                        kCGImageAlphaNone|kCGBitmapByteOrderDefault,// bitmap info
                                        provider,                                   //CGDataProviderRef
                                        NULL,                                       //decode
                                        false,                                      //should interpolate
                                        kCGRenderingIntentDefault                   //intent
                                        );
   

    // Getting UIImage from CGImage
    UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpace);
   
    return finalImage;
   
}

Comments Off

Share Build Settings between Projects in Xcode 4

06.30.11 Posted in Mac OS X by

I often find myself editing the build settings of my Xcode projects because of external libraries or weird compiler flags for Objective-C++. It’s always frustrating when starting a new project to hunt down and reapply these settings. Even though the build settings interface improved in Xcode 4 (my opinion), it’s still not fun to use – especially when you just need to edit a few fields.

Thankfully, the solution to this problem is the often overlooked configuration settings file. You can create multiple configuration files for different targets or build settings and then use them to quickly apply build settings to new projects. I’ll show you how to do this:

In an Xcode project where you already have custom build settings, create a new Configuration Settings File which is found in the Other category. Give it a descriptive name and save it anywhere in your project.

Create a new configuration settings file

Now, navigate to your build settings and select all of the relevant/changed fields (by holding command) and copy them. I forget where I learned to do this. It’s almost as hidden as clicking the serial number of a device in iTunes to retrieve the UDID.

Copy the relevant build settings

Paste these lines into your newly created configuration file.

Example main configuration fileFor some projects, you’ll need different build settings for the different configurations/schemes such as Debug and Release. For this particular example, I need to do this for the setting Library Search Paths. Note that I didn’t copy that field earlier. If you also want to make specialized files, create a new configuration settings file for a particular configuration (I show my Debug version below). Paste in the fields that are specific to this configuration settings file. PRO TIP: include the original configuration settings file in this specific one so that the common settings can be changed in only one file!

Example debug configuration file Create any additional files for your different configurations.

The final step is to tell Xcode to use these files. Go to the Info tab in the main project settings area and apply your new files to the Configurations section. See below, because I know that sounds confusing.

Apply the Configuration Settings FilesThat’s it!

There is one thing that might trip you up here. It’s important to realize that if you change build settings in the “traditional” way, they will supersede the same fields in your configuration files. If you go and clear the fields manually in build settings that you just pasted into an .xcconfig file, you will get errors. Why? Because clearing those fields overrides your configuration settings files! If you are having trouble with that, feel free to select the fields as before an then delete them. This shouldn’t be a problem in new projects. Moreover, Target settings have priority over Project settings. In the picture above, I applied the files to the project counterpart of the Debug/Release configurations. I think that’s good practice in case you end up creating other targets with different settings in the future.

Hopefully this will save you as much frustration and time that it has saved me!


Comments Off

40 Mile Range XTend 900 MHz RPSMA Configuration

02.09.10 Posted in Uncategorized by

Our research group just bought a couple of these 40 mile range RF transmitters for our Everglades project. Doug Mann and I were tasked with getting them to talk to each other, and to our dismay, no tutorials existed on the interwebs. The documentation was little help because it kept on referring to the development board. Unfortunately, the dev board can’t be purchased separately, and we had already acquired two of these modules.

We tried a bunch of different ways to get them to talk serially to a computer, but let me just tell you what ended up working. After hours of frustration, I remembered something I read in the book Making Things Talk (great book, highly recommend) that explained a certain way to configure an XBee radio. This involved removing the ATMega chip from an Arduino Microcontroller which just turned it into a slightly more expensive – but easier to interface with – FTDI chip. An FTDI chip is used to interface with “old” communications protocols over USB. This chip is a part of every Arduino board, but can also be bought separately for a slightly more dedicated solution. I think this solution is pretty clever because Arduinos are ubiquitous these days.

Anyways, check out the final setup below. We have a breakout board for the transmitter, but we just wire wrapped it now for prototyping purposes. Aside – wire wrapping will change your life. You can see that the ATMega has been removed from the Arduino, and there are only 5 pins connected to 4 ports on the Arduino.

Check the data sheet because the pin numbering is a little weird, but we only connected the following:

Pin 1 – Ground
Pin 2 – 5 Volts
Pin 5 – Rx
Pin 6 – Tx
Pin 7 – 5 Volts

After doing this and plugging in the Arduino, we could send AT commands via any serial monitoring tool. Since you’re already using an Arduino, you can just use the serial monitor in the Arduino IDE, or use the “screen” command in Terminal for Mac OS X computers. Regardless, the X-CTU software is fantastic (albeit Windows only). I recommend finding a Windows machine to install X-CTU because it makes the process graphical and takes a lot of the guesswork out of it.

After configuring just two settings on the radios, we were sending data across the lake on campus at 115kbps! We’re going to do a longer range test soon.

This was a crucial step for us as far as the Everglades project is concerned. Check out our new $200 solar panel setup powering a Fit-PC:



Comments Off

Compiling HTK for Mac OS X Snow Leopard

01.22.10 Posted in Mac OS X by

The Hidden Markov Model Toolkit (HTK) is widely used in speech recognition research. Since I’ll be doing some multimodal speech recognition soon, I downloaded the HTK and tried to compile it for Snow Leopard. This didn’t work right away, and after scraping the bowels of the internet for help, I’ve finally managed to get it working.

Use the following option to configure the Makefile:

 

./configure – -build=i686-apple-macos

No space between the dashes in case you are copying and pasting this. And for one of my machines I had to add an option to the CFLAGS in the Makefile. Open the makefile with your favorite text editor and add the following to CFLAGS:

-I/usr/include/malloc

Also, don’t follow the instructions in the README for testing the installation. Instead, perform the following commands as found on the official HTK site for testing a Mac OS/Linux install.

cd HTKDemo
mkdir -p hmms/{tmp,hmm.{0,1,2,3}} proto acc test
perl runDemo configs/monPlainM1S1.dcf



Comments Off

HAID ’09

09.12.09 Posted in Uncategorized by

You can buy a bratwurst and a 0,5 liter beer for just 4,50 euros!

You can buy a bratwurst and a 0,5 liter beer for just 4,50 euros!

Guten Tag!

I’m posting this from my hotel in Germany. It’s my last night here after attending the Haptic and Audio Interaction Design conference at the Dresden University of Technology. I was presenting my work on the control of audio effects using head position estimation. I’ll have the PDF of the poster and paper in the portfolio section soon. There were many very interesting and fun people that I met on this trip. It was just a bunch of people that like to make cool things happen with technology!

Check out a few photos of the trip here:

http://gallery.me.com/pat_okeefe/100244

My apologies for the inferior white balance and focus of the iPhone camera. It did the trick though.


Comments Off

Getting Matlab 2008b+ to work with Mac OS X Snow Leopard

08.31.09 Posted in Uncategorized by

Being the nerd that I am, I pre-ordered Snow Leopard as soon as I could and also installed it on the same day it shipped. I did a complete reformat of my HD to get rid of all the junk I accumulated during the Leopard days. Much to my dismay, Matlab 2008b did not install properly because the Activation App wouldn’t work. I read the error logs and checked out some discussion on the mathworks website and determined it was a Java bug. Snow Leopard only comes with Java 6 and is 64-bit by default. Matlab, however, is written for Java 5 and 32-bit at that.

To get it to activate properly, navigate to /Applications/Utilities/ and launch “Java Preferences.app”.

Drag the 32-bit version of Java 6 to the top of both lists. Then, activate Matlab manually without using the internet (you’ll have to provide a license file). After the activation is successful, you can switch the Java back to 64-bit with no problems and launch Matlab normally. There is an exception thrown on launch, but I ran plenty of old scripts and even tried fdatool and whatnot with no problems.

Sweet.



Comments Off

Mac OS X Compilation for Heyu Home Automation

06.26.09 Posted in Heyu, Home Automation, Mac OS X by

I suppose this will be much like my last post. If you don’t know much about Heyu, this is from the main website:

HEYU is a text-based console program for remotely controlling lights and appliances in the home or office. The complete source is made available under the free Heyu License.

Heyu uses the CM11A computer interface to send and receive X10 control signals over the AC power lines to modules which can turn On, Off, or Dim attached lamps or appliances. It can store a schedule of timed events in the CM11A memory for execution when the computer is turned off or disconnected.

Now it is written for Linux, and that worked for me for a long time. However, I want to be able to create a GUI and use my most familiar programming environment of Xcode and Mac OS X.

Unless my search skills are horrible, it takes a looooong time to find instructions on how to compile the Heyu libraries for Mac OS X and get it up and running. I finally found some stuff from 2002, and I will share my newfound knowledge here so that it can spread on the interwebs.

First, you need a USB to Serial adapter. Sorry. They are probably $15, but cheaper ones must exist. Next, you need to discover where OS X thinks the adapter is. Open up Terminal and type:

cd /dev
ls

This should show a whole bunch of stuff. Ignore the tty* stuff and look for something that sounds like our adapter. My terminal shows an item called cu.usbserial. Perfect! So write down (or remember) the location.

Download Heyu from the website linked above. ‘cd’ into the downloaded directory and type:

./Configure freebsd

Mac OS X has a Unix base built upon freeBSD, so this creates a makefile perfect for OS X. Even though it says “now run make as a normal user,” there’s one last change left. Edit the x10.h file (I just use ‘pico’ in the Terminal) and perform the following:

change

#else
#define LOCKDIR “/var/lock”
#endif

to

#else
#define LOCKDIR “/tmp”
#endif

Now go ahead and run ‘make’. Heyu will guide you through the rest of the install. At some point you ‘sudo make install’ and give and option of where the config file should live. I chose the home directory so I could have easy access to it. (It will be a hidden directory so access through Terminal with ls -a). Also at some point, you’ll be asked to give the address of the CM11a interface, which you’ve connected to your USB to Serial port by now. Give it the location we found earlier. For what I found, this was ‘/dev/cu.usbserial’.

After the ‘sudo make install’ everything is ready to go! You can use the standard Heyu command set. Here are a few to get you started.

heyu start
heyu info
heyu on a1
heyu dim a1 10

My next Heyu post will discuss how to execute shell scripts and commands from an Xcode project using NSTask.



Comments Off

OpenCV and Xcode

06.26.09 Posted in Uncategorized by

OpenCV is really awesome. I’ve been using the library extensively in my summer research. For those who don’t know what OpenCV is, this is from the main website:

OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real time computer vision.

Example applications of the OpenCV library are Human-Computer Interaction (HCI); Object Identification, Segmentation and Recognition; Face Recognition; Gesture Recognition; Motion Tracking, Ego Motion, Motion Understanding; Structure From Motion (SFM); Stereo and Multi-Camera Calibration and Depth Computation; Mobile Robotics.

Cameo – Reid Draper: roommate and programmer extraordinaire.

I wasted a lot of time trying to get the library to compile on OS X. Don’t make the same mistake! Download the pre-compiled Universal Binary from this site. Currently, it is version 1.2, but a huge 2.0 release is coming in August.

Back to the framework. Don’t waste your time try to add build phases and whatnot. I never managed to get that to work. Just copy OpenCV.framwork to /Library/Frameworks. Do not add it to ~/Library/Frameworks, but the root Library.

After that, when adding “existing framework to application” just navigate to it. Everything will link just fine. Now, do something awesome.



Social Networks
Links
Search the Archives: