Jonathan Thomson's web journal

Convert Spectrographs to Spectrograms April 24, 2010

Introduction
Once you’re able to capture quality spectrographs with your spectroscope you can use a computer to convert a spectrograph to a type of plot called a spectrogram. Here’s an example of a of spectrograph of a blue LED converted to a spectrogram.

 

A gray image is composed of a grid of boxes called pixels. Each pixel has a unique location described by its row and column number. The diffraction grating projects a spectrum horizontally across the camera’s CCD; therefore the spectral content of a spectrograph changes with respect to a change in column number, but not row number. Each pixel holds “counts” which is a measure of the intensity of the light that struck the pixel. If a single row is taken from a spectrograph the result is a point series of counts vs. column number. When this data is graphed the result is a plot know as a spectrogram. However, even better results are possible if several rows are averaged together to get a point series of “average counts” vs. column number. The image below shows a pictorial representation of how a spectrogram is obtained from a spectrograph by taking the mean of every pixel in each column. This gives a point series of average counts (or gray values) versus column number (or the horizontal component of pixel location), with the left most pixel being in column 1.

 

Since the spectrographs taken with a digital camera are color images it’s possible to get a separate spectrogram for the individual red, green, and blue channels, which may then be summed to get a single spectrogram covering the entire spectrum that’s visible to the camera.

A simple spectrogram without a wavelength scale can be obtained quickly by using ImageJ to process the spectrograph with Edit->Select All, then Analyze->Plot Profile. However, to get a spectrogram with a wavelength scale or to process raw images it’s necessary to use a more powerful tool such as GNU Octave or MATLAB; the spectrometer code to do this is discussed at the end of this article, but some might find it beneficial to review the code now, so here’s a link to it.

 

Calibration
Fluorescent lights use a combination of mercury vapor and phosphors to produce light. The image below is a spectrogram of a compact fluorescent lamp (CFL) with some of the wavelengths of peaks in the mercury (Hg) spectrum labeled.

 

These known peak wavelengths can be used to translate a column number scale to a wavelength scale. Here’s how to get a calibrated spectrum step by step:
1) Take a spectrograph of a CFL.
2) Turn the spectrograph in to an uncalibrated spectrogram by averaging the pixels’ counts column-wise.
3) Locate the pixel locations of the reference Hg peaks in the spectrogram.
4) Use polyfit to find a 2nd order polynomial that relates the peaks’ pixel locations to the peaks’ wavelengths: λ = p(x) = ax^2 + bx + c
5) Use this polynomial to translate the entire column number scale to a wavelength scale.

 

The function wavelength_calibrate will present an interactive plot of the CFL’s spectrum and ask the user to pick out reference peaks 2, 5, and 7. The plot shows the separate red, green, and blue channels instead of a single average of all three because it is assumed that a single channel’s spectrum is more accurate over the range of wavelengths it transmits than all three channels combined. This is evident by examining the colored peaks’ heights. Based on the peaks’ locations, wavelength_calibrate will then calculate the wavelength scale λ. Once you’ve calibrated it, the computer+spectroscope system becomes a spectrometer capable of producing spectrograms with an accurate wavelength scale that can be used to replace the column number scale of any other spectrograms taken during the same session as the reference CFL spectrogram. If the spectroscope is moved or other environmental factors change the system must be recalibrated.

 

Cropping
There are a couple of reasons why it is best to crop the spectrograph to a region of interest before converting it to a spectrogram instead of using the entire spectrograph. The first reason being peak widening which is a result of the projection of the spectral lines onto the CCD not being perfectly vertical nor perfectly straight. The second reason is to leave out the dark regions at the top and bottom of the spectrograph which contribute nothing but noise to the resulting spectrogram.

 

Raw versus JPEG
It takes a good bit of processing to transform the light detected by a camera’s CCD into a JPEG. This processing produces pictures that look good to the human eye, but is harmful if your goal is to make accurate spectrograms. Therefore it’s best to use raw images to produce spectrograms. Raw shooting is usually an option found on higher-end cameras; however, some Canon point and shoot cameras capable of running the alternate firmware, CHDK, can have raw shooting enabled.

 

Spectrometer Code
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 of a CFL, 100W incandescent, 60W incandescent, and a cyan LED, and example scripts that demonstrate how to use the provided functions to turn the spectrographs of the cyan LED and incandescent bulbs into radiometrically calibrated spectrograms. You are free to reuse the code in accordance with the BSD open source license.

 

Links
Great source of info on how CCDs work

How digital camera works + various spectral sensitivity plots

An example of using a homemade spectrometer to determine if the amount of IR emitted from a green laser is safe.

Description of spectroradiometers

CFL Spectrum

 

Continue Reading

>>>Next — Determining the System Function>>>

<<<Previous — How to Build a Spectroscope<<<

 

Advertisements
 

2 Responses to “Convert Spectrographs to Spectrograms”

  1. […] being monochromatic, as would LEDs. You can also add lamps with known emission spectra – Jonathan Thomas uses the spectrum of a fluorescant lamp; there is no particular reason that you couldn’t similarly use […]

  2. Could you please tell the full process of Wavelength calibration,So how can I map Column number to Wavelength.Please advise,I am in big trouble


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s