Blog Archives

Simulating a Line-Following Robot in R

February 14, 2013
By
Simulating a Line-Following Robot in R

I’ve been reading up on controlling mobile robots, and built a simple robotic movement simulator in R, using R graphing libraries. The motivation for doing this is to practice setting up the math for controlling a robot, without having to build a physical device. Starting with an over-simple model allows learning a bit at a

Read more »

Robot Localization in R

February 1, 2013
By

The excellent “Artificial Intelligence for Robotics” class on Udacity starts with a Python example on teaching a robot to determine where it is, given sensor data. Assuming the robot starts with a map of the world, and can make some observations of it’s surroundings, a series of movements and successive observations can quickly narrow the

Read more »

Building a JSON webservice in R

October 25, 2012
By
Building a JSON webservice in R

R is a programming language for mathematics and statistics. There are several R libraries available to support web development, including rjson and RJSONIO (note case – R library names are case sensitive). RJSONIO is based on rjson, but with modifications to improve performance working with large JSON payloads. The example below returns the data required

Read more »

Unit testing in R

October 23, 2012
By

Commentary R is a statistical programming language, with a strong focus on mathematical operations. When writing code that is math-heavy, unit testing becomes very appealing- while equations may look correct on paper, one minor error can ruin the output. R programming is also different to CRUD or enterprise software in that the R in-memory data

Read more »

Building a statistical significance testing web service powered by R

October 18, 2012
By

R is a programming language focused on solving statistical and mathematical calculations. R programs often operate on large, in-memory data sets, which feels somewhat similar to database programming. Examples in the R Cookbook bear a resemblence to functional programming in clojure, as others have noted. I’ve been exploring the language to gain insight into related,

Read more »

R Error: “Error in readBin(fileR, “integer”, n = Length/2, size = 2, signed = TRUE, : invalid ‘n’ argument”

October 15, 2012
By

The following error is an indication that an exceptional I/O error occurred. For instance, permissions denied, out of memory, etc. Normally the syntax of this error would indicate that a required parameter is missing from a function call, but with readBin it appears to be more often an exception. Error in readBin(fileR, "integer", n =

Read more »

Marking time in R

October 5, 2012
By
Marking time in R

In a previous example, I showed how to find the onset of a single drumbeat, as well as the chord at an instant. This new example extends the method to detect the onset of several notes in a row, and demonstrates some interesting challenges involved in musical transcription. The general process is to read in

Read more »

Finding the beat in R

September 8, 2012
By
Finding the beat in R

In a previous article, I described a method for detecting chords in an audio file (also available for Scala). Continuing on this theme, the following will find the onset of a drumbeat in a file, using R. I’m using a single drumstick click, which you can hear on freesound.org. This method detects sudden volume increases-

Read more »

Book Review: R Cookbook

September 7, 2012
By
Book Review: R Cookbook

The R Cookbook is written by Paul Teetor, a developer with degrees in statistics and computer science, specializing in finance. The programming language R is a specialized language designed for deep statistical research, although it has some support for other mathematical fields, such as matrix algebra and signal processing. True to the O’Reilly cookbook format,

Read more »

Detecting Pitches in music with R

September 2, 2012
By
Detecting Pitches in music with R

In a previous post, I described a method to detect a chord using a Fourier transform in Java/Scala. I’ve re-implemented the same in R, detailed below. This will generate an audio file containing the C-Major chord: library(sound) c<-261.63 e<-164.81 g<-196 len<-1 cData<-Sine(c,len) eData<-Sine(e,len) gData<-Sine(g,len) audio<-normalize(cData+eData+gData) saveSample(audio, "out\\ceg.wav", overwrite=TRUE) And a series of helper functions: magnitude<-function(x)

Read more »