Main Content

labelSpectrogramOptions

Spectrogram options for time-frequency label definition

Since R2025a

    Description

    Use a labelSpectrogramOptions object to store spectrogram options for signal labeling in the time-frequency domain. You can use spectrogram options to create time-frequency region-of-interest (ROI) label definitions.

    Creation

    Description

    opts = labelSpectrogramOptions creates an object, opts, that stores the spectrogram options with default values.

    opts = labelSpectrogramOptions(resType) also specifies how to divide a signal into segments when constructing its spectrogram.

    opts = labelSpectrogramOptions(resType,PropertyName=Value) specifies additional properties using name-value arguments. You can specify multiple name-value arguments. For example, the spectrograms in this object use Kaiser windows with automatically chosen length, 50 dB sidelobe attenuation, and 90% overlap between adjoining segments.

    opts = labelSpectrogramOptions("rbw",Overlap=90, ...
        Window="kaiser",WindowAttenuationKaiser=50)

    example

    Input Arguments

    expand all

    Spectrogram resolution type, specified as "leakage", "rbw", or "windowlength". This argument sets the ResolutionType property.

    There are three ways in which you can divide a signal into segments:

    This table lists the properties that you can specify as name-value arguments depending on how you choose to divide the signal.

    In addition, you can specify these properties for any resolution type: Overlap, MinimumThresholdMode, MinimumThreshold, and UseDecibels.

    Properties

    expand all

    All resolution types

    Spectrogram resolution type, returned as "leakage", "rbw", or "windowlength".

    To set this property, use resType. After you create an object, you can modify this property using dot notation. For more information about dot notation, see Access Property Values.

    Data Types: char | string

    Percentage of overlapped samples between adjoining segments, specified as a nonnegative scalar less than 100. To learn more about how labelSpectrogramOptions interprets Overlap depending on how you choose to divide a signal into segments, see Spectrogram Options for Time-Frequency Labeling.

    Data Types: single | double

    Mode to set the minimum threshold in the spectrogram computation, specified as one of these:

    • "auto"labelSpectrogramOptions automatically sets the minimum threshold of the spectrogram.

    • "specify" — You can use MinimumThreshold to specify the minimum threshold of the spectrogram.

    Data Types: char | string

    Minimum threshold for the spectrogram, specified as a real-valued scalar expressed in decibels. MinimumThreshold represents the lower bound for nonzero values in the spectrogram computation.

    To specify this property, set MinimumThresholdMode to "specify".

    Data Types: single | double

    Option to express spectrogram magnitude in decibels, specified as 1 (true) or 0 (false).

    Data Types: single | double | logical

    Specific to Resolution Type

    Spectral leakage, specified as a nonnegative scalar less than or equal to 40.

    Leakage controls the window sidelobe attenuation relative to the mainlobe width, balancing between improving resolution and decreasing leakage:

    • A large leakage value resolves closely spaced tones but masks nearby weak tones.

    • A small leakage value finds small tones in the vicinity of larger tones but smears close frequencies together.

    For more information, see Leakage.

    To specify this property, set resType to "leakage".

    Data Types: single | double

    Mode to set the time resolution in the spectrogram computation, specified as one of these:

    • "auto"labelSpectrogramOptions automatically sets the time resolution of the spectrogram.

    • "specify" — You can use TimeResolution to specify the time resolution of the spectrogram.

    For more information, see Time Resolution.

    To specify this property, set resType to "leakage".

    Data Types: char | string

    Time resolution of the spectrogram, specified as a positive scalar. For more information, see Time Resolution.

    To specify this property, set TimeResolutionMode to "specify".

    Data Types: single | double

    Option to reassign spectrogram values, specified as 0 (false) or 1 (true).

    If you set Reassign to true, then labelSpectrogramOptions sets the spectrogram computation to sharpen the localization of spectral estimates by performing time and frequency reassignment. The reassignment technique produces periodograms and spectrograms that are easier to read and interpret. This technique reassigns each spectral estimate to the center of energy of its bin instead of the bin's geometric center. The technique provides exact localization for chirps and impulses.

    To specify this property, set resType to "leakage".

    Data Types: single | double | logical

    Mode to set the resolution bandwidth in the spectrogram computation, specified as one of these:

    • "auto"labelSpectrogramOptions automatically sets the resolution bandwidth of the spectrogram.

    • "specify" — You can use RBW to specify the resolution bandwidth of the spectrogram.

    For more information, see RBW and Segment Length.

    To specify this property, set resType to "rbw".

    Data Types: char | string

    Resolution bandwidth of the spectrogram, specified as a positive scalar.

    For more information, see RBW and Segment Length.

    To specify this property, set RBWMode to "specify".

    Data Types: single | double

    Type of window, specified as "hamming", "blackmanharris", "flattop", "hann", "rectangular", "chebyshev", or "kaiser". For more information, see Windows.

    To specify this property, set resType to "rbw" or "windowlength".

    Data Types: single | double | logical

    Sidelobe attenuation of Chebyshev window, specified in decibels as a scalar greater than or equal to 21.

    To specify this property, set Window to "chebyshev".

    Data Types: single | double

    Sidelobe attenuation of Kaiser window, specified in decibels as a scalar greater than or equal to 45.

    To specify this property, set Window to "kaiser".

    Data Types: single | double

    Mode to set window length in the spectrogram computation, specified as one of these:

    • "auto"labelSpectrogramOptions automatically sets the window length of the spectrogram.

    • "specify" — You can use WindowLength to specify the window length of the spectrogram.

    For more information, see Window Length and Segment Length.

    To specify this property, set resType to "windowlength".

    Data Types: char | string

    Window length, specified as a positive integer.

    For more information, see Window Length and Segment Length.

    To specify this property, set WindowLengthMode to "specify".

    Data Types: single | double

    Mode to set number of discrete Fourier transform (DFT) points in the spectrogram computation, specified as one of these:

    • "auto"labelSpectrogramOptions automatically sets the number of DFT points used to calculate the spectrogram.

    • "specify" — You can use NFFT to specify the number of DFT points used to calculate the spectrogram.

    For more information, see Number of DFT Points.

    To specify this property, you must:

    Data Types: char | string

    Number of discrete Fourier transform (DFT) points used to calculate the spectrogram, specified as a positive integer. The number of DFT points must be greater than or equal to the window length.

    For more information, see Number of DFT Points.

    To specify this property, set NFFTMode to "specify".

    Data Types: single | double

    Object Functions

    Examples

    collapse all

    Create a set of spectrogram options for a signal label definition. Specify a Hamming window with a length of 1024 samples.

     opts = labelSpectrogramOptions("windowlength", ...
         Overlap=50, ...
         Window="hamming", ...
         WindowLengthMode="specify",WindowLength=1024)
    opts = 
      labelSpectrogramOptions with properties:
    
              ResolutionType: "windowlength"
                     Overlap: 50
                      Window: "hamming"
            WindowLengthMode: "specify"
                WindowLength: 1024
                    NFFTMode: "auto"
        MinimumThresholdMode: "auto"
                 UseDecibels: 1
    
    

    Create a time-frequency ROI signal label definition with time-frequency options.

     signalLabelDefinition("LowBand", ...
         LabelType="roiTimeFrequency",TimeFrequencyOptions=opts);

    Label Gaussian atoms in the time-frequency domain using a time-frequency region-of-interest (ROI) label definition and spectrogram options.

    Generate Signal and Visualize Spectrogram

    Generate a signal that consists of a voltage-controlled oscillator and four Gaussian atoms. The signal is sampled at 14 kHz for two seconds. Plot the spectrogram of the signal.

    Fs = 14000;
    t = (0:1/Fs:2)';
    st = 0.01;
    gaussFun = @(A,x,mu,f) exp(-(x-mu).^2/(2*st^2)).*sin(2*pi*f.*x)*A';
    atomTimeCenters = [0.2 0.5 1 1.75];
    atomFreqCenters = [2 6 2 5]*1000;
    s = gaussFun([1 1 1 1]/10,t,atomTimeCenters,atomFreqCenters);
    x = vco(chirp(t+.1,0,t(end),3).*exp(-2*(t-1).^2),[0.1 0.4]*Fs,Fs);
    s = s/10+x;
    
    bt = 0.2;
    tr = 0.05;
    op = 99;
    pspectrum(s,Fs,"spectrogram", ...
        Leakage=bt,TimeResolution=tr,OverlapPercent=op)

    Figure contains an axes object. The axes object with title Fres = 64.5333 Hz, Tres = 50 ms, xlabel Time (s), ylabel Frequency (kHz) contains an object of type image.

    The spectrogram shows four patches in time-frequency domain that correspond with the Gaussian atoms. Define the times and frequencies for all the atoms.

    atomTimes = atomTimeCenters'+[-st st]*5.5;
    atomFreqs = atomFreqCenters'+[-1 1]*200;

    Label Signal in Time-Frequency Domain

    Create a logical time-frequency ROI label definition to label the Gaussian atoms. Specify spectrogram options with leakage properties.

    opts = labelSpectrogramOptions("leakage", ...
        Leakage=40*(1-bt),Overlap=op, ...
        TimeResolutionMode="specify",TimeResolution=tr);
    
    lblDef = signalLabelDefinition("Atom", ...
        LabelDataType="logical", ...
        LabelType="roiTimeFrequency",TimeFrequencyOptions=opts);

    Create a labeled signal set from the signal and time-frequency ROI label definition.

    lss = labeledSignalSet(s,lblDef,SampleRate=Fs);

    Label the four atoms in time-frequency domain. Set the label values to true.

    setLabelValue(lss,1,"Atom",atomTimes,atomFreqs,true(1,4))

    Visualize Time-Frequency Image and Label Mask

    Create datastores from the labeled signal set for the time-frequency ROI label.

    imSize = [512 768];
    [sds,ads] = createDatastores(lss,"Atom", ...
        TimeFrequencyMapFormat="image", ...
        TimeFrequencyImageSize=imSize, ...
        TimeFrequencyLabelFormat="mask", ...
        TimeFrequencyMaskPriority=true);

    Read and show the time-frequency image.

    imagesc(read(sds))

    Figure contains an axes object. The axes object contains an object of type image.

    Read the label mask and display it above the time-frequency image.

    lbl = read(ads);
    im = zeros([imSize 3]);
    im(:,:,1) = lbl{1};
    hold on
    imagesc(im,AlphaData=0.5*lbl{1})
    hold off

    Figure contains an axes object. The axes object contains 2 objects of type image.

    More About

    expand all

    Version History

    Introduced in R2025a