This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Signal Labeler

Label signals for analysis or machine and deep learning applications

Description

Signal Labeler is an interactive tool that enables you to label signals for analysis or for use in machine learning and deep learning applications. Using Signal Labeler, you can

  • Label signals with attributes, regions, and points of interest

  • Use logical, categorical, numerical, or string-valued labels

  • Add, edit, and delete labels or sublabels

  • Display selected subsets of signals and labels

Signal Labeler saves data to Signal Analyzer as labeledSignalSet objects. You can use labeledSignalSet objects to train a network, classifier, or analyze data and report statistics.

Open the Signal Labeler

In the Signal Analyzer app, on the Analyzer tab, click Label.

Examples

expand all

Recordings of whale songs contain trills and moans. Trills sound like series of clicks. Moans are low-frequency cries similar to the sound made by a ship's horn. You want to look at each signal and label it to identify the whale type, the trill regions, and the moan regions. For each trill region, you also want to label a few selected signal peaks.

Load Unlabeled Data

Start by loading a data set that includes two recordings of whale songs. The signals are called whale1 and whale2 and are sampled at 4 kHz. whale1 consists of a trill followed by three moans. whale2 consists of two moans, a trill, and another moan.

load labelwhalesignals

% To hear, type soundsc(whale1,Fs), pause(22), soundsc(whale2,Fs)

Bring the signals into Signal Labeler:

  1. Start Signal Analyzer and drag the signals to the Signal table.

  2. Select the signals and add time information. On the Analyzer tab, click Time Values, select Sample Rate and Start Time, and enter the sample rate, Fs.

  3. With the signals selected, click Label on the Analyzer tab.

Add Signal Label Definitions

Define labels to attach to the signals. Labels can be of three types:

  • Attribute labels define signal characteristics.

  • Region-of-interest (ROI) labels define signal characteristics over regions of interest.

  • Point labels define signal characteristics over points of interest.

Each label can have one of four data types:

  • Logical labels can be either true or false.

  • Categorical labels can belong to any one of a set of categories that you specify.

  • Numeric labels can have any numeric value.

  • String labels can have any value represented by a string.

Any label can have any number of sublabels. Sublabels themselves cannot have sublabels.

For the whale song signals:

  1. Define a categorical attribute label to store whale types. Call it WhaleType. The possible categories are blue whale, humpback whale, and white whale.

  2. Define a logical region-of-interest (ROI) label that is true for moan regions. Call it MoanRegions.

  3. Define a logical ROI label that is true for trill regions. Call it TrillRegions.

  4. Define a numeric point label to capture trill peaks. Call it TrillPeaks. Set this label as a sublabel of the TrillRegions label.

To define each label, click Add Definition on the Label tab. To define the sublabel, select the TrillRegions label in the Label Definitions browser, click Add Definition ▼, and select Add sublabel definition.

Enter the following values in the fields in the dialog box that appears for each signal label or sublabel definition. Leave the Default field empty in each case.

