Main Content

Spectrogram Computation in Signal Labeler

A nonstationary signal is a signal whose frequency content changes with time. The spectrogram of a nonstationary signal is an estimate of the time evolution of its frequency content. To construct the spectrogram of a nonstationary signal, Signal Labeler follows these steps:

  1. Divide the signal into equal-length windowed segments that may or may not overlap. For best results, choose a segment length short enough that the frequency content of the signal does not change appreciably within a segment. In Signal Labeler, there are three ways of dividing a signal into segments:

  2. Compute the spectrum of each segment over a set of discrete Fourier transform points to get the short-time Fourier transform.

  3. Display segment by segment the magnitude squared of each spectrum in decibels. Depict the magnitudes side by side as an image with magnitude-dependent colormap.

For more information, see Spectrogram Computation with Signal Processing Toolbox.

Divide Signal into Segments: Control Leakage

If you select Leakage in the Resolution Type section of the Spectrogram tab, you can specify the segment length, the overlap between adjoining segments, and the sidelobe attenuation of the window.

Segment Length

  • To specify the segment length, on the Spectrogram tab, in the Time Resolution section, click Specify.

    • If the signal does not have time information, specify the time resolution (segment length) in samples. The time resolution must be an integer greater than or equal to 1 and smaller than or equal to the signal length.

    • If the signal has time information, specify the segment length in seconds. The app converts the result into a number of samples and rounds it to the nearest integer that is less than or equal to the number but not smaller than 1. The time resolution must be smaller than or equal to the signal duration.

  • If you select Auto in the Time Resolution section, Signal Labeler uses the length of the entire signal to choose the segment length. The app sets the time resolution as N/d samples, where the brackets denote the ceiling function, N is the length of the signal, and d is a divisor that depends on N.

    Signal Length (N)Divisor (d)Segment Length
    2 samples – 63 samples21 sample – 32 samples
    64 samples – 255 samples88 samples – 32 samples
    256 samples – 2047 samples832 samples – 256 samples
    2048 samples – 4095 samples16128 samples – 256 samples
    4096 samples – 8191 samples32128 samples – 256 samples
    8192 samples – 16383 samples64128 samples – 256 samples
    16384 samples – N samples128128 samples – ⌈N / 128⌉ samples

Window Type

If you divide the signal into segments by controlling the leakage, Signal Labeler uses Kaiser windows, which have an adjustable shape factor β that is related to the leakage by β = 40(1 – ).

Choosing a β value is equivalent to specifying the sidelobe attenuation of the Kaiser window. If α is the attenuation in dB, the two quantities are related by

