Instrumentation & Measurement Magazine 24-4 - 43

The eigenvectors and eigenvalues introduced in (1) can be
obtained from the diagonalization of the covariance matrix
calculated for the original data matrix X. This procedure can be
carried out using any programming language allowing matrix
calculation; in this paper, a hands-on example is provided using
the free Python language. Actually, in the last decades, this
programming language has gained increasing consideration
in the scientific world thanks to its easy syntax and to its numerous
standard and external libraries. For example, PCA can
be easily implemented using few lines of code thanks to the
open-source Scikit-learn library, which provides all the necessary
operations to perform needed calculations. Anyway,
before moving to this step, first it is necessary to perform some
preliminary processing to the acquired data matrix in order to
obtain meaningful results from PCA. Actually, this chemometric
technique is deeply influenced by measurement noise and
by the signal magnitude, so these two factors should be minimized
or made similar for all samples before computing the
principal components of the PCA model. In the next section,
these pre-processing operations will be described in detail,
presenting the example of spectroscopic measurements.
Pre-Processing
Pre-processing operations can be divided into four steps: 1)
interval selection, 2) baseline removal, 3) smoothing and 4)
normalization.
Step 1: Interval Selection
Not all measurements carry useful information, so the first
step is usually to identify the meaningful data. When dealing
with spectroscopic measurements, the whole spectrum is
often not worth attention, but only some ranges where characteristic
peaks of the analyzed compounds are present. Because
of this, generally the best choice is to limit the processed dataset
to this part of the spectrum and to linearly interpolate it to
generate a set number of data points. This way it is possible to
avoid building a model influenced by not relevant spectral regions,
and all samples will be constituted by the same abscissa
coordinates.
Step 2: Baseline Removal
The baseline of the acquired spectrum is removed. Actually,
it is not uncommon to have spectra characterized by an offset
or by a sloping line due to instrument drift or side phenomena
occurring when performing the measurement. One of the
possibilities is to compute the baseline by means of symmetric
least square smoothing, as described in [7]. This operation can
be easily performed in Python, taking advantage of the Scipy
library that allows the user to perform matrix operations and
solve matrix expressions [8]. After computing the baseline,
this background can be subtracted from the original spectrum.
Step 3: Smoothing
The signal-to-noise ratio (SNR) can be improved by applying
a smoothing filter to the original data. One of the most popular
filters is the so-called Savitzky-Golay filter, which is based
June 2021
on local least-squares polynomial approximation [9]. It can be
applied to the analyzed dataset using the savgol_filter function
from Scipy library. Input parameters for this function are the
window length and the polynomial order for the fitting curve.
They should be carefully chosen in order to avoid any oversmoothing,
that would lead to loss of information in the final
data, as one of the side effects of any smoothing filter is to reduce
peak height, with possible elimination of small peaks or
shoulders. Because of this, input parameters for Savitzky-Golay
filter should be tailored to each specific application, but a
general rule of thumb often found in many publications is to
use a window length of 15 points and a 2nd
order polynomial.
Step 4: Normalization
The normalization can be carried out by means of the Standard
Normal Variate Transformation, i.e., using the following expression
for each measurement point:
y
yý

SNV
std

(2)
where ySNV is the variable value after transformation, y is the
original variable, ý is the mean value in the original spectrum
and std is the standard deviation [10]. In this way, all spectra
composing the dataset will be mean-centered and scaled to
unit variance.
The effect of all pre-processing operations can be observed
in Fig. 1. The reported spectra are acquired analyzing
copper sulphate and copper hydroxychloride crystals using
Raman spectroscopy. This spectroscopic technique probes
the sample under investigation using a laser radiation having
wavelength either in the visible or in the infra-red range.
Vibrational modes at the molecular level can cause inelastic
scattering in the analyzed material, which would result in the
emission of photons with different energies (Raman scattering).
This signal is finally collected by a detector to compose
the Raman spectrum of the sample. The great advantage
of this technique is the possibility to identify specific compounds,
because each bond in the compound generates its
characteristic peaks, but at the same time spectra interpretation
is often not straightforward, due to possible presence of
a large number of peaks in the acquired spectrum. In the two
examples shown in Fig. 1, only wavelengths between 200 cm−1
and 1200 cm−1
are selected (step 1), as this range is the most important
for inorganic compounds. Actually, even if additional
peaks can be found in the region between 3000 cm−1
and 3500
cm−1
(Fig. 1b) associated to the OH bond stretching, the first
part of the spectrum is generally considered as the 'fingerprint
region' for identification of minerals. After selection of
the interval of interest, the large background signal due to the
fluorescence emission is removed (step 2), Savitzky-Golay filter
is applied to improve the signal-to-noise ratio (step 3) and
Standard Normal Variate Transformation is applied to normalize
the spectra to unit variance (step 4). In this example,
SNR (computed as the ratio between the highest peak and the
baseline noise) improved by about 7% in both spectra. Results
of all pre-processing are shown at the bottom of the figure,
IEEE Instrumentation & Measurement Magazine
43

