Processing a spectrum#
This example shows how to process a spectrum with DataLab:
Read the spectrum from a file
Apply a filter to the spectrum
Extract a region of interest
Fit a model to the spectrum
Save the workspace to a file
First, we open DataLab and read the spectrum from a file.
![../../_images/014.png](../../_images/014.png)
Open the spectrum file with âFile > OpenâŠâ , or with the button in
the toolbar, or by dragging and dropping the file into DataLab (on the panel on
the right).#
Here, we are actually generating the signal from a test data file (using âPlugins > Test data > Load spectrum of paracetamolâ), but the principle is the same.
![../../_images/024.png](../../_images/024.png)
Using the âTest dataâ plugin is a convenient way to generate test data for tutorials, but you can use any file containing a spectrum, such as a spectrum from a real experiment.#
The spectrum is displayed in the main window.
![../../_images/034.png](../../_images/034.png)
The spectrum is a 1D signal, so it is displayed as a curve. The horizontal axis is the energy axis, and the vertical axis is the intensity axis.#
Now, letâs process this spectrum by applying a filter to it. We will use a Wiener filter, which is a filter that can be used to remove noise from a signal, even if this is not absolutely necessary in this case.
![../../_images/044.png](../../_images/044.png)
Open the filter window with âProcessing > Wiener filterâ.#
![../../_images/054.png](../../_images/054.png)
The result of the filter is displayed in the main window.#
If we want to analyze a specific region of the spectrum, we can extract it from the spectrum using the âROI extractionâ feature from the âOperationsâ menu.
![../../_images/064.png](../../_images/064.png)
Open the ROI extraction window with âOperations > ROI extractionâ.#
![../../_images/074.png](../../_images/074.png)
The âRegions of interestâ dialog box is displayed. Click on âAdd ROIâ and resize the horizontal window to select the area. Then, click on âOKâ.#
![../../_images/084.png](../../_images/084.png)
The region of interest is displayed in the main window.#
Letâs try to fit a model to the spectrum. We will use a Gaussian model, which is a model that can be used to fit a peak in a spectrum.
![../../_images/094.png](../../_images/094.png)
Open the model fitting window with âProcessing > Fitting > Gaussian fitâ.#
![../../_images/104.png](../../_images/104.png)
The âGaussian fitâ dialog box is displayed. An automatic fit is performed by default. Click on âOKâ (or eventually try to fit the model manually by adjusting the parameters or the sliders, or try to change the automatic fitting parameters).#
![../../_images/114.png](../../_images/114.png)
The result of the fit is displayed in the main window. Here we selected both the spectrum and the fit in the âSignalsâ panel on the right, so both are displayed in the visualization panel on the left.#
![../../_images/123.png](../../_images/123.png)
We may also select the full spectrum and the fit in the âSignalsâ panel on the right, so that both are displayed in the visualization panel on the left, if this has a sense for the analysis we want to perform. Note that the full spectrum visualization also contains the region of interest we extracted previously.#
To demonstrate another processing feature, we can also try to detrend the spectrum.
![../../_images/133.png](../../_images/133.png)
Execute the âProcessing > Detrendingâ feature.#
![../../_images/142.png](../../_images/142.png)
We choose a linear detrending method, and we click on âOKâ.#
![../../_images/152.png](../../_images/152.png)
The result of the detrending is displayed in the main window (in that specific case, the detrending may not be appropriate, but it is just to demonstrate the feature).#
When analyzing a spectrum, it can be useful to try to identify the peaks in the spectrum. We can do this by fitting a multi-Gaussian model to the spectrum, using the âProcessing > Fitting > Multi-Gaussian fitâ feature.
![../../_images/162.png](../../_images/162.png)
First, a âSignal peak detectionâ dialog box is displayed. We can adjust the the vertical cursor position to select the threshold for the peak detection, as well as the minimum distance between two peaks. Then, we click on âOKâ.#
![../../_images/172.png](../../_images/172.png)
The âMulti-Gaussian fitâ dialog box is displayed. An automatic fit is performed by default. Click on âOKâ (or eventually try to fit the model manually by adjusting the parameters or the sliders, or try to change the automatic fitting parameters).#
![../../_images/182.png](../../_images/182.png)
The result of the fit is displayed in the main window. Here we selected both the spectrum and the fit in the âSignalsâ panel on the right, so both are displayed in the visualization panel on the left.#
We also could have used the âPeak detectionâ feature from the âOperationsâ menu to detect the peaks in the spectrum.
![../../_images/191.png](../../_images/191.png)
Open the âPeak detectionâ window with âOperations > Peak detectionâ.#
![../../_images/201.png](../../_images/201.png)
After having adjusted the parameters of the peak detection dialog (same dialog as the one used for the multi-Gaussian fit), click on âOKâ. Then, we select the âpeak_detectionâ and the original spectrum in the âSignalsâ panel on the right, so that both are displayed in the visualization panel on the left.#
Finally, we can save the workspace to a file. The workspace contains all the signals that were loaded in DataLab, as well as the processing results. It also contains the visualization settings (curve colors, etc.).
![../../_images/211.png](../../_images/211.png)
Save the workspace to a file with âFile > Save to HDF5 fileâŠâ,
or the button in the toolbar.#
If you want to load the workspace again, you can use the âFile > Open HDF5 fileâŠâ
(or the button in the toolbar) to load the whole workspace, or the
âFile > Browse HDF5 fileâŠâ (or the
button in the toolbar) to load
only a selection of data sets from the workspace.