How to divide a labeled labeledSignalSet and still keep the labels?
4 views (last 30 days)
Show older comments
MathWorks Support Team
on 9 Oct 2020
Edited: MathWorks Support Team
on 7 Feb 2025
I have a signal which I labeled using the "signal labeler app", but now, after it was labeled I want to divide it to shorter segments, which will be those who will get as input to the Deep network, and still remain the labels.
The main reason for doing this is that the undivided signal was already manually labeled, and manually labeling it again after the segmentation will be, although possible, very time consuming.
If there is a recommended dividing method which might help I'll be glad for any suggestion, I usually use reshaping the signal to a matrix and taking the columns as segments, sometimes use "for loops" to take the segments from time1 to time2 in constant jumps, but every method that will keep the labels will be fine.
Accepted Answer
MathWorks Support Team
on 25 Jan 2025
Edited: MathWorks Support Team
on 7 Feb 2025
A new object called "signalMask" allows you to convert regions of interest tables to sequence masks. You can use this to convert the regions table to a mask and then chunk the sequence into smaller sequences that can be used to train a model.
"signalMask" is available in R2020b. To explore more ideas, execute the following command in the MATLAB R2020b command window to access the release-specific documentation:
>> web(fullfile(docroot, 'signal/ref/signalmask.html?searchHighlight=signalMask'))
A function to chunk signals and their labels is planned for a future release.
The following example demonstrates how labeled signal regions are chunked to train an LSTM network to learn how to segment signals. To view the detailed documentation, run the command below in the MATLAB R2020b command window:
>> web(fullfile(docroot, 'signal/ug/waveform-segmentation-using-deep-learning.html'))
There is a script available to chunk signals and labels both using "signalMask" and without using "signalMask":
% Get the data load('ls_125.mat') % Convert labels to categoricals (numeric not supported) regionsTbl = ls.Labels.cessation{1}; regionsTbl.Value = categorical(cell2mat(regionsTbl.Value)); % Signal sample rate signalTbl = ls.Source{1}; signalVector = signalTbl.Sig; Fs = 1/seconds(mean(diff(signalTbl.Time))); % Sequence length seqLength = height(ls.Source{1}); %% Get a categorical sequence using signalMask (20b) % Signal mask based on regions labels m = signalMask(regionsTbl,'SampleRate',Fs); % Convert roi table mask to a categorical sequence mask of length = signal length sequenceMask = catmask(m,seqLength); %% Get a categorical sequence without using signalMask % Convert regions from seconds to samples regionsMatrix = min(seqLength,1+round(regionsTbl{:,1}*Fs)); sequenceMask = categorical(strings(seqLength,1)); for idx = 1:size(regionsMatrix,1) roi = regionsMatrix(idx,:); sequenceMask(roi(1):roi(2),1) = regionsTbl.Value(idx); end %% Get the signal chunks and the region labels for each chunk % Resize signal and label sequence based on desired chunk lengths chunkLength = 1000; numChunks = floor(seqLength/chunkLength); sequenceMask = sequenceMask(1:numChunks*chunkLength); signalVector = signalVector(1:numChunks*chunkLength); % Each of the matrices below correspond to a signal chunk and its % corresponding label mask signalChunks = reshape(signalVector,chunkLength,numChunks); labelSequenceChunks = reshape(sequenceMask,chunkLength,numChunks);
For further information regarding the current release, please visit the following link:
0 Comments
More Answers (0)
See Also
Categories
Find more on AI for Signals 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!