Instrumentation & Measurement Magazine 24-4

Table of Contents for the Digital Edition of Instrumentation & Measurement Magazine 24-4

No label
Instrumentation & Measurement Magazine 24-4 - No label
Instrumentation & Measurement Magazine 24-4 - Cover2
Instrumentation & Measurement Magazine 24-4 - 1
Instrumentation & Measurement Magazine 24-4 - 2
Instrumentation & Measurement Magazine 24-4 - 3
Instrumentation & Measurement Magazine 24-4 - 4
Instrumentation & Measurement Magazine 24-4 - 5
Instrumentation & Measurement Magazine 24-4 - 6
Instrumentation & Measurement Magazine 24-4 - 7
Instrumentation & Measurement Magazine 24-4 - 8
Instrumentation & Measurement Magazine 24-4 - 9
Instrumentation & Measurement Magazine 24-4 - 10
Instrumentation & Measurement Magazine 24-4 - 11
Instrumentation & Measurement Magazine 24-4 - 12
Instrumentation & Measurement Magazine 24-4 - 13
Instrumentation & Measurement Magazine 24-4 - 14
Instrumentation & Measurement Magazine 24-4 - 15
Instrumentation & Measurement Magazine 24-4 - 16
Instrumentation & Measurement Magazine 24-4 - 17
Instrumentation & Measurement Magazine 24-4 - 18
Instrumentation & Measurement Magazine 24-4 - 19
Instrumentation & Measurement Magazine 24-4 - 20
Instrumentation & Measurement Magazine 24-4 - 21
Instrumentation & Measurement Magazine 24-4 - 22
Instrumentation & Measurement Magazine 24-4 - 23
Instrumentation & Measurement Magazine 24-4 - 24
Instrumentation & Measurement Magazine 24-4 - 25
Instrumentation & Measurement Magazine 24-4 - 26
Instrumentation & Measurement Magazine 24-4 - 27
Instrumentation & Measurement Magazine 24-4 - 28
Instrumentation & Measurement Magazine 24-4 - 29
Instrumentation & Measurement Magazine 24-4 - 30
Instrumentation & Measurement Magazine 24-4 - 31
Instrumentation & Measurement Magazine 24-4 - 32
Instrumentation & Measurement Magazine 24-4 - 33
Instrumentation & Measurement Magazine 24-4 - 34
Instrumentation & Measurement Magazine 24-4 - 35
Instrumentation & Measurement Magazine 24-4 - 36
Instrumentation & Measurement Magazine 24-4 - 37
Instrumentation & Measurement Magazine 24-4 - 38
Instrumentation & Measurement Magazine 24-4 - 39
Instrumentation & Measurement Magazine 24-4 - 40
Instrumentation & Measurement Magazine 24-4 - 41
Instrumentation & Measurement Magazine 24-4 - 42
Instrumentation & Measurement Magazine 24-4 - 43
Instrumentation & Measurement Magazine 24-4 - 44
Instrumentation & Measurement Magazine 24-4 - 45
Instrumentation & Measurement Magazine 24-4 - 46
Instrumentation & Measurement Magazine 24-4 - 47
Instrumentation & Measurement Magazine 24-4 - 48
Instrumentation & Measurement Magazine 24-4 - 49
Instrumentation & Measurement Magazine 24-4 - 50
Instrumentation & Measurement Magazine 24-4 - 51
Instrumentation & Measurement Magazine 24-4 - 52
Instrumentation & Measurement Magazine 24-4 - 53
Instrumentation & Measurement Magazine 24-4 - 54
Instrumentation & Measurement Magazine 24-4 - 55
Instrumentation & Measurement Magazine 24-4 - 56
Instrumentation & Measurement Magazine 24-4 - 57
Instrumentation & Measurement Magazine 24-4 - 58
Instrumentation & Measurement Magazine 24-4 - 59
Instrumentation & Measurement Magazine 24-4 - 60
Instrumentation & Measurement Magazine 24-4 - 61
Instrumentation & Measurement Magazine 24-4 - 62
Instrumentation & Measurement Magazine 24-4 - 63
Instrumentation & Measurement Magazine 24-4 - 64
Instrumentation & Measurement Magazine 24-4 - 65
Instrumentation & Measurement Magazine 24-4 - 66
Instrumentation & Measurement Magazine 24-4 - 67
Instrumentation & Measurement Magazine 24-4 - 68
Instrumentation & Measurement Magazine 24-4 - 69
Instrumentation & Measurement Magazine 24-4 - 70
Instrumentation & Measurement Magazine 24-4 - 71
Instrumentation & Measurement Magazine 24-4 - 72
Instrumentation & Measurement Magazine 24-4 - 73
Instrumentation & Measurement Magazine 24-4 - 74
Instrumentation & Measurement Magazine 24-4 - 75
Instrumentation & Measurement Magazine 24-4 - 76
Instrumentation & Measurement Magazine 24-4 - 77
Instrumentation & Measurement Magazine 24-4 - 78
Instrumentation & Measurement Magazine 24-4 - 79
Instrumentation & Measurement Magazine 24-4 - 80
Instrumentation & Measurement Magazine 24-4 - 81
Instrumentation & Measurement Magazine 24-4 - 82
Instrumentation & Measurement Magazine 24-4 - 83
Instrumentation & Measurement Magazine 24-4 - 84
Instrumentation & Measurement Magazine 24-4 - 85
Instrumentation & Measurement Magazine 24-4 - 86
Instrumentation & Measurement Magazine 24-4 - 87
Instrumentation & Measurement Magazine 24-4 - 88
Instrumentation & Measurement Magazine 24-4 - 89
Instrumentation & Measurement Magazine 24-4 - 90
Instrumentation & Measurement Magazine 24-4 - 91
Instrumentation & Measurement Magazine 24-4 - 92
Instrumentation & Measurement Magazine 24-4 - 93
Instrumentation & Measurement Magazine 24-4 - 94
Instrumentation & Measurement Magazine 24-4 - 95
Instrumentation & Measurement Magazine 24-4 - 96
Instrumentation & Measurement Magazine 24-4 - 97
Instrumentation & Measurement Magazine 24-4 - 98
Instrumentation & Measurement Magazine 24-4 - 99
Instrumentation & Measurement Magazine 24-4 - 100
Instrumentation & Measurement Magazine 24-4 - 101
Instrumentation & Measurement Magazine 24-4 - 102
Instrumentation & Measurement Magazine 24-4 - 103
Instrumentation & Measurement Magazine 24-4 - 104
Instrumentation & Measurement Magazine 24-4 - 105
Instrumentation & Measurement Magazine 24-4 - 106
Instrumentation & Measurement Magazine 24-4 - 107
Instrumentation & Measurement Magazine 24-4 - 108
Instrumentation & Measurement Magazine 24-4 - 109
Instrumentation & Measurement Magazine 24-4 - 110
Instrumentation & Measurement Magazine 24-4 - 111
Instrumentation & Measurement Magazine 24-4 - 112
Instrumentation & Measurement Magazine 24-4 - 113
Instrumentation & Measurement Magazine 24-4 - 114
Instrumentation & Measurement Magazine 24-4 - 115
Instrumentation & Measurement Magazine 24-4 - 116
Instrumentation & Measurement Magazine 24-4 - 117
Instrumentation & Measurement Magazine 24-4 - 118
Instrumentation & Measurement Magazine 24-4 - 119
Instrumentation & Measurement Magazine 24-4 - 120
Instrumentation & Measurement Magazine 24-4 - Cover3
Instrumentation & Measurement Magazine 24-4 - Cover4
https://www.nxtbook.com/allen/iamm/24-6
https://www.nxtbook.com/allen/iamm/24-5
https://www.nxtbook.com/allen/iamm/24-4
https://www.nxtbook.com/allen/iamm/24-3
https://www.nxtbook.com/allen/iamm/24-2
https://www.nxtbook.com/allen/iamm/24-1
https://www.nxtbook.com/allen/iamm/23-9
https://www.nxtbook.com/allen/iamm/23-8
https://www.nxtbook.com/allen/iamm/23-6
https://www.nxtbook.com/allen/iamm/23-5
https://www.nxtbook.com/allen/iamm/23-2
https://www.nxtbook.com/allen/iamm/23-3
https://www.nxtbook.com/allen/iamm/23-4
https://www.nxtbookmedia.com