# Beer at work!?!

I once worked at a place that had beer at work… it was great and we never really had any issues with it. In fact I’d say it served as a great way to bring together a group of, seemingly, misfits.

Sparkfun does it too and here is a set of rules they abide by. We had no such thing. But maybe Sparkfun is on to something.

Sparkfun's Beer Policy

# Add a Label to a Colorbar in Matlab

To add a label to the colorbar in your current figure, just use:
 t = colorbar('peer',gca); set(get(t,'ylabel'),'String', 'Colorbar Label Text Here'); 
where t is just a handle.

# You are an Engineer!

Just because you aren’t an engineer working inside a large corporation known for engineering that doesn’t mean you shouldn’t work like an engineer when it comes to documenting your open source projects.

I caught a great talk by Amanda Wozniak at the Open Hardware Summit about project design. While the talk used the development of an Arduino servo controller as an example of documenting your process, I think what was presented could be applied to the design process in general.

When we talk about open (source) hardware it would seem that CAD files and a bill of materials is enough for anyone to understand and adapt your design— but that’s not really the case. Schematics and a list of components doesn’t say anything about what you were thinking when you were designing your project. Stupidity or brilliance may be lurking in there but it’s not so easy for someone else to reverse engineer your thoughts.

It doesn’t matter if you are working on one aspect of an integrated project or if you are a solo hardware hacker you should have the same approach to documenting your design. Inside of private (closed) projects there is a great deal of documentation behind corporate walls that you may get a chance to see if you sign non-disclosure agreements. Just because a project is closed doesn’t mean that there isn’t any documentation, it’s just not available to you. In the end, an engineer on a large, closed corporate project ends up having to do more paperwork justifying components and commenting on liability issues. We get a break in this regard when working on projects that aren’t commercial.

This design and documentation process is straightforward:

1. An idea!
3. Design & record your rationale;
4. Review what you’ve done;
5. Make it and test it.

but that’s not all… you need to evaluate your design:

1. Does it work?
2. Did you address the questions (see step 2)?

Now repeat steps 2—7 until you are ready to unleash your design onto the world.

This thinking can be applied to both hardware and software projects. Documenting your design rationale is overlooked and important step in truly open-sourcing your project. Even if you aren’t an engineer, you are when it comes to documenting your projects!

Check out the presentation for yourself amongst the many others from this year’s Open Hardware Summit.

# Installing SciPy/ipython with macports

Install ipython/python v2.6:
 sudo port -v install py26-ipython 
This is probably going to take a good two or three hours, depending on what your system. If you have a pretty minimal set of macports packages, count on this taking around 3 hours on a macbook pro (circa 2010).

Install matplotlib:
 sudo port install py26-matplotlib 

“python_select” is deprecated, so just use “select” to select the appropriate python version to add to your path:
 sudo port select python python26 

Install wxpython. This required to drive the graphical backend (i.e., when using the “show()” command). You can get around this by using the MacOSX backend, but if you have time go ahead and install this (it’ll probably take an hour or more):
 sudo port install py26-wxpython 

To get images to show you need to set the appropriate backend. Edit your matplotlibrc configuration file. It should be located at:
 ~/.matplotlib/matplotlibrc 
If it doesn’t exist, go ahead and make it and edit (using textmate):
 touch ~/.matplotlib/matplotlibrc mate ~/.matplotlib/matplotlibrc 

Make sure the following line is added to the configuration file, using MacOSX as the backend seems to work fine.
 backend : MacOSX # Use macosx as the plotting backend. 
I used this since I was waiting for wx-python to compile. More information about various settings in the configuration file can be found here.

Fire up pylab:
 ipython-2.6 -pylab 
and generate a sin plot:
 x = arange(0,10,0.2) y = sin(x) plot(x, y) 
If a plot shows up you have Numpy installed and MacOSX is a functional backend.

Have a beer!

# Using Papers and Web of Science Proxy

