Examine Labeled Signal Set

Load into the MATLAB® workspace the MAT-file you created in the Label Signal Attributes, Regions of Interest, and Points example. Verify that the labeled signal set contains the definitions that you added using Signal Labeler.

load Whale_Songs

labelDefinitionsSummary(whalesongs)
ans=3×9 table
      LabelName        LabelType     LabelDataType     Categories     ValidationFunction    DefaultValue             Sublabels             Tag            Description         
    ______________    ___________    _____________    ____________    __________________    ____________    ___________________________    ___    ____________________________

    "WhaleType"       "attribute"    "categorical"    {3x1 string}       {["N/A"   ]}       {0x0 double}    {0x0 double               }    ""     "Whale type"                
    "MoanRegions"     "roi"          "logical"        {["N/A"   ]}       {0x0 double}       {0x0 double}    {0x0 double               }    ""     "Regions where moans occur" 
    "TrillRegions"    "roi"          "logical"        {["N/A"   ]}       {0x0 double}       {0x0 double}    {1x1 signalLabelDefinition}    ""     "Regions where trills occur"

Verify that TrillPeaks is a sublabel of TrillRegions.

labelDefinitionsHierarchy(whalesongs)
ans = 
    'WhaleType
       Sublabels: []
     MoanRegions
       Sublabels: []
     TrillRegions
       Sublabels: TrillPeaks
     '

Retrieve the second member of the set. Retrieve the names of the timetable variables.

song = getSignal(whalesongs,2);

summary(song)
RowTimes:

    Time: 76579x1 duration
        Values:
            Min           0 sec       
            Median        9.5722 sec  
            Max           19.144 sec  
            TimeStep      0.00025 sec 

Variables:

    whale2: 76579x1 double

        Values:

            Min       -0.37326
            Median           0
            Max        0.37914

Plot the signal.

t = song.Time;
sng = song.whale2;

plot(t,sng)

Visualize Labeled Regions

Display and identify the regions of interest that you labeled. For more details, see the code for the labelIntervals function at the end of the example.

mvals = getLabelValues(whalesongs,2,'MoanRegions');
tvals = getLabelValues(whalesongs,2,'TrillRegions');

cmap = lines;

hold on

tmoan = mvals.ROILimits;
for kj = 1:size(tmoan,1)
    tv = find(seconds(t)>tmoan(kj,1) & seconds(t)<tmoan(kj,2));
    plot(t(tv),sng(tv),'Color',cmap(2,:))
end

ttrill = tvals.ROILimits;
for kj = 1:size(ttrill,1)
    tv = find(seconds(t)>ttrill(kj,1) & seconds(t)<ttrill(kj,2));
    plot(t(tv),sng(tv),'Color',cmap(3,:))
end

labelIntervals(mvals,tvals,cmap(4,:))

hold off

Visualize Labeled Points

Display and identify the trill peaks that you labeled.

pk = getLabelValues(whalesongs,2,{'TrillRegions','TrillPeaks'});

locs  = zeros(size(pk,1),1);
for kj = 1:length(locs)
    locs(kj) = find(seconds(t) == pk.Location(kj));
end

hold on
plot(t(locs),sng(locs)+0.01,'v','MarkerSize',8,'Color',[0.929,0.694,0.125])
text(t(locs)+seconds(0.2),sng(locs)+0.05,int2str(cell2mat(pk.Value)), ...
    'HorizontalAlignment','center')
hold off

This helper function displays and identifies regions of interest.

function labelIntervals(mvals,tvals,clr)
    [X,Y] = meshgrid(seconds([mvals.ROILimits;tvals.ROILimits]),ylim);
    plot(X,Y,':k')
    topts = {'HorizontalAlignment','center','FontWeight','bold', ...
        'FontSize',12,'Color',clr};
    text((X(1,1:4)+X(1,5:end))/2,Y(2,5:end)-0.1, ...
        ["moan" "moan" "moan" "trill"],topts{:})
end

See Also

Apps

Functions

Related Examples

More About