## 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:

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:Compute the spectrum of each segment over a set of

*discrete Fourier transform points*to get the*short-time Fourier transform*.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`

samples`2`

`1`

sample –`32`

samples`64`

samples –`255`

samples`8`

`8`

samples –`32`

samples`256`

samples –`2047`

samples`8`

`32`

samples –`256`

samples`2048`

samples –`4095`

samples`16`

`128`

samples –`256`

samples`4096`

samples –`8191`

samples`32`

`128`

samples –`256`

samples`8192`

samples –`16383`

samples`64`

`128`

samples –`256`

samples`16384`

samples –*N*samples`128`

`128`

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

$$\beta =\{\begin{array}{ll}0.1102(\alpha -8.7),\hfill & \alpha >50\hfill \\ 0.5842{(\alpha -21)}^{0.4}+0.07886(\alpha -21),\hfill & 50\ge \alpha \ge 21\hfill \\ 0,\hfill & \alpha <21\hfill \end{array}$$

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 Samples | Resulting 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:$$\text{Windowlength}=\lceil \frac{\text{Samplerate}}{\text{RBW}}\times \frac{{\displaystyle \sum _{n=1}^{\text{Windowlength}}{\left|\text{Window}\left(n\right)\right|}^{2}}}{{\left|{\displaystyle \sum _{n=1}^{\text{Windowlength}}\text{Window}\left(n\right)}\right|}^{2}}\rceil .$$

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`

samples`2`

`1`

sample –`32`

samples`64`

samples –`255`

samples`8`

`8`

samples –`32`

samples`256`

samples –`2047`

samples`8`

`32`

samples –`256`

samples`2048`

samples –`4095`

samples`16`

`128`

samples –`256`

samples`4096`

samples –`8191`

samples`32`

`128`

samples –`256`

samples`8192`

samples –`16383`

samples`64`

`128`

samples –`256`

samples`16384`

samples –*N*samples`128`

`128`

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:$$\beta =\{\begin{array}{ll}0.1102(\alpha -8.7),\hfill & \alpha >50\hfill \\ 0.5842{(\alpha -21)}^{0.4}+0.07886(\alpha -21),\hfill & 50\ge \alpha \ge 21\hfill \\ 0,\hfill & \alpha <21\hfill \end{array}$$

#### 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 Samples | Resulting 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$$\text{Windowlength}=\lfloor \frac{\text{Signallength}}{8-7\times \frac{\text{Overlappercent}}{100}}\rfloor $$

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:$$\beta =\{\begin{array}{ll}0.1102(\alpha -8.7),\hfill & \alpha >50\hfill \\ 0.5842{(\alpha -21)}^{0.4}+0.07886(\alpha -21),\hfill & 50\ge \alpha \ge 21\hfill \\ 0,\hfill & \alpha <21\hfill \end{array}$$

#### 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 Samples | Resulting 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

- Label Signal Attributes, Regions of Interest, and Points
- Label ECG Signals and Track Progress
- Examine Labeled Signal Set
- Automate Signal Labeling with Custom Functions
- Label Spoken Words in Audio Signals

## More About

- Use Signal Labeler App
- Import Data into Signal Labeler
- Create or Import Signal Label Definitions
- Label Signals Interactively or Automatically
- Custom Labeling Functions
- Customize Labeling View
- Feature Extraction Using Signal Labeler
- Dashboard
- Export Labeled Signal Sets and Signal Label Definitions
- Signal Labeler Usage Tips