Fetch Spectrum Through Ocean Optics Spectrometer Using MATLAB Instrument Driver
This example shows how to acquire the spectrum of a fluorescent light source from an Ocean Optics Spectrometer.
Introduction
Instrument Control Toolbox™ supports communication with instruments through high-level drivers. In this example you can acquire spectrum from an Ocean Optics Spectrometer using the MATLAB Instrument Driver.
Requirements
This example requires the following:
- A 64-bit Microsoft® Windows® 
- Ocean Optics spectrometer USB2000 
Create MATLAB Instrument OmniDriver object.
spectrometerObj = icdevice('OceanOptics_OmniDriver.mdd');
Connect to the instrument.
connect(spectrometerObj); disp(spectrometerObj)
NatUSB_64
Driver: NatUSBWin_64
   Instrument Device Object Using Driver : OceanOptics_OmniDriver.mdd
 
   Instrument Information
      Type:               Spectrometer
      Manufacturer:       Ocean Optics
      Model:              QE65 Pro, Maya2000 Pro, Jaz EL350, HR2000, USB2000, USB4000, NIRQuest
 
   Driver Information
      DriverType:         MATLAB generic
      DriverName:         OceanOptics_OmniDriver.mdd
      DriverVersion:      1.0
 
   Communication State
      Status:             open
Set parameters for spectrum acquisition.
% integration time for sensor. integrationTime = 50000; % Spectrometer index to use (first spectrometer by default). spectrometerIndex = 0; % Channel index to use (first channel by default). channelIndex = 0; % Enable flag. enable = 1;
Identify the spectrometer connected.
% Get number of spectrometers connected. numOfSpectrometers = invoke(spectrometerObj, 'getNumberOfSpectrometersFound'); disp(['Found ' num2str(numOfSpectrometers) ' Ocean Optics spectrometer(s).']) % Get spectrometer name. spectrometerName = invoke(spectrometerObj, 'getName', spectrometerIndex); % Get spectrometer serial number. spectrometerSerialNumber = invoke(spectrometerObj, 'getSerialNumber', spectrometerIndex); disp(['Model Name : ' spectrometerName]) disp(['Model S/N : ' spectrometerSerialNumber])
Found 1 Ocean Optics spectrometer(s). Model Name : USB2000+ Model S/N : USB2+H11505
Set the parameters for spectrum acquisition.
% Set integration time. invoke(spectrometerObj, 'setIntegrationTime', spectrometerIndex, channelIndex, integrationTime); % Enable correct for detector non-linearity. invoke(spectrometerObj, 'setCorrectForDetectorNonlinearity', spectrometerIndex, channelIndex, enable); % Enable correct for electrical dark. invoke(spectrometerObj, 'setCorrectForElectricalDark', spectrometerIndex, channelIndex, enable);
Acquire the spectrum.
wavelengths = invoke(spectrometerObj, 'getWavelengths', spectrometerIndex, channelIndex); % Get the wavelengths of the first spectrometer and save them in a double % array. spectralData = invoke(spectrometerObj, 'getSpectrum', spectrometerIndex);
Plot the waveform.
    plot(wavelengths, spectralData);
    title('Optical Spectrum');
    ylabel('Intensity (counts)');
    xlabel('\lambda (nm)');
    grid on
    axis tight

Clean up.
disconnect(spectrometerObj); delete (spectrometerObj);