Useful Programs
Jonathan Pritchard

Below is a selection of codes I have written - feel free to use these, let me know if there are any bugs / ways to improve the code. Also, if the link is broken but you want the code e-mail me - .

Contents:

Top of Page

Matlab Code

Angular Momentum

Below are functions for calculating Wigner symbols and Clebsch-Gordan coefficients for calculating angular dipole matrix elements. These functions use Stirlings law for large factorials to avoid getting 'Inf' from Matlab above 170!. Equations are taken from 'Angular Momentum:Techniques in Quantum Mechanics' by V. Devanathan and 'Angular Momentum: An Illustrated guide to Rotational Symmetries for Physical Systems' by W. J. Thompson.

Curve Fitting

Download CURVE_FITTING.ZIP

This package contains tools for performing a weighted fit to a set of (x,y) data with y errorbars. This is done using a chi-squared minimisation to optimise the fit parameters. This can be done using one of three functions:

  • linfit.m: Weighted fit to a straight line using analytic formulae to obtain best fit gradient and intercept and their uncertainty.

  • fit_simplex.m: Performs weighted fit to any arbitrary function using the built in Matlab simplex algorithm (fminsearch). This does not evaluate the uncertainty in parameters, but is quite robust.

  • fit_function.m: Performs weighted fit to any arbitrary function using the Levenberg-Marquardt Algorithm. This returns both the best fit parameters and their uncertainties, as the method requires the gradient matrix to be evaluated, and is a very useful tool. This implementation uses a modified version of leasqr.m from the Matlab Central File Exchange and dfdp.m to evaluate the gradient numerically. In addition to returning the uncertainty, it is also possible to fix some of the parameters in the model.

Two example programs are included, linear_fit_example.m which shows how to use all three algorithms for fitting the sample data provided, and curve_fit_example.m which fits a Lorentzian to a different sample data set. I have included some fitting functions (lorentzian.m,gaussian.m,voigt.m,nth_order.m) which allow fitting to various functions or an nth-order polynomial, but it is very easy to define an arbitary function as long as it has the arguments 'y=arb_fun(x,p)' where p is a 1D array of fit parameters. For more information on curve fitting try 'Data Reduction and Error Analysis for the Physical Sciences' by Bevington and Robinson or 'Measurements and their Uncertianties' by Hughes and Hase, and contact me if you have problems with the code.

In addition, plotterr.m is also included as this allows plotting data with both x and y errorbars.

Optical Bloch Equations

Download MATLAB_OBE.ZIP

This contains code for solving OBEs for two and three level atoms using Matlab integrators. The example programs calculate the result for scanning the probe laser about resonance (as done in our cold atom experiments) but is easily adapted to a scanning coupling laser or time-dependent Rabi frequencies for schemes such as STIRAP.

FORTRAN Code

Complex ODE solver

Download FORTRAN_ODE.ZIP

This contains both double precision and double complex fixed step 4th-order or adpative step 4th/5th order Runge-Kutta integrators for solving a set of ordinary differential equations. The code is derived from 'Numerical Recipes in Fortran 77', 2nd Ed. by W. H. Pres et al.. The integrators are contained in module ode_solver.f90 and comes with example programs for both the double and complex integrators.

Optical Bloch Equations

This contains code for calculating OBEs for two or three level atoms.

Rubidium Rydberg Wavefunctions

To be added soon...

LabVIEW Code

Tektronix DPO scope Library

A library of subVIs to interface with DPO scopes to set triggering and acquisition settings and to read waveforms into LabVIEW. Save to folder 'labview\user.lib' to install as a user library. To use the VIs it is necessary to install the USB driver for the scope available from Tektonix.To save right-click DPO_INTERFACE.LLB and select 'save as'.

Top of Page

Content © Jonathan D. Pritchard, Durham University 2009