HDL-MIC · Documentation

Spectrogram and signal

The “Spectrogram” and “Microphone signal” cards are intended for analysing the signal of the selected channel in the time and frequency domains before and after processing, and for listening to it.

Purpose

RepresentationDomainApplication
Amplitude spectrumfrequencySignal composition: tonal components, harmonics, noise level, filter effect
WaveformtimeSignal shape, pulses, clipping, DC component, filter transient
Spectrogramtime-frequencyVariation of the spectrum over time; choice of filter edge frequencies
Listening—Auditory assessment of the signal and the processing result

The channel is selected with the ch0…ch3 switch. The original signal and the processed signal (filter, equalizer and, in streaming mode, noise reduction) are displayed simultaneously.

Data source

The spectrum and waveform are updated every 0.5 s, the spectrogram every 0.25 s.

Amplitude spectrum

The spectrum is computed by the discrete Fourier transform (DFT, FFT algorithm) of the window samples after subtracting the mean value and multiplying by the Hann window. The amplitudes are normalized so that a sinusoid with an amplitude equal to full scale gives a level of 0 dBFS:

X(k) = Σn=0…N−1 (x[n] − x̄)·w[n]·e−j2πkn/N,   w[n] = 0.5 − 0.5·cos(2πn/N)
L(k) = 20·lg( |X(k)| / (N/4 · 223) ) dBFS,   fk = k·fs/N,   k = 0…N/2

The factor N/4 equals the product of N/2 (the amplitude of a sinusoid in the one-sided spectrum) and the coherent gain of the Hann window, 0.5. The frequency resolution is Δf = fs/N. For display the spectrum is reduced to 300 points evenly spaced on a logarithmic frequency axis from max(10 Hz, fs/N) to fs/2; each point shows the maximum value over the bins falling into it, which preserves narrow spectral peaks.

Spectral leakage and window

The DFT of a finite-length window is equivalent to the DFT of the signal multiplied by a rectangular window. If the frequency of a sinusoid does not coincide with a bin frequency fk, its energy is spread over adjacent bins — spectral leakage. The Hann window reduces the sidelobe level to −31 dB (−13 dB for the rectangular window) and provides a sidelobe roll-off of 18 dB/octave at the cost of widening the main lobe to ±2Δf.

Fig. 1. Amplitude spectrum of a sinusoid with an amplitude of 0 dBFS and a frequency between bins (f = 1000 Hz + Δf/2), N = 1024, fs = 16,276 Hz: rectangular window and Hann window.

Noise level in the spectrum

The normalization of L(k) is correct for sinusoidal components. For broadband noise the power per bin is proportional to the bin width Δf = fs/N. Therefore the displayed noise level depends on the window length and the sampling rate: when N is doubled it decreases by 3 dB, while the level of a sinusoidal component does not change. Noise levels on different spectra may be compared only for equal N and fs; for absolute estimates the power spectral density is used (for example, Welch's method, scipy.signal.welch, applied to recorded data).

Waveform

The waveform displays the samples x[n]/223 (fraction of full scale) as a function of time t = n/fs. For display the number of points is limited to 1024: with W = 2048 every second sample is shown (decimation without filtering, for display only). The initial interval of the filtered signal of duration S/fs corresponds to the filter transient (see “Filters”).

Spectrogram

A spectrogram is the amplitude spectrum as a function of time: time on the horizontal axis, frequency on the vertical axis (logarithmic scale, 20 Hz…fs/2), the level in dBFS encoded by brightness. Each column is the spectrum of one block:

A column contains 128 frequency bands with logarithmic spacing; the level is rounded to 1 dB. The server stores up to 4000 most recent columns for all channels; when the frequency grid changes (fs or window length), the accumulated columns are reset.

ControlAction
original / processedSelection of the displayed signal
10 / 30 / 60 sDuration of the displayed interval
auto rangeUpper scale limit — the maximum level; lower — the 5th percentile of levels, but not below the maximum −60 dB; the scale width is at least 30 dB
from / to, dBFSManual setting of the scale limits
click / Shift+clickSetting the edge frequency f1 / f2 of the current filter (lines on the spectrogram)

The colour scale is sequential and single-hue: the level is mapped monotonically to the lightness of one hue.

Listening

Listening uses the streaming mode of the FPGA: the samples of one channel are transferred continuously at the rate fs set in the “Capture” block. The processing server performs filtering, equalization and noise reduction and passes the signal to the playback service (fpgasink) for output to the sound card of the computer running the server. Windowed measurement is unavailable during listening.

ParameterValuesDescription
original / processed—Switching without interrupting playback
Volume0…60 dBDigital gain of the reproduced signal; samples exceeding full scale are clipped and counted
Word lengthauto, 16, 24 bitsWord length of UART transfer; 24 bits if the stream fits into the channel (fs ≤ 28.8 kHz)
FPGA shift0…8 bitsMultiplication of the sample by 2s with saturation before word-length truncation

Shift. When transferring 16 bits, the FPGA sends bits [23−s : 8−s] of the sample; the server divides the received value by 2s, so that levels and processing are in the original scale. The quantization noise of the 16-bit representation is about −98 dBFS (quantization signal-to-noise ratio 6.02·16 + 1.76 ≈ 98 dB), which is below the self-noise of the INMP441 microphone (about −80 dBFS). Therefore, for the INMP441 the shift does not reduce noise; measurements confirm the same noise level at s = 0, 2, 4, 6. On saturation (|x|·2s > 223) a counter of saturated samples is displayed.

Limitations