Main Content

Generate MATLAB Code for 1-D Wavelet Packet Denoising and Compression

1-D Wavelet Packet Denoising

You can generate MATLAB® code to reproduce app–based 1-D wavelet packet denoising at the command line. You must perform this operation in the Wavelet Packet 1-D - - Denoising tool. You must first denoise your signal before you can enable the File > Generate MATLAB Code (Denoising Process) operation.

  1. Enter waveletAnalyzer at the MATLAB command prompt.

  2. Select Wavelet Packet 1-D.

  3. At the MATLAB command prompt, type

    load noisbump
    In the *** tool, select File > Import from Workspace > Import Signal. When the Import from Workspace dialog box appears, select the noisbump variable. Click OK to import the data.

  4. Select the db4 wavelet, and set the Level to 4. Accept the default value Shannon for Entropy.

  5. Click Analyze.

  6. Click Denoise.

  7. Under Select thresholding method, accept the default Fixed form thr. (unscaled wn) with the soft radio button enabled.

    Set Select Global Threshold to 2.75.

  8. Click Denoise.

  9. Select File > Generate MATLAB Code (Denoising Process)

The operation generates the following MATLAB code.

function [sigDEN,wptDEN] = func_denoise_wp1d(SIG)
% FUNC_DENOISE_WP1D Saved Denoising Process.
%   SIG: vector of data
%   -------------------
%   sigDEN: vector of denoised data
%   wptDEN: wavelet packet decomposition (wptree object)


% Analysis parameters.
%---------------------
Wav_Nam = 'db4';
Lev_Anal = 4;
Ent_Nam = 'shannon';
Ent_Par = 0;

% Denoising parameters.
%----------------------
% meth = 'sqtwologuwn';
sorh = 's';    % Specified soft or hard thresholding
thrSettings = {sorh,'nobest',2.750000000000000,1};

% Decompose using WPDEC.
%----------------------
wpt = wpdec(SIG,Lev_Anal,Wav_Nam,Ent_Nam,Ent_Par);

% Nodes to merge.
%-----------------
n2m = [];
for j = 1:length(n2m)
    wpt = wpjoin(wpt,n2m(j));
end

% Denoise using WPDENCMP.
%------------------------
[sigDEN,wptDEN] = wpdencmp(wpt,thrSettings{:});

Save func_denoise_wp1d.m in a folder on the MATLAB search path.

Save the denoised signal from the Wavelet Packet 1-D - - Denoising tool as wp_denoisedbump.mat in a folder on the MATLAB search path.

Execute the following code.

load noisbump;
[sigDEN,wptDEN] = func_denoise_wp1d(noisbump);
load wp_denoisedbump;
plot(sigDEN); title('Denoised Signal');
axis([1 1024 min(sigDEN)-1 max(sigDEN+1)]);
norm(sigDEN-wp_denoisedbump,2)