Problem Set #2 -- COGS 501

Due 10/4/2010

1. Basic section

A. Download the files c501a.m, c501b.m and MartyClip1.wav into a folder (or directory) accessible to Matlab. If the folder you use is not Matlab's "work" folder, then use the Matlab "path" command to give Matlab access to the folder you put the files in. Use Matlab's "help" command to see how to use "path", either by typing

>> help('path')

at the command prompt, or by using the "help" menu item.

You can run the first two files by typing in the Matlab command window

>> c501a

and

>> c501b

If you the Matlab code in these files already makes sense to you, this will be enough. If you need more introduction to Matlab-ese, then open the files in an editor (e.g. by using the menu File>>Open in Matlab), or print them out, and try going through them by typing the commands yourself, and trying some alternative formulations to see how things work.

Thus at the point where c501a.m invokes the command

plot((2*SR:3*SR)/SR, M(2*SR:3*SR) )

If you don't understand everything that is happening, use "help" -- here it would be help('plot')-- and/or try breaking the command up into pieces, e.g. type

>> (2*SR:3*SR)/SR

and see what you get; you could break that down further by typing

>> 2*SR

etc.

B. Now create a function getzc( ), analogous to the function getamp( ), for calculating zero crossing rates in any signal. The first line should be something like

function z = getzc(X, SR, window, increment)

Verify that it works. Hand in the .m-file for this function, along with a Matlab script that offers some evidence that it works -- say by graphing a couple of analysis windows and showing that the zero-crossing count is correct.

2. Intermediate section

Download colmatch.mat and load it into Matlab. This file contains a number of matrices and vectors related to the color matching problems discussed in class. In particular, the variable P is an N x 3 matrix containing wavelength spectra for three basis lights ("primaries''), and the variable M is a 3 x N color-matching matrix corresponding to these primaries. For these problems N=31, corresponding to samples of the wavelength spectrum from 400nm to 700nm in increments of 10nm.

Set the variable light to a random vector of length 31 (help rand will give you information about how to do this). We will consider the components of this vector to be samples of the wavelength spectrum of a particular light.

  1. What combination of the three primaries in P will match the appearance of this randomly chosen test light? Compute the wavelength spectrum of the matching light (as a linear combination of the three primary wavelength spectra) and compare it to that of the test light. Why is it different?
  2. The variable Palt contains a different set of primary lights. Compute the corresponding matching matrix Malt (you will probably need to make use of the Matlab function inv which computes the inverse of a square matrix). Repeat the previous exercise with Palt and Malt. Is the matching spectrum different than in the previous exercise?
  3. The variable Phosphors contains the emission spectra of three standard color monitor phosphors. How would you choose the amplitude of each phosphor's emission in order to produce light on the monitor that matches light? Compute these amplitudes and demonstrate that the resulting mixture of phosphors does indeed produce the same tri-stimulus coordinates in the matching experiment.
  4. The variable M2 contains yet another matching matrix. This one was computed for a color-impaired individual, using the primaries in P. Compute the SVD of M2. How can you tell this individual is color-impaired? Assume that the individual has a standard color-blindness problem: they are missing one or more cone types. Derive the spectral sensitivity of the missing (or remaining) cone.
  5. The variable Cones contains approximate spectral sensitivities of t he three color photoreceptors (cones) in the human eye. They are ordered such that Cones(1,:) corresponds to the L (long-wavelength, or red) cones, Cones(2,:) the M (green) cones, and Cones(3,:) the S (blue) cones. Plot these using plot or try rgbplot, and compare to the cone sensitivity vector you derived in the previous problem. Which cone was missing from (or remaining in) your color-blind subject?

3. Advanced Section

  1. Having just purchased a new house in Center City, you decide to paint the baseboard trim a new color. In particular, you'd like to have the trim match the color of your new couch (chartreuse, of course). You make a trip to the paint store, carrying with you a sample piece of fabric (complete with plastic slipcover). The store carries two brands of paint: ShabbyTint, which is mixed from three primary colors, and RichTone, which is mixed from a set of six primary colors. Naturally, the RichTone costs four times as much, so you decide to go with the ShabbyTint, and quickly pick a matching color from the ShabbyTint paint chart (the store mixes it for you, from the three ShabbyTint primaries).

    Load the file paint.mat into Matlab. This will define a few variables:

    • couch contains a vector of the color reflectance function of the couch.
    • shabby is a matrix whose columns are the reflectance functions of the three ShabbyTint primaries.
    • rich is a matrix whose columns are the reflectance functions of the six RichTone primaries.
    • fluo contains a vector of the color spectrum of the fluorescent lights in the paint store, and in your living room.
    • daylight contains a vector of color spectrum of the sun.

    1. Determine the mixture of ShabbyTint primaries that will match the sample you've taken to the paint store. Assume that paint-mixing is additive (it really isn't!). Plot the wavelength spectra of the sample and the paint (when viewed in the paint store) on the same plot (use the Matlab hold command to do this). Demonstrate that a paint mixed from this proportion of the three primaries will look just like the sample.
    2. You may now view these colors on your monitor. To do this, first download the MATLAB m-file showcols.m and place it where MATLAB (or Octave) can "see" it. Then create two column vectors of height 3, called rgb1 and rgb2 containing the monitor gun values (proportion of each phosphor) to be used to display a color matching the couch and the shabby paint mixture under fluorescent lighting. You should assume that the matrix Phosphors contains emission spectra that are correct for your monitor (this may not be true). Then call the function showcols(rgb1,rgb2).
    3. You take the paint home, and paint a small sample of baseboard. The next morning, when the sun comes up, you find to your horror that the baseboard doesn't match the couch at all. What happened? Show that the two colors really don't match when viewed under daylight. Render them on the screen using showcols to check this.
    4. What is the best (least-squares) combination of ShabbyTint primaries that you could have used to match the couch both in daylight and fluorescent light?
    5. What if you use the RichTone paint? Assess the quality of the best-matching mixture under both daylight and fluorescent light.