Share Results Using Signal Multiresolution Analyzer
This example shows how to use Signal Multiresolution Analyzer to generate a script to recreate a signal decomposition in your workspace. This example also shows how to modify a copy ot a decomposition.
Load the Kobe earthquake data into your workspace. The data are seismograph measurements (vertical acceleration in ) recorded at Tasmania University, Hobart, Australia, on 16 January 1995, beginning at 20:56:51 (GMT) and continuing for 51 minutes at one second intervals.
load kobe
Open Signal Multiresolution Analyzer and import the earthquake data into the app. By default, the app creates a four-level MODWTMRA decomposition of the signal called kobe1
using the modwt
and modwtmra
functions with default settings. To show plots with respect to time and express frequencies in Hz, click the Sample Rate radio button in the Signal Multiresolution Analyzer tab.
Duplicate Decomposition
Create a new six-level decomposition using the order 4 Coiflet. In the Signal Multiresolution Analyzer tab, click Duplicate in the toolstrip. Since kobe1
is the currently selected item in Decomposed Signals, a duplicate of the first decomposition is created. The duplicate is called kobe1Copy
. The plots in Reconstructions are updated to include the new decomposition. Except for the color, the duplicate is identical with the first decomposition. You can change the name of the duplicate by right-clicking on the name in Decomposed Signals.
In the MODWT tab, change the settings in the toolstrip to the following values and then click Decompose.
Wavelet:
coif
Number: 4
Level: 6
In Level Selection, note which components of the decomposition are included in the reconstruction: the approximation and the level 5 and level 6 details.
Level 4 has approximately 60% of the total energy. Remove levels 5 and 6 from the reconstruction, and include level 4. Show only the approximation and level 4 details in the Decomposition pane. To approximately align the decomposition with the reconstruction, drag the Decomposition pane beneath the Reconstructions pane.
Generate MODWT Script
You have three export options. You can export the reconstruction or the entire decomposition of the selected decomposed signal to your workspace, or you can export a MATLAB® script to recreate the decomposition in your workspace. To generate a script, in the Signal Multiresolution Analyzer tab click Export > Generate MATLAB Script.
An untitled script opens in your editor with the following executable code. The true-false values in levelForReconstruction
correspond to which Include
boxes are checked in Level Selection. You can save the script as is, or modify it to apply the same decomposition settings to other signals. Run the code.
% Logical array for selecting reconstruction elements levelForReconstruction = [false,false,false,true,false,false,true]; % Perform the decomposition using modwt wt = modwt(kobe,'coif4',6); % Construct MRA matrix using modwtmra mra = modwtmra(wt,'coif4'); % Sum down the rows of the selected multiresolution signals kobe1Copy = sum(mra(levelForReconstruction,:),1);
Plot the original signal and reconstruction. Except for possibly the colors, the plot will match the kobe1Copy
reconstruction shown in the app.
t = 0:numel(kobe)-1; plot(t,kobe) grid on hold on plot(t,kobe1Copy,LineWidth=2) xlabel("Seconds") title("Reconstruction") legend("Original","Reconstruction",Location="northwest") axis tight hold off
Generate EMD Script
Add the EMD decomposition of the Kobe data by clicking Add ▼ and selecting EMD in the Signal Multiresolution Analyzer tab. The name of the decomposed signal in the Decomposed Signals pane is kobe3
. By default, the reconstruction consists only of the residual. The decomposition is obtained by using the emd
function with default settings.
Generate a script that creates the EMD decomposition by clicking Export > Generate MATLAB Script. An untitled script opens in your editor with the following executable code. Run the code.
% Logical array for selecting reconstruction elements levelForReconstruction = [false,false,false,false,false,true]; % Perform the decomposition using EMD [imf,residual,info] = emd(kobe, ... SiftRelativeTolerance=0.2, ... SiftMaxIterations=100, ... MaxNumIMF=5, ... MaxNumExtrema=1, ... MaxEnergyRatio=20, ... Interpolation='spline'); % Construct MRA matrix by appending IMFs and residual mra = [imf residual].'; % Sum down the rows of the selected multiresolution signals kobe3 = sum(mra(levelForReconstruction,:),1);
Compare the reconstruction kobe3
with the original signal. In this case, the reconstruction only consists of the residual.
plot(t,kobe) grid on hold on plot(t,kobe3,LineWidth=2) xlabel("Seconds") title("Reconstruction") legend("Original","Reconstruction",Location="northwest") axis tight hold off