This section demonstrates the features of multiscale principal
components analysis provided in the Wavelet Toolbox™ software.
The toolbox includes the
and a Wavelet Analyzer app.
This section describes the command-line and app methods, and information
about transferring signal and parameter information between the disk
and the app.
The aim of multiscale PCA is to reconstruct, starting from a multivariate signal and using a simple representation at each resolution level, a simplified multivariate signal. The multiscale principal components generalizes the normal PCA of a multivariate signal represented as a matrix by performing a PCA on the matrices of details of different levels simultaneously. A PCA is also performed on the coarser approximation coefficients matrix in the wavelet domain as well as on the final reconstructed matrix. By selecting the numbers of retained principal components, interesting simplified signals can be reconstructed.
Since you can perform multiscale PCA either from the command line or using the app, this section has subsections covering each method.
This example uses noisy test signals. In this section, you will:
Load a multivariate signal.
Perform a simple multiscale PCA.
Display the original and simplified signals.
Improve the obtained result by retaining less principal components.
Load a multivariate signal by typing at the MATLAB® prompt:
load ex4mwden whos
The data stored in matrix
x comes from two
test signals, Blocks and HeavySine, and from their sum and difference,
to which multivariate Gaussian white noise has been added.
Perform a simple multiscale PCA.
The multiscale PCA combines noncentered PCA on approximations and details in the wavelet domain and a final PCA. At each level, the most significant principal components are selected.
First, set the wavelet parameters:
level= 5; wname = 'sym4';
Then, automatically select the number of retained principal components using Kaiser's rule by typing
npc = 'kais';
Finally, perform multiscale PCA:
[x_sim, qual, npc] = wmspca(x ,level, wname, npc);
Display the original and simplified signals:
kp = 0; for i = 1:4 subplot(4,2,kp+1), plot(x (:,i)); set(gca,'xtick',); axis tight; title(['Original signal ',num2str(i)]) subplot(4,2,kp+2), plot(x_sim(:,i)); set(gca,'xtick',); axis tight; title(['Simplified signal ',num2str(i)]) kp = kp + 2; end
The results from a compression perspective are good. The percentages reflecting the quality of column reconstructions given by the relative mean square errors are close to 100%.
qual qual = 98.0545 93.2807 97.1172 98.8603
Improve the first result by retaining fewer principal components.
The results can be improved by suppressing noise, because the details at levels 1 to 3 are composed essentially of noise with small contributions from the signal. Removing the noise leads to a crude, but large, denoising effect.
The output argument npc contains the numbers of retained principal components selected by Kaiser's rule:
npc npc = 1 1 1 1 1 2 2
d from 1 to 5,
the number of retained noncentered principal components (PCs) for
details at level d. The number of retained noncentered PCs for approximations
at level 5 is
the number of retained PCs for final PCA after wavelet reconstruction.
As expected, the rule keeps two principal components, both for the
PCA approximations and the final PCA, but one principal component
is kept for details at each level.
To suppress the details at levels 1 to 3, update the
npc(1:3) = zeros(1,3); npc npc = 0 0 0 1 1 2 2
Then, perform multiscale PCA again:
[x_sim, qual, npc] = wmspca(x, level, wname, npc);
Display the original and final simplified signals:
kp = 0; for i = 1:4 subplot(4,2,kp+1), plot(x (:,i)); set(gca,'xtick',); axis tight; title(['Original signal ',num2str(i)]); set(gca,'xtick',); axis tight; subplot(4,2,kp+2), plot(x_sim(:,i)); set(gca,'xtick',); axis tight; title(['Simplified signal ',num2str(i)]) kp = kp + 2; end
As shown, the results are improved.
This section explores multiscale PCA using the Wavelet Analyzer app.
Open the Wavelet Analyzer app by typing
the command line.
Click Multiscale Princ. Comp. Analysis to open the Multiscale Principal Components Analysis tool in the app.
Select File > Load Signals.
In the Select dialog box, select
ex4mwden.mat from the MATLAB folder
Click Open to load the multivariate signal into the app. The signal is a matrix containing four columns, where each column is a signal to be simplified.
These signals are noisy versions from simple combinations of the two original signals, Blocks and HeavySine and their sum and difference, each with added multivariate Gaussian white noise.
Perform a wavelet decomposition and diagonalize each coefficients matrix.
Use the default values for the Wavelet, the DWT Extension Mode, and the decomposition Level, and then click Decompose and Diagonalize. The tool displays the wavelet approximation and detail coefficients of the decomposition of each signal in the original basis.
To get more information about the new bases allowed for performing a PCA for each scale, click More on Adapted Basis. A new figure displays the corresponding eigenvectors and eigenvalues for the matrix of the detail coefficients at level 1.
You can change the level or select the coarser approximations or the reconstructed matrix to investigate the different bases. When you finish, click Close.
Perform a simple multiscale PCA.
The initial values for PCA lead to retaining all the components.
Kaiser from the Provide
default using drop-down list, and click Apply.
The results are good from a compression perspective.
Improve the obtained result by retaining fewer principal components.
The results can be improved by suppressing the noise, because the details at levels 1 to 3 are composed essentially of noise with small contributions from the signal, as you can see by careful inspection of the detail coefficients. Removing the noise leads to a crude, but large, denoising effect.
For D1, D2 and D3, select
0 as the Nb. of non-centered PC and click Apply.
The results are better than those previously obtained. The first signal, which is irregular, is still correctly recovered, while the second signal, which is more regular, is denoised better after this second stage of PCA. You can get more information by clicking Residuals.
The Multiscale Principal Components Analysis tool lets you save the simplified signals to disk. The toolbox creates a MAT-file in the current folder with a name of your choice.
To save the simplified signals from the previous section:
Select File > Save Simplified Signals.
Select Save Simplified Signals and Parameters. A dialog box appears that lets you specify a folder and file name for storing the signal.
Type the name
click OK to save the data.
Load the variables into your workspace:
load s_ex4mwden whos
The simplified signals are in matrix
parameters of multiscale PCA are available in
PCA_Params PCA_Params = 1x7 struct array with fields: pc variances npc
PCA_Params is a structure array of length
the maximum decomposition level
d=5) such that
the matrix of principal components. The columns are stored in descending
order of the variances.
the principal component variances vector, and
the vector of selected numbers of retained principal components.