% Iterative fit to an experimentally measured blackbody spectrum
% to determine the color temperature (in K) and the emissivity.
% Uses the fitblackbody.m function.
% T. C. O'Haver, May 2008; edited to work in Octave, August 2013
format compact
global emissivity

% Enter data
wavelength=[200 250 300 350 400 450 500 600]; % Wavelength in nm
radiance = [.007 .011 .02 .04 .07 .08 .1 .1]; % Measured radiance in Watts/cm2/sr

% Perform an iterative fit using FMINSEARCH and fitblackbody.m
start=3000;   % generic initial guess for blackbody temperature
options = optimset('TolX',0.1);  % Determines how close the model must fit the data
% Temperature=fminsearch('fitblackbody',start,options,wavelength,radiance);
Temperature=fminsearch(@(lambda)(fitblackbody(lambda,wavelength,radiance)),start);
% Compute a model and plot it (blue line) along with 
% the original data (red points)
model=emissivity.*1.19111E+16*wavelength.^(-5)./(exp(14380000./(wavelength*Temperature))-1);
plot(wavelength,radiance,'r.',wavelength,model,'b')
xlabel( 'Wavelength, in nm' )
ylabel('Radiance, Watts/cm2/sr')
emissivity  
Temperature
