The spectrometer code consists of several functions and scripts written for the GNU Octave/MATLAB environment. The code supports JPEG spectrographs and raw spectrographs decoded to PGM with the help of dcraw. Within the archived code there are two primary functions: wavelength_calibrate and image2spectrum, several support scripts and functions, sample spectrographs, and example scripts that demonstrate how to use the provided functions to turn the spectrographs of a cyan LED and incandescent bulbs into radiometrically calibrated spectrograms. You are free to reuse the code in accordance with the BSD open source license.
spectrometer code README.TXT — be sure to call setup_path.m when you start a new session with the spectrometer code.
spectroradiometer code only (github) — This repository contains only the spectrometer code. It does not provide the pre-processed spectrograph mat-files nor raw spectrographs. None of the primary scripts nor example scripts will work until you provide them with your own data or sample data to process.
If you’d like to try out the code with some sample data, download one of the sample data archives below. Two archives are offered, but only one is needed. It’s better to get sample_data.zip, but if you have trouble downloading a file that large you can get minimal_sample_data.zip which is a third the size.
sample spectrographs zip file (sample_data.zip, 969 MB) — This archive contains pre-processed spectrograph mat-files and raw spectrographs. With this sample data set: All of the example scripts will work. The primary script make_master_dark_flat_bias.m will not work because the frames it processes are not included in this archive to save space.
sample pre-processed spectrograph mat-files zip file (minimal_sample_data.zip, 318 MB) — This archive contains pre-processed spectrograph mat-files. With this sample data set: All of the example scripts will work. The primary scripts batch_preprocess.m, batch_raw_decode.m, and make_master_dark_flat_bias.m will not work because the frames they process are not included in this archive to save space.
image2spectrum() – converts a spectrograph to a spectrogram by summing the columns within a region of interest.
wavelength_calibrate() – takes a spectrograph of a CFL bulb and plots a spectrogram, requests that the user picks out specific spectral peaks, and then uses the peaks pixel locations to calculate a wavelength scale to replace the column number scale.
bayer_demosaic() – converts a Bayer raw image into an RGB image matrix by interpolating missing pixels in a channel from the nearest neighbors in that channel.
generate_Wbb_spectrum() – outputs the emissivity corrected, black-body spectrum of a tungsten filament incandescent bulb.
batch_preprocess – ensemble averages and calibrates (noise reduction) every spectrograph. This script needs to be run once for every new set of spectrographs.
batch_raw_decode – decodes all raw images found within a parent directory and all of it’s children directories. This script needs to be run once for every new set of spectrographs.
make_master_dark_flat_bias – converts a collection of calibration frames into master calibrations frames. This script only needs to be run on a new set of calibration frames. It’s necessary to take a new set of dark frames if you change the exposure time. Each camera needs it’s own set of calibration frames.
CHDK scripts and grid
CHDK_files.zip contains two lua scripts and a custom grid. shootn.lua sets the camera’s exposure time, aperture, zoom, focus, and ISO, then shoots N spectrographs. get_values.lua outputs the current camera settings, which can then be used to modify shootn.lua to alter the camera settings desired for shooting spectrographs. These scripts have only been tested on my Canon PowerShot A590, so you may have to modify them to work on your camera. Neither script is essential for taking spectrographs; they simply help automate the process. cfl.grd is a grid of vertical lines that occur at the locations of the most pronounced spectral peaks of a mercury compact fluorescent lamp’s spectrograph as recorded by my A590. You may not be able to use the grid directly, but you should be able to modify it easily so it better matches the CFL spectrum your camera captures.