Field Spectroscopy Facility Post Processing Toolbox
by Iain Robinson
A toolbox for importing and processing optical spectra acquired with portable spectroradiometers.
%ABSOLUTEREFLECTANCE Calculates absolute reflectance spectra from relative
% R_ABS = ABSOLUTEREFLECTANCE(R_REL, PANEL)
% Multiplies all spectra in the structure R_REL by a panel calibraiton
% specturm PANEL.
% P must be a structure with two fields: a column vector of wavelengths
% (P.wavelength) and a column vector of corresponding panel reflectances
% (P.data) in the range 0 to 1.
% The panel calibration PANEL can be imported from a comma-seaprated
% values (CSV) file or an Excel spreadsheet using the
% importpanelcalibrationspectrum function.
% panel = importpanelcalibration('FSF panels.xls', 'SRT #005')
% R_abs = absolutereflectance(R_rel, panel)
% See also: importpanelcalibration
% FSF Post Processing Toolbox
% Field Spectroscopy Facility, Natural Environment Research Council
% Author: Iain Robinson
% Contact: firstname.lastname@example.org
% MATLAB R2009b or later
% importpanelcalibration from FSF Post Processing Toolbox
% Revision: 1.2.9
% Date: 2011-03-28
function [output] = absolutereflectance(input, panel)
% Check that the wavelength scale is the same for all spectra in the
error('The wavelength scales of the input spectra are not all identical. To calculate the absoluterefelectance of an array of spectra all wavelength values must be equal.');
% Check that the wavelength scale is sorted in increasing order.
warning('The wavlelength values of the input spectrum (or spectra) are not sorted in increasing order. This may indicate that there are overlapped data in the spectrum; for example at the joins between different detectors. This may cause unpredicatble results in the overlapped regions during post processing.');
% Get the wavelength scale of the input spectrum.
inW = input(1).wavelength;
% The panel calibration data may cover a different range of wavelengths
% to the input spectra. The output wavelength scale should therefore be
% the wavelength range which is covered by _both_ panel and spectra.
minW = max(inW(1), panel.wavelength(1)); %...the smallest wavelength in _both_ panel and spectra (i.e. the maximum of the minimums).
maxW = min(inW(end), panel.wavelength(end)); %...the largest wavelength in _both_ panel and spectra (i.e. the minimum of the maximums).
% Set the output wavelength scale.
outW = inW(inW >= minW & inW <= maxW);
% Copy the input spectra to the output.
output = input;
% Overwrite wavelength and data fields with new values.
% Crop the output spectrum to the wavelength range: minW to maxW.
output(i).wavelength = outW;
output(i).data = input(i).data(inW >= minW & inW <= maxW);
% Interpolate the panel spectrum to the cropped wavelength scale.
%if panel.wavelength == outW
% P = panel.data;
P = spline(panel.wavelength, panel.data, outW);
% warning('Interpolated panel data.');
% Multiply the output spectrum by the interpolated panel spectrum.
output(i).data = P .* output(i).data;