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
DataLab menus change depending on the context. Since we are going to work with a spectrum, a 1D signal, we need to select the Signal Panel before proceeding.
In a typical workflow, we would open DataLab and read the spectrum from a file using
âFile > OpenâŠâ, the button in the toolbar, or by dragging and
dropping the file into the panel on the right. However, for this tutorial,
we will use the âPlugins > Test data > Load spectrum of paracetamolâ feature to
generate a test spectrum, which is convenient for demonstration purposes.
The âFile > OpenâŠâ menu to open a spectrum file.#
The âPlugins > Test data > Load spectrum of paracetamolâ plugin to generate the test spectrum for this tutorial.#
Once opened, the spectrum is displayed in the main window. It 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.
The spectrum displayed on the âSignal Viewâ panel.#
The signal is quite clean. However, to demonstrate DataLabâs filtering capabilities, we will apply a Wiener filter to reduce any residual noise while preserving the spectral features. This is available under âProcessing > Noise Reduction > Wiener filterâ.
The âProcessing > Noise Reduction > Wiener filterâ menu option.#
The result displayed in the main window.#
Letâs focus our analysis on one of the peaks of interest. To do that, we define a region of interest (ROI) around the feature we want to analyze and use the âROI > ExtractâŠâ menu to extract it. The âRegions of interestâ dialog box will be displayed. Select an area and click âOKâ. A confirmation window will appearâclick âYesâ to extract the region of interest. A new signal containing the ROI will be created and displayed in the main window.
The âOperations > ROI extractionâ menu.#
The âRegions of interestâ dialog box displayed.#
The region of interest displayed in the main window.#
Open the model fitting window with âProcessing > Fitting > Gaussian fitâ.#
The result of the fit displayed in the main window.#
Both the full spectrum and the fit are selected in the âSignalsâ panel, so that both are displayed in the visualization panel on the left. This allows for easy visual comparison if needed for the analysis.#
Linear detrending#
After fitting the main peak, we may want to remove any baseline drift present in the entire spectrum. The detrending function in DataLab performs a linear fit across the entire signal, including the peaks. In our signal, the peaks occupy a large portion of the data, which is acceptable for signals where peaks are symmetrically distributed around the center with similar amplitudes. However, this is not the case here, so we cannot expect this function to work well. Nevertheless, this example illustrates how DataLab functions can be combined to perform more advanced analyses.
To visualize the limitation mentioned above, we will apply the detrending function directly to the filtered signal. Itâs important to remember that we previously set a ROI on the signal to focus on the main peak. We need to remove this ROI constraint to perform detrending on the full signal. To execute the detrending, we use âProcessing > Detrendingâ, choose the linear detrending method, and click âOKâ. The result will be displayed in the main window.
The âProcessing > Detrendingâ feature.#
We choose a linear detrending method, and we click on âOKâ.#
The result of the detrending displayed in the main window.#
Comparing the filtered and detrended signals shows, as expected, that the detrending function does not work well on this signal. As explained earlier, this is because the algorithm performs a linear fit across the entire signal, including the peaks. The effect is clearly visible in the plot: the higher peaks on the left start at an intensity value lower than those on the right after detrending, and all peaks have a baseline below zero.
Improved detrending with peak exclusion#
To overcome the detrending functionâs limitation, we can draw inspiration from the behavior of the detrended signal. Weâve already identified the problem: the linear fit includes both the baseline and the peaks.
For better detrending, we can first exclude the peaks and then perform a linear fit only on the non-peak regions. We can reasonably expect this approach to provide a more accurate baseline estimation and a better detrended signal.
This is illustrated in the following steps:
We select the regions corresponding to the regions without peaks.#
A linear fit is performed only on the selected regions.#
The linear baseline obtained from the fit is shown.#
We delete the rois to apply the detrending on the whole signal.#
We use the âdifferenceâ operation to subtract the baseline from the original signal.#
We select the linear baseline to perform the subtraction.#
The resulting detrended signal is shown, now with a correct baseline.#
Automatic peak detection#
We can use DataLabâs âMulti-Gaussian fitâ function to automatically identify and fit multiple peaks in the spectrum by selecting âProcessing > Fitting > Multi-Gaussian fitâ from the menu.
First, the âSignal peak detectionâ dialog box appears. You can adjust the vertical cursor position to set the threshold for peak detection and specify the minimum distance between peaks. Then click âOKâ.#
The âMulti-Gaussian fitâ dialog box appears. An automatic fit is performed by default. Click âOKâ (or optionally adjust the parameters manually using the sliders, or modify the automatic fitting parameters).#
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.#
Alternatively, we could use the âPeak detectionâ feature from the âAnalysisâ menu to detect peaks in the spectrum. This is the first step of the âMulti-Gaussian fitâ function and can be used independently to detect peaks without performing a fit, creating a signal with a delta function at each detected peak position.
Open the âPeak detectionâ window with âAnalysis > Peak detectionâ.#
After adjusting the peak detection parameters (using the same dialog as for the multi-Gaussian fit), click âOKâ. Then select both the âpeak_detectionâ result and the original spectrum in the âSignalsâ panel to display them together in the visualization panel on the left.#
Saving the workspace#
Finally, we can save the workspace to a file. The workspace contains all signals loaded or created in DataLab, along with processing results and visualization settings (such as curve colors).
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.