Public Lab Research note

This is an upgrade for spectrometry. Try building it and report back how it goes.

PLab 3 Spectrometer Upgrade Prototype

by stoft | March 02, 2015 09:23 02 Mar 09:23 | #11649 | #11649

stoft was awarded the Basic Barnstar by liz for their work in this research note.


Even though the ink is barely dry on the new manuals for the PLab 3.0 Spectrometer Kit, I'd like to propose an upgrade. Simple changes to the existing design can significantly improve the spectrometer's performance as is shown in the plots below.


Spectrometer Stability

Spectrometer Noise

Spectrometer Time Filter

Spectrometer Noise Solution?

Spectrometer Peak-Hold

Spectrometer DVD-Alignment Auto-Correction


The plot below compares the before-and-after upgrade of a CFL spectral response:


Note the improved sharpness of the peaks and the added detail in the 575-630nm region which shows actual spectral information, not just added noise; while the background noise remains low.


This next plot shows a close-up of the 435nm Hg peak from a CFL. You can clearly see the improved resolution between the existing Vers 3.0, the 3.0-upgrade proto and extracting camera data at full 1600pix camera image resolution. (SoftwareWorkBench (SWB) will require an update to take advantage of this last improvement.) The FWHM value is the measure of the peak's Full Width at Half the Maximum of the peak's height. It is a common measure of resolution bandwidth for spectrometers.


The above plot shows a close-up of the 545nm double Hg peak from the same CFL spectra. While a FWHM value is not a meaningful measure in this case, the sharpness of the peaks and the more clearly defined double-peak give support to the improvement shown by the 435nm peak.

