Monday, August 20, 2018

Fast inverse transform sampling for an arbitrary probability distribution

This is a fast Python implementation of Inverse Transform Sampling for an arbitrary probability distribution. Generating 106 random numbers with this crazy probability density function takes ~150 ms on a i5-3320M CPU @ 2.6 GHz, most of it from scipy.interpolate.interp1d.

Thursday, July 30, 2015

Animated stripchart

This script creates a moving stripchart-style plot of a data stream. Change num_points to increase the length of the section that gets plotted. (TODO: put in a matplotlib slider widget for num_points.)

Tuesday, July 22, 2014

Linear least squares phase estimation of a sine wave

This snippet extracts the phase out of a noisy sinusoidal signal. The algorithm is a clever linear least squares (LLS) scheme, courtesy of the IEEE waveform measurement standard for characterizing ADCs and DACs. It works in spite of the fact that the sine wave is non-linear -- which just underscores the point that the linear bit of LLS is linearity in the parameters, not the fit function. It works quite a bit faster than the Levenberg-Marquardt nonlinear least squares routine.

 

Monday, July 21, 2014

Exit fluff. Enter IEP !

After dinking around with getting iPython notebooks to work without trouble on my linux laptop, I've finally hit the limit of my patience for the sluggishness and foppish foofery of iPython notebooks. I tried to revert to my old gedit + Dreampie combination, but having been spoiled by executing code inline, I looked around for other alternatives. And found an amazing option: IEP 

The features I like include
  • syntax highlighting and the simple, uncluttered interface
  • organized file structure for projects
  • easy integration with matplotlib (and not having to switch back and forth with %pylab tags to make code run on different machines)
  • being able to run selected code snippets with just Alt + Enter !
One word for it. Liberating! 

Monday, June 16, 2014

Arduino gets its Due

After a few years away from Arduinos, I started thinking about them a few days ago as a possible solution for a laser feedback controller project. In the past, I have been unimpressed with the Arduino's ADC, and with its outputs: either PWMs that need to be post-filtered, or klugey DAC chips. And so I was delighted to see the specs of the new(ish) Arduino Due: 12 bit analog ADCs sampling (as fast as ~50 kHz), and real 12 bit DACs right on the board. Finally, something with enough juice to do useful things in the lab!

To celebrate, here's a simple arbitrary waveform generator, taking advantage of the Due Timer library.

Wednesday, May 7, 2014

Impedance of transmission lines

This code calculates the characteristic impedance of transmission lines of specified cross section, by calculating the electric potential through relaxation on a grid. You'll need to be able to run blitz from scipy.weave.

Here is an example of what it can do.