How to adjust the length of each cell array in a nested cell array for SWT Denoising?

Hi all,
I have a nested cell array c (12600,1). Each cell array contains time series with varying length. I want to denoise each of these time series using a db-10 wavelet with 8 levels of decomposition using SWT denoising-1D in the Wavelet Analyzer toolbox.
SWT denoising requires that for 8 levels of decomposition, the length of the input time series should be a multiple of 2^8 (i.e 256). That is, the length of my time series should be multiples of 256 ( 256, 512,768 etc...). So for all the cell arrays, I want to alter the length of the time series to be muliples of 256 by removing some data points in the time series. For ex: if the length of time series is 6000x1, I want to make it to 5888x1 by removing data points and I want to do this for all cell arrays in the nested cell array.
How do I do this?
Thanks,
P.S: I tried using the signal extension toolbox for this case, but the additional data points added to the time series altered my analysis results. Hence I rather remove data points from my time series (shorten) than add additional artificial data points (extend) to the length of time series.
Capture.PNG

 Risposta accettata

I am not certain how you are doing the denoising. However getting the vectors to the appropriate lengths is straightforward.
Example:
V = rand(5998,1); % Create Vector
ExtraLength = rem(numel(V), 256); % Length Beyond Integer Multiples Of 256
V1 = V(1 : numel(V)-ExtraLength); % First Vector For Denoising
V2 = V(ExtraLength+1 : end); % Second Vector For Denoising
This will ‘trim’ ‘V’, the first (‘V1’) removing elements from the end, the second (‘V2’) from the beginning. Ideally, you can denoise your entire signal by denoising both, then recombine (concatenate) the end of the second with the first to have a denoised version of the entire signal:
DV1 = ... ; % Denoised ‘V1’
DV2 = ... ; % Denoised ‘V1’
DV = [DV1, DV2(numel(V2)-ExtraLength+1 : end)]; % Denoised Vector
If I remember correctly, the denoised vectors are row vectors (not column vectors as were your original vectors), so be careful in creating ‘DV’ to concatenate them correctly.
I tested parts of this but not all of it, so I am presenting this as UNTESTED CODE.

10 Commenti

Thank you so much for your answer. I tried it and it does work perfectly for vectors.
For my case, I wrote the following code (based on your code) using for loop and I am having trouble getting the correct answer. I'm getting the error "Index exceeds the number of array elements".Please let me know where I am going wrong.
for i =1:numel(cnew)
ExtraLength(i) = rem(numel(cnew{i,1}), 256);
V1= cnew{i,1}(1:numel(cnew{i,1})-ExtraLength(i));
V2= cnew{i,1}(ExtraLength(i)+1 : end);
end
As always, my pleasure.
I cannot reproduce the error you are getting. When I create a version of ‘cnew’ that closely resembles the one you posted, this runs without error:
cnew = mat2cell(rand(6000, 5), 6000, ones(1,5))'; % Create ‘cnew’
for i =1:numel(cnew)
ExtraLength(i) = rem(numel(cnew{i,1}), 256);
V1= cnew{i,1}(1:numel(cnew{i,1})-ExtraLength(i));
V2= cnew{i,1}(ExtraLength(i)+1 : end);
end
It would help if you copy and paste all the red error text from your Command Window to a Comment here so that I can see it. (That usually also has a copy of the line that threw the error. If it does not, please copy the line and include it as well.)
Thank you for your prompt response.
Yes the code does work now. But it doesn't give the results I want.
cnew = mat2cell(rand(6000, 4), 6000, ones(1,4))'; gives
cnew = { {6000x1 double}
{6000x1 double}
{6000x1 double}
{6000x1 double}
}
After using my for loop code I get the following results:
Extralength = [112, 112, 112, 112]
V1=[0.65 0.89 ..... 0.64]
V2=[0.68 0.89 ..... 0.0576]
I want to modify my code so that I get
V1 = { {5888x1 double}
{5888x1 double}
{5888x1 double}
{5888x1 double}
}
and the same for V2.
How should I modify my current code to get this result?
When I run it, both ‘V1’ and ‘V2’ are (in this instance) (5888x1) vectors:
cnew = mat2cell(rand(6000, 5), 6000, ones(1,5))'; % Create ‘cnew’
for i =1:numel(cnew)
ExtraLength(i) = rem(numel(cnew{i,1}), 256);
V1= cnew{i,1}(1:numel(cnew{i,1})-ExtraLength(i));
V2= cnew{i,1}(ExtraLength(i)+1 : end);
V1s = size(V1) % Temporary Diagnostic
V2s = size(V2) % Temporary Diagnostic
end
producing:
V1s =
5888 1
V2s =
5888 1
for all of them.
If you want ‘V1’ and ‘V2’ to be row cell arrays, save them as such:
V1{i} = cnew{i,1}(1:numel(cnew{i,1})-ExtraLength(i));
V2{i} = cnew{i,1}(ExtraLength(i)+1 : end);
To save them as column cell arrays:
V1{i,:} = cnew{i,1}(1:numel(cnew{i,1})-ExtraLength(i));
V2{i,:} = cnew{i,1}(ExtraLength(i)+1 : end);
If I understand correctly, that should do what you want.
Worked like a charm! Thanks a lot!!
Please do help me if this falls under your area of expertise.
Thanks in advance.
Unfortunately, it does not. I looked at that shortly after you posted it. I am not able to figure out how the Wavelet Analyzer App calculates the threshold.
I need to review wavelets, so I will take another look at it later. I cannot promise to be able to answer that question, though.
No problem. Thank you for trying :)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Wavelet Toolbox in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by