version (20.4 KB) by Maksym Sich
Load data from .SPE files (full support v2.x & v3.0) created by PI software (LightField, WinSpec).


Updated Wed, 28 Mar 2018 05:00:24 +0000

From GitHub

View License on GitHub

Load data from .SPE files created by Princeton Instruments software (LightField, WinSpec). Full support for v2.x & v3.0 multi-frame, multi-ROI files and header information.
[data, wavelengths, params] = loadSPE( filename )
If the file has only one ROI and one frame then data is a simple (2D) array. If the file has one ROI but several frames then data is a 3D array of dimensions ( height, width, number of frames).
If the file has several ROIs then the data variable will look different for v2.x and v3.x spe files due to the difference in how the data is stored.
For v3.x if the file has one frame and several ROIs data is a struct data.ROI{numOfROIs}( height, width). If the file has several frames and several ROIs in each frame then data is an array of structs data (numOfFrames).ROI{numOfROIs}( height, width).
For v2.x the data will be either a 2D or 3D array, depending on the number of frames. Then params.ROI will contain a struct with info on sizes of ROIs and location on the full frame, which then can be individually extracted. This may be added in the future releases
params.version contains version info of the file. For SPE v3.x the whole XML footer is parsed as a struct in params.SpeFormat.
SPE v3.0 file and XML specification is at
For the SPE v2.x all parameters were stored in file header some of the key parameters are stored directly in the 'root' of the params struct:
Full set of parameters are stored in params.full except for x and y calibrations which are stored separately as params.xcalib and params.ycalib. Full specification of the SPE v2.x header is available at
For SPE v2.x is a single 1D array defined by either x-axis or y-axis calibration, whichever is present in the file using the polynomial
For SPE v3.x wavelengths is a 1D array if there is a single ROI or a cell array of 1D arrays corresponding to the different ROIs

- 1 frame and 1 ROI per frame
[ d, w, ~] = loadSPE( 'example.spe' );
plot( w, d );

- 1 frame and several ROIs per frame. Some ROIs are 1D spectra, some are
2D images of CCD
[ d, w, ~] = loadSPE( 'example2.spe' );
for i = 1 : length( w )
[ x, y ] = d.ROI{i}';
if y == 1 %1D spectra
plot( w{i}, d.ROI{i} );
else %2D image
imagesc( w{i}, 1:y, d.ROI{i}' );
% or could simply plot pixels imagesc( d.ROI{i}');

XML parsing is implemented using functions based on, written by W. Falkena, modified by A. Wanner, I. Smirnov, X. Mo. xml2struct (C) 2012, W. Falkena

(C) 2018, M. Sich, The University of Sheffield
v2.7 27-03-2018

Cite As

Maksym Sich (2022). maxsich/loadSPE (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: xml2struct, xml2struct

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.