β={0.1102(α8.7),α>500.5842(α21)0.4+0.07886(α21),50α210,α<21

  • The minimum value in the Leakage slider range corresponds to a Kaiser window with β = 40, where a wide mainlobe captures essentially all the spectral energy representable in double precision and the energy contained in the sidelobes becomes negligible.

  • An intermediate value of β ≈ 6 approximates a Hann window closely.

  • The maximum value in the slider range corresponds to a Kaiser window with β = 0, equivalent to a rectangular window with a narrow mainlobe and large sidelobes.

Note

The leakage used to divide a signal into segments is independent of the leakage used to compute signal spectra. You can adjust the values separately.

Overlap

Specify the overlap as a percentage of the segment length in the Time Resolution section of the Spectrogram tab. The app converts the value into a number of samples and rounds it to the nearest integer that is less than or equal to the number.

Specifying the overlap changes the number of segments. The larger the overlap, the larger the number of segments. Segments that extend beyond the signal endpoint are zero-padded

For example, consider the seven-sample signal [s0 s1 s2 s3 s4 s5 s6] and a window length of 4 samples.

Number of Overlapping SamplesResulting Segments
0
s0 s1 s2 s3
            s4 s5 s6 0
1
s0 s1 s2 s3
         s3 s4 s5 s6
2
s0 s1 s2 s3
      s2 s3 s4 s5
            s4 s5 s6 0
3
s0 s1 s2 s3
   s1 s2 s3 s4
      s2 s3 s4 s5
         s3 s4 s5 s6

By default, Signal Labeler uses 50% overlap.

Discrete Fourier Transform Points

If you adjust the spectral resolution by controlling the leakage, Signal Labeler always uses 1024 discrete Fourier transform points.

Divide Signal into Segments: Control Resolution Bandwidth

Since R2024b

If you select RBW in the Resolution Type section of the Spectrogram tab, you can specify the RBW, the window type, the overlap between adjoining segments, and the sidelobe attenuation for some windows.

Segment Length

  • If you specify an RBW value in the Bandwidth section of the Spectrogram tab, Signal Labeler determines the segment length iteratively by solving this equation:

    Window length=Sample rateRBW×n=1Window length|Window(n)|2|n=1Window lengthWindow(n)|2.

  • If you select Auto in the Bandwidth section of the Spectrogram tab, Signal Labeler chooses a segment length of N/d samples, where the brackets denote the ceiling function, N is the signal length, and d is a divisor that depends on N.

    Signal Length (N)Divisor (d)Segment Length
    2 samples – 63 samples21 sample – 32 samples
    64 samples – 255 samples88 samples – 32 samples
    256 samples – 2047 samples832 samples – 256 samples
    2048 samples – 4095 samples16128 samples – 256 samples
    4096 samples – 8191 samples32128 samples – 256 samples
    8192 samples – 16383 samples64128 samples – 256 samples
    16384 samples – N samples128128 samples – ⌈N / 128⌉ samples

Window Type

If you divide the signal into segments by controlling the resolution bandwidth, you can choose one of these spectral windows:

  • Blackman-Harris

  • Chebyshev

  • Flat-top

  • Hamming (default)

  • Hann

  • Kaiser

  • Rectangular

You can control the sidelobe attenuation for the Chebyshev and Kaiser windows. Specify the desired attenuation as a positive number in decibels.

  • For a Chebyshev window, all sidelobes have an amplitude smaller than the mainlobe level by the specified attenuation value. The specified value must be at least 45 dB.

  • For a Kaiser window, the highest sidelobe has an amplitude smaller than the mainlobe level by the specified attenuation value. The specified value must be at least 21 dB. Choosing a sidelobe attenuation of α dB is equivalent to specifying this β value:

    β={0.1102(α8.7),α>500.5842(α21)0.4+0.07886(α21),50α210,α<21

Overlap

You can specify the window length and the overlap between adjoining segments simultaneously. Specifying the overlap changes the number of segments. The larger the overlap, the larger the number of segments. Segments that extend beyond the signal endpoint are zero-padded.

For example, consider the seven-sample signal [s0 s1 s2 s3 s4 s5 s6] and a window length of 4 samples.

Number of Overlapping SamplesResulting Segments
0
s0 s1 s2 s3
            s4 s5 s6 0
1
s0 s1 s2 s3
         s3 s4 s5 s6
2
s0 s1 s2 s3
      s2 s3 s4 s5
            s4 s5 s6 0
3
s0 s1 s2 s3
   s1 s2 s3 s4
      s2 s3 s4 s5
         s3 s4 s5 s6

Specify the overlap value as a percentage of the window length. The default value is 50%.

Note

You cannot specify 100% overlap. The maximum attainable value corresponds to one sample less than the window length. If you specify that value, Signal Labeler divides the signal into [Signal length – (Window length – 1)] segments.

Discrete Fourier Transform Points

If you adjust the segment length by controlling the resolution bandwidth, Signal Labeler always makes NFFT equal to the window length.

Divide Signal into Segments: Control Window Length

Since R2024b

If you select Window Length in the Resolution Type section of the Spectrogram tab, you can specify the window length, the number of discrete Fourier transform points, the window type, the overlap between adjoining segments, and the sidelobe attenuation for some windows.

Segment Length

  • To specify the segment length, select Specify in the Window Length section of the Spectrogram tab. Specify the segment length in samples.

  • If you select Auto in the Window Length section of the Spectrogram tab, Signal Labeler uses a window length

    Window length=Signal length87×Overlap percent100

    so that the signal is divided into eight segments with ⌊Window length × Overlap percent/100⌋ samples of overlap between adjoining segments. The ⌊⌋ symbols denote the floor function.

Window Type

If you adjust the segment length by controlling the window length, you can choose one of these spectral windows:

  • Blackman-Harris

  • Chebyshev

  • Flat-top

  • Hamming (default)

  • Hann

  • Kaiser

  • Rectangular

You can control the sidelobe attenuation for the Chebyshev and Kaiser windows. Specify the desired attenuation as a positive number in decibels.

  • For a Chebyshev window, all sidelobes have an amplitude smaller than the mainlobe level by the specified attenuation value. The specified value must be at least 45 dB.

  • For a Kaiser window, the highest sidelobe has an amplitude smaller than the mainlobe level by the specified attenuation value. The specified value must be at least 21 dB. Choosing a sidelobe attenuation of α dB is equivalent to specifying this β value:

    β={0.1102(α8.7),α>500.5842(α21)0.4+0.07886(α21),50α210,α<21

Overlap

You can specify the window length and the overlap between adjoining segments simultaneously. Specifying the overlap changes the number of segments. The larger the overlap, the larger the number of segments. The app zero-pads segments that extend beyond the signal endpoint.

For example, consider the seven-sample signal [s0 s1 s2 s3 s4 s5 s6] and a window length of 4 samples.

Number of Overlapping SamplesResulting Segments
0
s0 s1 s2 s3
            s4 s5 s6 0
1
s0 s1 s2 s3
         s3 s4 s5 s6
2
s0 s1 s2 s3
      s2 s3 s4 s5
            s4 s5 s6 0
3
s0 s1 s2 s3
   s1 s2 s3 s4
      s2 s3 s4 s5
         s3 s4 s5 s6

Specify the overlap value as a percentage of the window length. The default value is 50%.

Note

You cannot specify 100% overlap. The maximum attainable value corresponds to one sample less than the window length. If you specify that value, Signal Labeler divides the signal into [Signal length – (Window length – 1)] segments.

Discrete Fourier Transform Points

If you adjust the spectral resolution by controlling the window length, you can specify NFFT. NFFT must be greater than or equal to the window length. If you do not specify a value, Signal Labeler uses the window length.

Time Alignment

Once the segment length and overlap are set, the number of segments and their edge locations stay fixed and are independent of any zooming or panning. When you zoom and pan, Signal Labeler computes and displays the spectrogram using the segments that fall within the visible zoomed-in region of interest.

The app:

  • Aligns the time axis of the spectrogram with the axis of the corresponding time-domain plot. That way, the spectral content at a given time aligns with its occurrence.

  • For nonzero overlap, extends the first and last segments to the signal endpoints.

  • Zero-pads the signal if the last segment extends beyond the signal endpoint.

When the segments have 0% overlap, each segment is centered at the actual time of occurrence. When the overlap is nonzero, the alignment of the spectrogram time axis with the time-domain axis has the effect that the first and last time intervals are elongated. All other time intervals are of the same length. In other words, the center of each segment, except for the first and last, corresponds to the actual time of occurrence. Consider this example:

Compute and Display Segment Spectra

Given the window shape and length, the overlap between segments, and the number of discrete Fourier transform points, Signal Labeler computes the spectrum of each segment following the procedure outlined in Spectrum Computation in Signal Analyzer. In summary, the app finds a compromise between the spectral resolution achievable with the entire length of the segment and the performance limitations that result from computing large FFTs.

See Also

Apps

Functions

Related Examples

More About