This tutorial gives a complete walk-through of LeyLa, the Raman spectra analysis software.
- Load data
- Edit Spectra
- Fit Spectra
- Download and unzip LeyLa0.8.zip file anywhere on your computer (e.g. D:\LeyLa).
- Start Matlab and set path to this folder (D:\LeyLa). In Matlab go to: File->Set Path …, click on “Add Folder …” button, and then click Save and Close.
- Run LeyLa by writing in the command window “LeyLa”. Be carefull, Matlab is case-sensitive.
To import Raman spectra make sure you have ASCII files with two columns and no header. In the first column is the X coordinate, or the wavenumber in cm-1, and in the second column (Y coordinate) is the spectral intensity.
In the Menu, go to Data-> Load Data, or press Ctrl+L
After you select one or more ASCII files the last spectrum will be plotted on the main graph and the name of imported files will be shown in the left listbox. You can choose between different files by simply clicking on them in the left listbox.
In the title above the main graph sample description parameters are shown. To change those parameters go to Data->Sample Description. These information should be common to all imported spectra.
Description of the individual spectra can be added below the main graph in a large textbox.
The name of each imported spectrum can be changed by right-clicking on the name in the left listbox and select Edit. In the same way spectrum can be deleted or copied as ascii data to clipboard.If Fitted curve is available it can also be copied to the clipboard from the same menu.
After the spectra are loaded they can be edited in several ways:
You can subtract from the spectrum (i) another spectrum, (ii) fitted curve, or (iii) base line. All these operations can be done on a single spectrum. In the menu select Edit->Subtract and then “Subtract Base Line”, “Subtract Data”, or “Subtract Fit”.
- Subtract Base Line will search for “offset” and “slope” coefficients in the table on the Fitting panel. Those values will be shown in the dialog box where you can change them. After you press “OK” Y values will be changed to Y-slope*X – offset.
- Subtract Data will multiply spectrum with “ref_idx” number by a “factor” and subtract it from current spectrum with “spc_idx” number
- Subtract Fit will subtract fitted curve multiplied by a “factor” from its spectrum with the number “idx”.
Spectra can be normalized between 0 and 1. For this function go to Edit->Normalize. You will be asked for the range of spectra to be normalized. By default all spectra are selected (e.g. “1:3”, means all spectra from one to three). If you want to normalize only one spectrum enter its number. The number of currently selected spectrum is written in the dialog caption with “current = “.
Otherwise, the selected spectrum number is written in a textbox above left listbox (“Selected: #”).
Multiply the intensity of spectra by a given factor. For this function go to Edit->Multiply. In the dialog box you will be asked besides the range of spectra also the factor for multiplication. This command will calculate: Y = factor*Y, where Y is a vector of intensities.
Shift the selected spectra to the right by shift value. For this function go to Edit->Shift. In the dialog box you have to provide a range of spectra to be shifted and the numeric shift value, which can also be negative. The command will calculate: X = X + shift, where X is a vector of wavenumbers.
Bin data. This command will substitute n-neighbouring points with a single one having a mean value of their intensities. This will decrease the noise of the data, however, it will also decrease the number of points by a factor of n. In the dialog box you have to provide a range of spectra to be binned and the numeric value n under “Binning:”.
Spline Base Correction function. When choosing Edit->Spine Base Correction in the menu, the panel one the right will change to the “Spline Base Correction” panel. When pressing “Add Point” button a cross will appear on the screen which will allow you to place a point on your spectrum. When three or more points are placed a spline curve will be calculated between those points. You can remove points by pressing “Remove Point” button and click in the vicinity of a point you want to remove. If you change your mind before clicking, simply click on graph with right mouse button and any routine will be canceled. Added points can also be adjusted manually in the table in the panel. After you modify their values click on a button “Refresh”. When you are happy with the spline function. Press “Subtract Spline” button and “Done” button to close Spline Base Correction panel.
The Spline Base Correction can be done only for a single spectrum at a time. If while adding points you click on a different spectrum the points from previous spectrum will be saved and you can continue when selecting that spectrum again.
Return Original Data. If you want to restore the original data after changing it you can go to Edit->Return Original Data. After choosing the range of spectra, as before, those will be returned to the original state.
This program is mostly used to extract position, width, and intensity of the lines in the Raman spectra. To extract these values we need to first choose a model. There are several functions available to construct an appropriate model (e.g. Lorentzian, Gaussian, pseudo Voit, …). You can add various functions by first selecting the function in the “Functions:” combobox and then pressing “Add” button. Besides the peak functions there are also “power”, “slope”, and “offset” functions. The power function is defined as y = p# * xn# where # is substituted with a function number. Slope and offset functions are defined as y = slope * x, and y = offset, respectively. The definitions of the rest of the functions are specified in “spc_fun_lib.m” file. When adding a new function in spc_fun_lib.m be sure to add the name of the function also in the otherwise case at the end of the switch statement.
When the model is constructed and the functions are all added, a list of function parameters will appear in the table on the Fit panel. Notice that each parameter has its own function number at the end. These functions are also called components.
To get as good fit as possible the initial parameters have to be set similar to the final ones. The first step is to find the position of the peaks on the main graph. To get a position of the peak just left click on a graph close to a peak center (do not click on a line or a curve!). A gray vertical line will appear with coordinates shown in the bottom right part of the screen and printed in the Matlab command window. At the same time x coordinate will be copied to the clipboard. (If you right-click, horizontal line will be plotted and y coordinate will be copied to the clipboard.) After left click select “pos#” box in the table and press “Ctrl+V” keys. The rest of parameters have to be inserted by hand. Normally, a value of 1 for area and width is a good starting parameter and a value of 0 for alpha, slope, and offset. Press “Plot” button to see your current functions on the main graph. Adjust parameters by hand and pressing “Plot” to get a good agreement with the measured spectrum. You can also see individual components if you check the “Plot components” checkbox.
You can also specify a range on the x axis where the fit should be evaluated. “Range” editbox searches for pairs of numbers and plots or fits only in the regions defined by these pairs. For example, Range: “[300 400] [500 600]” will plot or fit spectrum only between 300-400 and 500-600 cm-1.
Keep in mind that the quality and the speed of the fitting procedure strongly depends on the proximity of the initial coefficients to the final ones and on the number of free parameters that the program has to find. To improve the performance try to keep some parameters fixed (choose fix checkbox in the table) and set parameter limits (“min” and “max” values). You can also run fitting several times with different parameters being fixed.
To fit the data press “Fit” button. If the agreement is not best, you can increase the number of fit repetitions in the “Repeat” textbox. When repeating, new parameters are automatically used as initial parameters.
The fitting procedure fails and moves your parameters to unphysical values, the initial parameters can be restored using “Undo” and “ReUndo” buttons below the table. The fitting parameters can also be exported to imported from an ASCII file. To do this go to the menu and select Fit->Parameters-> “Export”, “Import”.
When a spectrum was successfully fitted, you can continue manually by selecting another spectrum in the left listbox and repeat the fitting procedure. When some spectra are already fitted you can use “Plot Fit function” checkbox to toggle between showing and hiding fitted function. Another useful feature is “Update parameters” checkbox which controlles whether parameter table is updated when selecting different spectrum with fitted function or not.
In cases when you have a lot of spectra you can use the “Run” button. It goes automatically through a list of spectra and for each spectra it presses the “Fit” button. The list of spectra is defined by the dialog box where you specify the first spectrum index (“start idx”), the last spectrum index (“stop idx”) and step (“abs(step)”) size, which is normally 1.
The running process can be stopped by pressing the “Stop” button (before it was Run button) and wait for current fit to stop.
When running through spectra there are two additional update options: “Update coefficients” and “Update Fix column”. The first option allows you to update the parameter table after the spectrum is fitted or not. If not the same parameters will be used for fitting the next spectrum. This is useful when you want to fit all the spectra with the same initial parameters (uncheck “Update coefficients”) or when next spectra is very similar to the previous one and the parameters are not expected to change drastically (check “Update coefficients”). The “Update Fix column” checkbox allows you to keep the fix check box the same although “Update parameters” checkbox is checked. This is useful when you want to repeat the fitting using parameters from previous fit, however, this time you want to keep other coefficients fixed.
To provide faster access to different fitting modes and appropriate setting of “Update Parameters”, “Update coefficients”, and “Update Fix column” checkboxes we added Fitting modes in the menu: Fit->Mode-> …
- “Initiate” mode. In this mode all the spectra are fitted with the same initial parameters that are in the table.
- “Chain” mode. In this mode all the spectra are fitted with the optimized parameters from the fit of previous spectrum.
- “ReFit” mode. In this mode all the spectra are fitted with the optimized parameters from the previous fit of the same spectrum. Fix checkbox in the table is not updated.
|“Initiate” mode||“Chain” mode||“ReFit” mode|
|Update Fix column||–||–||false|
After fits have been obtained you can plot various coefficients as a function of spectrum number by pressing “Plot Results” button. In the dialog box select which parameters to plot (separated by comma), specify the list of components to put on the same graph for a parameter and whether you want to display errorbars of the parameters.
There are several export options in the Fit->Export menu:
- Export Data. Similar to Copy Data when right clicking on the spectrum name in the listbox, however, here data is exported to a file.
- Export Fit Function. Again similar to Copy Fit functions, but here the export is done to a file.
- Export Results: Fit results will export the parameter table to a file. Rows represent different spectra and are ordered as in listbox. Columns represent parameters in the same order as in parameter table. There are twice as many columns as parameters. Every second column contains errorbar values of the parameter left of it. Copy Fit Results with Area will copy exactly the same table into a clipboard. Copy Fit Results with Heights will copy a similar table into a clipboard, however, this time instead of area and error of area, the program calculates the height of each individual component (function). Note, that this operation might take much longer, since there are many more calculations and function recognition involved.
- Copy Figure. The whole window of LeyLa program is captured as a picture and copied into a clipboard.
Another useful feature for analysing the quality of fits is the Chi2 histogram window. When opened (in the menu go to: Fit->Chi2 histogram) it will show a histogram off all the χ2 values (goodness of fit, sse value). On the y axis the frequency of χ2 values within some narrow range, or the number of spectra with that χ2, is plotted against the intervals of χ2 values. On the right hand-side is a list of spectrum names that have χ2 values above the cutoff. The cutoff value can be set in the editbox above the histogram, or by clicking with the mouse on the white background in the histogram. A gray vertical line will show the cutoff value.
Chi2 histogram window makes it easy to identify spectra that have bad fitting parameters, especially when there are many spectra. If the spectrum is separated to the right from the main group on the histogram, it should be corrected by redoing the fit.
This is a complete tutorial on how to use LeyLa Matlab software. If you have any other question, remarks, comments, or requests please let me know by sending a message below: