% 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 700 800 1000]; % Wavelength in nm
radiance = [.007 .011 .02 .04 .07 .08 .09 .1 .095 .085 .06]; % 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.001);  % Determines how close the model must fit the data
% Temperature=fminsearch('fitblackbody',start,options,wavelength,radiance); Older form of coding
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,'ro',wavelength,model,'b')
xlabel( 'Wavelength, in nm' )
ylabel('Radiance, Watts/cm2/sr')
emissivity  
Temperature