Papers has been a pretty good app for dealing with all the PDFs I get from journals. I originally used google scholar to get BibTex article metadata but it leaves something to be desired. So I started using Web of Science to search for articles and match papers. It works great… when I am within a network that has a subscription! But what about when I am at home? I have access through a proxy server but papers doesn’t seem to acknowledge this as an option.

Lo and behold, Harvard medical school has instruction on how to set this up.

In short, for Papers versions <2, you just need to append the address contained in gatewayurl.txt with your EZproxy address.

For instance, change:
http://wok-ws.isiknowledge.com/esti/soap/SearchRetrieve
to include the url of your EZproxy server:
http://wok-ws.isiknowledge.com.EZproxyserver.edu/esti/soap/SearchRetrieve

You can find gatewayurl.txt in:
Users/username/Library/Application Support/Papers/PlugIns/SearchEngines /WOSSearchEngine.searchengine/Contents/Resources/

# Where can I buy Vegemite in NYC?

Wondering where Vegemite is to be found in New York City?

UPDATE: Looks like Morton William’s has it too… at least at the Morty’s on 23rd St @ 2nd Ave—and it’s a bit cheaper than Kalustyans.

I have found it in Manhattan at Kalustyans– $8.99$13.99 for a 150 220 gram glass jar:

123 Lexington Ave (bet. 28th & 29th Sts.)
New York, NY 10016
(212) 685-3451 ?

# Discharing a Capacitor

The practical application of discharging a capacitor in an RC circuit is a tradeoff between the time it takes to safely discharge a circuit and the amount of power dissipated in the resistor. The voltage across the plates of a capacitor decreases exponentially with time during discharge, $V = V_0 e^{-t/RC}$, where the capacitors time constant is defined as:

$\tau = RC$

It is generally assumed that a capacitor is “fully” discharged after 10 time constants (10*RC). For instance, a 3500 microfarad capacitor with a 20 kohm resistor has a time constant of 70 seconds. It should be fully discharged in ~12 minutes. Supposing that the capacitor initially has 400 volts across the plates, the voltage after 10*RC is 18 millivolts. This is found by solving the equation above; or can be approximated by (400 volts)*(0.37^10), since each time constant reduces the voltage by 63 %.

The second factor to consider is the power dissipated across the resistor. To safely discharge a capacitor the power dissipated by the resistor must be within its limits. The power dissipated by a resistor is:

$P = \frac {V^2}{R}$

Thus for the RC circuit mentioned above the resistor must be capable of dissipating:

$P_{diss} = \frac {(400~\textrm{volts})^2}{20~\textrm{k}\Omega} = 8~\text{watts}$

Consider this before placing a standard 1/4 W resistor across that high voltage capacitor!

# Inner Product as Sum of Products {Matlab}

The inner product (mtimes, in matlab speak):

C = A*B;

is a neat way to get the sum of the product of two vectors. It may come naturally to those who often work with matrices, but I usually work with array operations (i.e. .*), so this is a neat “trick.”

The inner product of a row-vector and a column-vector, gives a scalar that is equal to the sum of the products over the respective indexes:

$A \cdot B = \begin{bmatrix} a_1 & a_2 & \hdots & a_n \end{bmatrix} \cdot \begin{bmatrix} b_1\\ b_2\\ \vdots\\ b_n \end{bmatrix} = \sum_1^n a_n b_n$
Matrix manipulation is where Matlab excels.

# Replace NaNs with Zeroes {Matlab}

The inner product of two vectors is equivalent to the summation of the product of the respective indices. Alas, there is a caveat! If there are any NaNs in either vector, the resulting scalar will be reported as NaN by matlab. So, to get around this, just convert any NaN in your the to 0. You can also easily convert NaNs to zeroes in a matrix with the same code because matlab can specify matrix elements with linear indexing.

The matlab code to replace NaNs with zeroes for any matrix, or vector, A is simply:

A(isnan(A)) = 0;