How to specify thresholding for SWT in a loop?
2 views (last 30 days)
Show older comments
Hi all,
I have a nested cell array (cnew) and each cell array contains a time series. I am using SWT denoising -1D in the wavelet analyzer toolbox for denoising. For the first time serise in the 1st cell array (5990x1), I used a db-10 level 8 decomposition for denoising (as shown in the code auto-generated by wavelet analyzer toolbox).
Here
1) I used a soft threshold and clicked "denoise" in the toolbox
2) I accepted the automatic thresholding limits set by the toolbox for coefficients 1, 2, 3, 4 without changing anything
3) I manually set "0" as the thresholding limit for coeffcient 5, 6, 7 ,8
4) Then clicked "denoise" again and auto-generated this code
My question is: How can I do the same thresholding procedure for all the cell arrays in my nested cell array without having to manually open the toolbox every time ?
Note: The length of my time series varies
function [sigDEN,wDEC] = func_denoise_sw1d(SIG)
% FUNC_DENOISE_SW1D Saved Denoising Process.
% SIG: vector of data
% -------------------
% sigDEN: vector of denoised data
% wDEC: stationary wavelet decomposition
% Auto-generated by Wavelet Toolbox on 28-Jul-2019 15:55:45
% Analysis parameters.
%---------------------
wname = 'db10';
level = 8;
% Denoising parameters.
%----------------------
% meth = 'sqtwolog';
% scal_OR_alfa = one;
sorh = 's'; % Specified soft or hard thresholding
thrSettings = {...
[...
1.000000000000000 5888.000000000000000 0.255766629023205; ...
]; ...
[...
1.000000000000000 5888.000000000000000 0.425342655228765; ...
]; ...
[...
1.000000000000000 5888.000000000000000 0.645995128480590; ...
]; ...
[...
1.000000000000000 5888.000000000000000 0.838125150823955; ...
]; ...
[...
1.000000000000000 5888.000000000000000 0.000000000000000; ...
]; ...
[...
1.000000000000000 5888.000000000000000 0.000000000000000; ...
]; ...
[...
1.000000000000000 5888.000000000000000 0.000000000000000; ...
]; ...
[...
1.000000000000000 5888.000000000000000 0.000000000000000; ...
]; ...
};
% Decompose using SWT.
%---------------------
wDEC = swt(SIG,level,wname);
% Denoise.
%---------
len = length(SIG);
for k = 1:level
thr_par = thrSettings{k};
if ~isempty(thr_par)
NB_int = size(thr_par,1);
x = [thr_par(:,1) ; thr_par(NB_int,2)];
x = round(x);
x(x<1) = 1;
x(x>len) = len;
thr = thr_par(:,3);
for j = 1:NB_int
if j==1 , d_beg = 0; else d_beg = 1; end
j_beg = x(j)+d_beg;
j_end = x(j+1);
j_ind = (j_beg:j_end);
wDEC(k,j_ind) = wthresh(wDEC(k,j_ind),sorh,thr(j));
end
end
end
% Reconstruct the denoise signal using ISWT.
%-------------------------------------------
sigDEN = iswt(wDEC,wname);
0 Comments
Answers (1)
Subhadeep Koley
on 9 Aug 2019
Hi, I understand that you are trying to perform the same thresholding procedure (as generated by the wavelet analyzer toolbox) for all the cell arrays in your nested cell array without having to manually open the toolbox every time.
The following code might help you.
denoisedSignal=cell(size(cnew));
for i=1:size(cnew)
SIG=cnew{i,1};
[sigDEN,wDEC] = func_denoise_sw1d(SIG);
denoisedSignal{i,1}=sigDEN;
end
See Also
Categories
Find more on Signal Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!