[edit] Absorption Spectrum in Matlab
load color;
# Estimate the absorption spectra of the 3 cone types
# from 400nm to 690nm in 10nm steps from the lecture notes.
function [y] = gaussian(a, b, c, x)
y = a.*e.^(-(x.-b).^2/(2.*c.^2));
end;
blue = gaussian(1,450,25,linspace(400,690,29));
green = gaussian(1,550,35,linspace(400,690,29));
red = gaussian(1,580,35,linspace(400,690,29));
cones = [red; green; blue];
plot(linspace(400,690,29), cones);
title "Absorption spectra"
xlabel "Wavelength"
ylabel "Absorption"
# Calculate the spectrum of reflected light for all combinations of
# light source and material. Comment.
neon_apple = neon.*apple;
neon_leaf = neon.*leaf;
sun_apple = sun.*apple;
sun_leaf = sun.*leaf;
plot(wavelengths, [neon_apple, neon_leaf, sun_apple, sun_leaf]);
title "Reflection spectrum"
xlabel "Wavelength"
ylabel "Reflection"
# Comment:
# Wider variety of wavelengths for sun, thus apple - red spectrum,
# leaf - green spectrum; only one wavelength for neon light
# Calculate the cone activation for all spectra of reflected light.
blue = transpose(gaussian(1,450,25,linspace(1,2286,2286)));
green = transpose(gaussian(1,550,35,linspace(1,2286,2286)));
red = transpose(gaussian(1,580,35,linspace(1,2286,2286)));
neon_apple_blue = neon_apple.*blue;
neon_leaf_blue = neon_leaf.*blue;
sun_apple_blue = sun_apple.*blue;
sun_leaf_blue = sun_leaf.*blue;
plot(wavelengths, [neon_apple_blue, neon_leaf_blue, sun_apple_blue, sun_leaf_blue]);
neon_apple_green = neon_apple.*green;
neon_leaf_green = neon_leaf.*green;
sun_apple_green = sun_apple.*green;
sun_leaf_green = sun_leaf.*green;
plot(wavelengths, [neon_apple_green, neon_leaf_green, sun_apple_green, sun_leaf_green]);
neon_apple_red = neon_apple.*red;
neon_leaf_red = neon_leaf.*red;
sun_apple_red = sun_apple.*red;
sun_leaf_red = sun_leaf.*red;
plot(wavelengths, [neon_apple_red, neon_leaf_red, sun_apple_red, sun_leaf_red]);