Investigation: The folks at Public Labs (@Matthew, @Warren, have designed some very clever origami which provides a low-cost, more streamlined and light-tight enclosure. The kit was fairly quick to assemble and the system immediately produced spectra using SWB on release 35 of Firefox. However, I was unable to obtain the well-defined CFL spectra I'd expected; prompting the following questions:

1 - Is the new Sanm camera focus an issue? 2 - How does the new slit design affect performance? 3 - What is the impact of the new grating / camera optical configuration? 4 - Does the longer baseline and construction leave options for improvement?

[Note: I addressed question #1 and #2 separately; here: and here: ]

The answer to question #3 came from writing some Matlab code to analyze the optical path, diffraction angles and camera aperture; the details of which are described below. The answer to question #4 came from observing the mechanics of the kit's construction; a lack of mechanical rigidity of the optical path from slit to grating to camera. While precise positioning of those components is not required, spectral stability and performance is VERY sensitive to any CHANGE in that positioning. The camera and DVD grating are mounted separately using Velcro and the slit is slid into the paper housing which is NOT attached to the base.

Prototype: Remember that laboratory optical benches and commercial spectrometers are constructed on/with metal "base plates" because critical distances related to measuring light are so very small. So, the initial challenge was to find a simple, low-cost method to "hard-mount" all components to a common, rigid platform.


The photo above shows a new configuration prototype and SWB plots below confirm an associated performance improvement.


The construction is simple and the material cost is low. I used some Maple stock I had available which I trimmed to lengths of 1.5x0.25 stock and then cut to size and purpose. The important elements are glued to the base. The one flexible element is a "foam spring" which firmly holds the replaceable slit-elements. A rough sketch of the design is provided below.


Additional Details: For those that are interested, the following should help explain my observations and design choices.

Optical Path: I wrote some Matlab code to create a graphic to visualize the optics. It calculates the theoretical rays of light from source, through the slit, through the DVD diffraction grating and then imaged by the webcam. ( I did not include the webcam lens optics as I don't have the specs but the focal length and approximate image sensor area are known -- so, for simplicity, I assumed an ideal lens and simply plotted ray extensions to the image plane.)

First, consider the graphic below which I believe approximates the PLab 3.0 design


Notice that the grating incident angle is 25 deg from the grating normal so the exit light path bends another 20 deg at 524nm. Note also that the diffraction pattern is not symmetrical about the camera lens normal (the axis of the camera). This means the dispersion (the rate of change in pixel distance between diffracted wavelengths) is no longer linear and that adds difficulty to performing wavelength calibration with a CFL as the errors are magnified. (Read more about CFL Cal issues here: Finally, notice that the diffracted light could quickly get 'cut-off' by the physical aperture so one end of the spectrum might not fully expose the camera sensor. This shows there are limits which can quickly restrict the positioning of grating and camera and downsides to asymmetry.

DVD Grating: Many contributors, including myself, have tried to describe the origins of the mountings angles for the DVD grating and the camera optics. Hopefully, these diagram will help clarify the numbers behind the construction. Grating diffraction angles, which determine the exit angle for a given wavelength, are a function of the grating line dimensions, wavelength and incident angle.

There are two basic approaches to grating angle selection. The simplest to visualize is the grating mounted perpendicular to the light from the slit. Diffraction then forms two spectra; one above and one below that line. The spectrometer uses only one of these. The other method, and the one used here, is to direct the incident light at an angle to the grating and then the exit path from the grating will be perpendicular to the grating. The angular change is the same for either case.

Consider the symmetrical design:


Symmetry: If symmetry is assumed, then the remaining adjustment is the distance between grating and lens -- increasing the spacing widens the spectrum in the camera image but that adjustment range is only a few mm. For simplicity, I just try to leave a 1mm gap to avoid touching the grating against the lens housing. By mounting the polycarbonate-backed DVD grating at 45 deg, and importantly, mounting the camera at 90 deg to the grating, the spectrum will be closely "centered" within the camera's field of view. This keeps the dispersion linear (spectral line position change vs wavelength) and provides more leeway in the mounting distance between the grating and the lens (without the aperture cutting off either end of the spectrum).

[ Note: Symmetry is important to CFL calibration as discussed here: ]

The diffraction angle for Mode 1 (the lowest diffraction angle) is calculated as the arcsin( ((M*L)/d)-sin(IA) ) where M=mode (1 here), L=wavelength, d=grating spacing and IA=incident angle of the light to the grating. If the light from the slit is assumed to have an incident angle of 45-deg, Then the diffracted light at 524nm would exit the grating at 0-deg -- i.e. perpendicular to the grating. For the range of 395-650nm the light would exit at +/- 10-deg so the camera should be oriented on this 0-deg perpendicular to the grating to keep the spectra centered and symmetrical.

[ Note: The grating on a DVD is not floating in space and the physical material that supports the grating is part of the optical path. The index of refraction (IoR) for polycarbonate DVD material is about 1.55. The light from the slit is bent by the DVD's IoR at both sides so the end effect is only a small shift in position of the exit light path, not the diffraction angle, so can be ignored.]

Camera Aperture: The webcam's physical aperture is only about 1.5mm (even though the lens is ~5mm diameter -- only the center is used to reduce distortion). This means the grating must be placed within a couple mm of the camera or else the ends of the spectra will be blocked by the aperture. This is why the DVD grating needed to be mounted directly to the webcam housing in version 1.

The Slit: The slit is an easy way to increase the percentage of light reaching the diffraction grating which is collimated -- a parallel beam. However, a slit only offers an approximation of collimation and the exit light is far less parallel than a laser pointer. While using a slit is "pretty good", the real question is "how good?" and what are the implications.

[ Note: For more detail about the impact of slit width on spectral resolution look here: ]

Mechanical Sensitivity: The PLab 3.0 design nicely adds more distance between slit and DVD-Camera (about 200mm), which is good, and by placing the light source at some distance (across the room) from the spectrometer, the light exiting the slit will better approximate a parallel beam of collimated light. However, it's still not totally parallel and most light sources (like CFLs) are not point sources. This means that because the slit has some width, the light will spread a little before it reaches the grating. This causes some error because it effectively produces variation in the incidence angle of the light hitting the grating which will cause a variable position in the spectral line position on the camera image sensor. The result is some amount of "smearing" of the spectral information -- i.e. sharp spectral peaks won't be as sharp and the system resolution will be reduced. (In the graphic above, I used a wide 1mm slit; but only to demonstrate the potential impact of the slit and to calculate sensitivity.)

With slits as narrow as 0.09mm, this issue can be minimized. However, if the slit changes mechanical position, relative to the grating, then the spectral lines will also shift -- I call this "slit sensitivity" which I estimate at about 1.4 mils/pixel (or 12 mils/nm for 1600pix resolution). Slit sensitivity is a very significant source of error which means the slit must be mounted rigidly with respect to the grating and camera.


The above Matlab plot was generated by stepping between discrete 2nm increments in wavelength and then calculating the affect of the slit's collimation error (or equivalent mechanical position noise). With zero error, the plot would have been just single spectral lines; one for every 2nm. The program arbitrarily superimposed Gaussian noise with a bandwidth equal to the slit-induced error to simulate the creating of a "smeared" spectrum resulting from slit "noise". This allowed calculating the sensitivity of the slit's mechanical position on the detected spectrum. If the slit moves due to mechanical change (like vibration) that will easily result in significant spectral errors. The theoretical numbers suggest that vibration can easily degrade a spectrum and that while measuring a source, the slit must not move more than a few thousandths of an inch (12 mils/nm sensitivity).

I made this Help out by offering feedback!

People who made this (0)

None yet. Be the first to post one!


An excellent technical note. I have just read it once, but I shall have to read it again to get a fuller appreciation of the contents.


Reply to this comment...

I'm going to look at pricing these wooden blocks and see if we can integrate these changes into the kit in the next 12 weeks or so. Getting circular holes drilled in bocks is tough-- if there are other ways to go about doing the baffles that would be great-- but this all looks really doable.

Reply to this comment...

1/4-in thick pieces make it easy to assemble things square and the glue results are strong. Hardwood is rigid and handles machining better. I started with the idea of cutting 'U-channel' with the table saw, then cut into slices and glue (inverted) to form slots. This would work, but opted for the drill as much less time for a proto. You could glue-up pairs of 3/4 material then cut to 1.5x2 in, rip a center channel and then slice. As for drilling, since there are only 2 sizes (but same widths) multiple pieces can be drilled at once - a drill-press helps. There are 3 'tricks' to note with drilling: 1) use fine-grain wood for better material uniformity, 2) side-clamp the material to offset drilling forces which can crack the material and 3) with drill bits, drill to size with several steps. Perhaps a better alternative, which could be faster, is using a mill-bit in a drill press with a stack of pieces side-clamped in a mill-type vise. (side note: the best glue for this is the 'yellow' woodworker glue as it's thicker, stronger and sets quick. works with the black paper as well.)

Reply to this comment...

I was thinking along the lines of a U-channel. Drilling takes a lot of setup and if we could use a Dado blade or a router it would go fast. We get wooden blocks cut at a shop that replicates custom moulding for historic restoration, so they have a lot of gear for cutting shapes linearly. We'll probably stick with the Ash because it is pretty cheap in finish grades, so we don't have to do finishing work on the blocks.

Reply to this comment...

You might then also consider a u-ch shape for the camera block. That would nicely control the exact spacing between camera and DVD which is important. THen all you need do is make the appropriate two cuts at 45-deg (the top of the piece need not be flat as in my proto). Also, if the channel is kept to just 1/2-in, there is more surface area to support the slit w/paper-fold against a flat surface so it is held firm and flat. I don't know that the baffle is very critical but it seemed to help some with reflections and is cheap to add. I also noticed that the camera module on the PC board was not perfectly mounted on mine and there is the effect of camera angle (side to side when mounted) which results in the spectral image moving up/dn the image. While it doesn't matter if it's centered (the line can be reset in SWB) once the position is set by the user, if the camera tilts on it's tape mounting, that will translate into variable relative intensity. All this just means that while the camera 45-deg angle needs to be stable, so does the mounting to the camera doesn't move. Maybe a 1/2-in wide tape would be more secure?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

This is an amazing contribution. Thank you!

Reply to this comment...

Sounds great so far.

One question: if you put a second slit right in front of the grating/webcam subset - wouldn't the light be even more parallel?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

Interesting thought, but the camera is (ideally) focused on the slit so adding a second one next to the lens would be out of focus; though maybe if wide enough and aligned carefully might not interfere. Astronomical spectrometers can dispense with the slit as stars are point sources.

Reply to this comment...

This is such a big post, I'm wondering if we could continue (as our earlier upgrades start to see replications) to adapt multiple additional upgrades out of it -- like swappable slits, perhaps. And do you think we could then reference this from each of the narrower-scoped upgrades and remove the original from the upgrades grid?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

Alternatively -- we could consider a "replication" of each and every sub-upgrade to then constitute a replication of this larger set of changes, and link out to the sub-upgrades from the top of this one. Seems like there are several options.

Reply to this comment...

@warren, I'm not sure I follow the linking details for grids etc., but more abstractly, a tree structure comes to mind. This note describes one complete upgrade with the fundamental change of mechanically linking slit, DVD and camera. If an upgrade did not do that for some reason, it would be a fundamentally different approach. Beyond this basic concept, each component might be considered a separate sub-upgrade -- i.e. a number of slit designs, alternate grating options, alternate camera variants, etc. There is also the upgrade variant of materials -- all 3 parts still mechanically linked, but switching materials (like my note on using only paper and tape). So, I'm just suggesting that it is more the concept of mechanically linking Slit/DVD/Cam that is the "root" as opposed to specific materials. Similarly, this would also apply to slit designs. Maybe this would be applicable to your thoughts about grids and organizing notes?

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

This is a bit off-topic to the thread, but I want to give credit to @stoft for contributions from this thread to a project I've been working on for about six months on measuring cameras' spectral sensitivity. Particularly, making the spectrum splay symetrically on the camera sensor is important, and what @stoft wrote here was instrumental to modifying my lightbox design accordingly. I wrote about the whole project in a series of threads at; the specific post describing the symmetry quest is here:


Thank you for sharing this great work @glenn_butcher , and for taking the time to credit and celebrate @stoft, a wonderful contributor! 😃

Reply to this comment...

Login to comment.