This example shows how to use the Wavelet Signal Denoiser app to denoise a real-valued 1-D signal. You can create and compare multiple versions of a denoised signal with the app and export the desired denoised signal to your MATLAB® workspace. To reproduce the denoised signal in your workspace, or to apply the same denoising parameters to other data, you can generate and edit a MATLAB script. This example illustrates one possible workflow.
Load data into the MATLAB workspace. The
.mat file contains a clean version and a noisy version of a signal. Plot both versions of the signal.
load fdata plot(fNoisy,'b-') hold on plot(fClean,'r-','LineWidth',2) legend('Noisy Signal','Clean Signal') hold off grid on
Open the Wavelet Signal Denoiser app. From the MATLAB Toolstrip, open the Apps tab and under Signal Processing and Communications, click Wavelet Signal Denoiser. You can also start the app by typing
waveletSignalDenoiser at the MATLAB command prompt.
Load the noisy signal from the workspace into the app by clicking Import in the toolstrip. From the list of workspace variables that can be loaded into the app, select
fNoisy and click Import.
The app imports the noisy signal and immediately denoises it using default parameters.
Examine the fNoisy plot. The app plots the original signal,
fNoisy, the denoised signal,
fNoisy1, and the coarse scale approximation of the signal,
1. The Denoised Signals pane lists all versions of the denoised signal. The list currently contains only the signal that the app created using a default name,
You can change the default name by right-clicking it, choosing Rename from the pop-up menu, entering the new name in the dialog box, and pressing the Enter key.
You can delete a denoised signal by right-clicking its name and choosing Delete from the pop-up menu. You can also delete the selected denoised signal by clicking Delete in the toolstrip.
2. The Current Wavelet Parameters pane lists the denoising parameters applied to create
3. Zoom and pan a region of interest. First, place the cursor over the plot to reveal a floating palette. Then select the desired action from the palette.
When you select to either zoom in or out, the mouse wheel controls the zoom.
4. Toggle what signals are visible in the Denoised Signals plot by:
Clicking Signals ▼ in the toolstrip and using the drop-down menu to toggle the visibility of the original and denoised signal plots.
Clicking individual signals in the plot legend.
5. Examine the Coefficients plot.
The coefficients in red are used to reconstruct the denoised signal. The Current Wavelet Parameters pane indicates that a 9-level wavelet decomposition was used to denoise the signal.
Zoom and pan a region of interest. First, place the cursor over the plot to reveal a floating palette. Then select the desired action from the palette.
When you select to either zoom in or out, the mouse wheel controls the zoom and not the scrollbar.
When you zoom in, zoom out, or pan in the
D1 coefficients level, the zoom is applied to all levels.
Click the Wavelet tab. Use this toolstrip to adjust and apply denoising parameters for the selected denoised signal.
The values listed are the parameters used to create the denoised signal,
fNoisy1. To modify the values of these settings, working from left to right in the toolstrip:
1. In the Wavelet dropdown menu, choose the Daubechies wavelet family,
db. Because of this action:
The Number dropdown field changes to
1. Change the value to
In the status bar, text appears in the Denoised Signals plot, stating that there are pending wavelet parameter changes. This text appears whenever you have any pending changes to a signal. The text in the status bar disappears when you either apply the changes by using the Denoise button, or navigate away from the signal to another signal.
2. From the Method dropdown menu, select
3. To define a 10-level wavelet decomposition, change the value of Level to
4. By changing the Method to
Universal Threshold, the Rule setting changed automatically from
Soft. Change the setting to
5. Click Level-Dependent.
6. Apply the new values for these settings by clicking Denoise.
The Current Wavelet Parameters pane updates with the new parameters used to denoise the signal, and the app replots the denoised signal,
Note: All parameters are contextual. Possible values for one parameter can depend on the currently selected value of another parameter. You cannot make an incompatible selection. For example, when the denoising method is FDR, there is only possible thresholding rule: hard. In this instance, no other values are listed in the Rule dropdown menu.
If you like a particular denoised signal but want to explore more denoising parameters, you can duplicate it. You can then modify the parameters for the duplicate, without losing the original parameters.
1. From the Denoised Signals pane, select
fNoisy1. Then on the toolstrip, from the Signal Denoiser tab, click Duplicate.
The duplicate signal,
fNoisy1Copy, appears highlighted in Denoised Signals.
The denoising parameters for the duplicate are listed in Current Wavelet Parameters.
The duplicate is plotted as a thick line in the Denoised Signals plot. The plot legend updates to include the duplicate.
2. On the Wavelet tab, change the Level to
2, and then click Denoise. The app denoises the signal using a two-level wavelet decomposition. In addition, the app:
Recalculates and plots the approximation for the duplicate.
Updates the Coefficients plot to show the levels for the duplicate.
fNoisy1Copy is highlighted, its approximation is plotted. The app always plots the approximation for the currently selected denoised signal. You can demonstrate this behavior as follows. In the plot legend, click
fNoisy1Copy. The names of both denoised signals fade, and the two signals are no longer plotted. Only the original signal and approximation plots are visible.
The dashed line in the plot represents the approximation. Because
fNoisy1Copy is highlighted in the Denoised Signals list, the approximation plotted is the result of a two-level wavelet decomposition. The approximation is relatively noisy. Now select
fNoisy1 in the list. The approximation of a 10-level wavelet decomposition is different.
You can always return to using the original default parameters by adding a new denoised signal. From the toolstrip, on the Signal Denoiser tab, click Add.
The added denoised signal,
fNoisy3, appears highlighted in the Denoised Signals list. The default denoising parameters are listed in Current Wavelet Parameters.
The new denoised signal is plotted as a thick line. The approximation is calculated and plotted as well. The plot legend updates to include
If you want to apply the same denoising parameters to other data, you can use the app to generate a script that reproduces the selected denoised signal. You can then modify and save the script for your own purposes. To do further analysis, you can export a denoised signal to your workspace.
fNoisy3 in Denoised Signals. On the Signal Denoiser tab of the toolstrip, from the Export ▼ menu, select
Generate MATLAB Script. An untitled script opens in your MATLAB Editor with the following executable code:
fNoisy3 = wdenoise(fNoisy,9, ... 'Wavelet', 'sym4', ... 'DenoisingMethod', 'Bayes', ... 'ThresholdRule', 'Median', ... 'NoiseEstimate', 'LevelIndependent');
wdenoise input arguments are populated with the values used to create
fNoisy3. Save the script and then run. This will create the variable
fNoisy3 in your workspace.
Load the file
fdataTS. The file contains noisy data of 100 time series. Each time series has 4096 data points. The data is contained in a type
TimeTable variable called
To apply the denoising parameters to
fdataTS, edit the script by replacing
fdataTSclean. Then run the script.
fdataTSclean = wdenoise(fdataTS,9, ... 'Wavelet', 'sym4', ... 'DenoisingMethod', 'Bayes', ... 'ThresholdRule', 'Median', ... 'NoiseEstimate', 'LevelIndependent');
Compare the 15th noisy time series with its denoised version.
subplot(2,1,1) plot(fdataTS.Time,fdataTS.fTS15) title('Original Time Series') grid on subplot(2,1,2) plot(fdataTSclean.Time,fdataTSclean.fTS15) title('Denoised Time Series') grid on
fNoisy3 in Denoised Signals. Then on the toolstrip, from the Signal Denoiser tab, click the green check mark on Export ▼. Since
fNoisy3 already exists in your workspace, you can force the export and overwrite the workspace variable. Alternatively, you can cancel the export, rename either the denoised signal in the app or the workspace variable, and export again. Text appears in the status bar appears confirming the signal is exported. Selecting a different denoised signal or importing a new signal will clear the text from the status bar.
Because you have the clean signal in your workspace, calculate the sign-to-noise ratio of the denoised signal.
snrWavelet = -20*log10(norm(abs(fClean-fNoisy3))/norm(fClean))
snrWavelet = 35.9623
If you have Signal Processing Toolbox™, denoise the signal using a moving average filter and Savitzky-Golay filter and compute the SNR of each denoised signal.
fmv = smoothdata(fNoisy,'movmean',25); snrMovingAverage = -20*log10(norm(abs(fClean-fmv))/norm(fClean))
snrMovingAverage = 26.0040
fsg = smoothdata(fNoisy,'sgolay',25); snrSavitskyGolay = -20*log10(norm(abs(fClean-fsg))/norm(fClean))
snrSavitskyGolay = 28.8932
You achieve superior results denoising with the