LabelNameLabelTypeLabelDescriptionDataTypeCategoriesWhaleTypeAttributeWhaletypecategorical{bluehumpbackwhiteMoanRegionsROIRegionswheremoansoccurlogical---TrillRegionsROIRegionswheretrillsoccurlogical---TrillPeaksPointTrillpeaksnumeric---

You can export the signal definitions you created to a MAT-file by clicking Export. A dialog box appears that prompts you for a file name. At any point you can import signal definitions stored in a MAT-file by clicking Import.

Label Signal Attributes

The songs in the data are from two blue whales. Set the WhaleType values for both signals:

  1. Select WhaleType on the Label Definitions browser.

  2. Click Label ▼ and select Label Signals.

  3. In the dialog box that appears, verify that both whale1 and whale2 are selected and that the Value field is set to blue. (If you do not specify a default value in a categorical signal label definition, Signal Labeler sets the label to the first category specified in the definition.)

  4. Click OK.

Plot the whale1 signal by selecting the check box next to its name. Signal attributes appear both in the Labeled Signal Set browser and under the time plot.

Label Signal Regions

Visualize the whale songs and label the trill and moan regions.

  • Trill regions have distinct bursts of sound punctuated by silence. whale1 has a trill centered at about 2 seconds.

  • Moan regions are sustained low-frequency wails. whale1 has moans centered at about 7 seconds, 12 seconds, and 17 seconds.

Label the signals one at a time:

  1. On the Plot column of the Labeled Signal Set browser, check the box next to the signal name to plot the signal.

  2. To label a moan, on the Label Definitions browser, select the MoanRegions label definition.

  3. Click Label ▼ and select Label Plotted. A shaded region appears, framed by an animated dashed line. (The animated frame indicates the region is active.) Move and resize the active region until it encloses a moan region. For better label placement, you can go to the Display tab and choose a zoom action or activate the panner.

  4. Click Accept, press Enter, or double-click to label the ROI. The region changes to a gradient of the signal color. If you do not specify a default value in a logical label definition, Signal Labeler sets the label to true.

  5. Repeat the procedure for the other two moans.

  6. To label a trill, on the Label Definitions browser, select the TrillRegions label definition. Label the trill region using steps 3 and 4.

  7. Before labeling the second whale song signal, remove the first whale song signal from the plot by clearing the check box next to its name in the Labeled Signal Set browser. If you have the two signals plotted when you label a region or point, Signal Labeler associates the label with both signals.

The label viewer axes show the locations and widths of the regions of interest. They also show the value assigned to each region.

Label Signal Points

Trill regions have distinct peaks that correspond to bursts of sound. Label three peaks in each trill region. Because trill peaks are sublabels, each one must be associated with a particular TrillRegions label.

Label the signals one at a time:

  1. On the Plot column of the Labeled Signal Set browser, check the box next to the signal name to plot the signal. Also check the box corresponding to the trill region whose peaks you want to label.

  2. On the Label Definitions browser, select TrillPeaks.

  3. On the toolstrip, under Value, enter 1, corresponding to the first peak.

  4. On the Labeled Signal Set browser, select the trill region. The trill region becomes active and is framed by an animated dashed line.

  5. Click Label ▼ and select Label Plotted. The trill region is framed by a solid line, and an animated dashed (active) line appears for the point being labeled.

  6. Move the active line until it crosses the signal at a peak of your choice. For better label placement, you can go to the Display tab and choose a zoom action or activate the panner.

  7. Click Accept, press Enter, or double-click to label the peak. The dashed line changes to a solid line of the same color as the signal.

  8. Repeat for two more peaks, entering 2 and 3 to identify them.

  9. Before labeling trill peaks for the second whale song signal, remove the first whale song signal from the plot by clearing the check box next to its name in the Labeled Signal Set browser.

The label viewer axes show the locations of the points of interest and the value assigned to each point.

Plot the two signals to see a summary of their labels in the Label Viewer. Expand the labeled signal set hierarchy in the Labeled Signal Set browser to see details for all the labels. (To expand the hierarchy, right-click any signal in the browser and select Expand All.) For each signal, plot the first moan region and the third trill peak that you labeled.

Edit Signal Label Values

At any point, you can edit any signal label using the Labeled Signal Set browser. To edit an attribute label, select it, right-click, and select Edit. For example, if you discover that the second whale is actually a white whale, you can select the WhaleType attribute for whale2, right-click, select Edit, and, on the dialog box that appears, select white from the drop-down menu.

If you want to edit the value of an ROI label or a point label, you can modify the value in the dialog box. To modify the location of an ROI label or a point label, you can modify the location fields in the dialog box. Alternatively, you can:

  1. Plot the label by checking the box next to its name.

  2. Select the label.

  3. Move the region or point in the time plot when it becomes active.

Export Labeled Signal Set

Export labeled signals by saving your labeling and exporting the new labeledSignalSet object. Click the Save Labels button on the toolstrip. In the dialog box that appears, give the name whalesongs to the labeled signal set. Clicking the OK button gets you back to Signal Analyzer. See Signal Labeler Import and Export Behavior for more information on how Signal Labeler exports labeled signal sets.

On the Signal table, select whalesongs and right-click to export it to a file called Whale_Songs.mat.

Load into the MATLAB® workspace the MAT-file you created in the Whale Song Labeling 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"]               []         []                             ""     "Whale type"                
    "MoanRegions"     "roi"          "logical"        ["N/A"     ]         []                    []         []                             ""     "Regions where moans occur" 
    "TrillRegions"    "roi"          "logical"        ["N/A"     ]         []                    []         [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

Tips

Signal Labeler averages channel colors when it renders labels corresponding to multichannel signals. For best results, customize the line color so that it is exactly the same for all channels in a given signal. Perform the customization in Signal Analyzer before entering Signal Labeler.

Compare the label color for diffr, a signal whose channels have different colors, to the label color for equal, a signal whose channels all have the same color. Any labels for equal will be rendered in the shade of blue that all the channels share. Labels for diffr will be rendered in a shade of brown that does not match any of the channel colors.

Introduced in R2019a