HDL-MIC · Documentation

Capture: sampling and windows

The “Capture” block sets the sampling rate of the four microphone signals and the length of the block of samples (window) transferred to the computer. These parameters determine the operating frequency band, the frequency resolution, the result update rate and the fraction of time during which the signal is available for processing.

Capture parameters

ParameterValuesDetermines
Sampling rate fs7.81–48.83 kHz (8 values)Upper band limit fs/2; amount of transferred data
Window length W256, 512, 1024, 2048 samplesWindow duration W/fs; frequency resolution fs/W; window transfer time
Pause between windows0–5000 msWindow request period (0 — no pause)
Test generatoron/offReplacement of the microphone signals by a deterministic sequence

The parameters can be changed only while the measurement is stopped. A configuration is rejected if the current filter cannot be realized at the new fs (a filter cutoff frequency exceeds fs/2).

Sampling and quantization

Sampling is the representation of a continuous signal x(t) by the sequence of its values at the time instants t = n·T, where T = 1/fs is the sampling period. Quantization is the representation of each value (sample) by a number of finite word length.

Fig. 1. A 1 kHz sinusoid and its samples at fs = 8 kHz.

Sampling theorem (Kotelnikov — Nyquist — Shannon). A band-limited signal is uniquely reconstructed from its samples if its spectrum contains no components above fs/2 (the Nyquist frequency). After sampling, a component of frequency f > fs/2 is indistinguishable from a component of frequency |f − k·fs| in the range 0…fs/2. This phenomenon is called aliasing.

Fig. 2. Aliasing: the samples of a 7 kHz signal at fs = 8 kHz coincide with the samples of a 1 kHz signal (|7 − 8| = 1 kHz; phase inverted).

The INMP441 microphone contains an oversampling sigma-delta ADC and a built-in digital decimation filter. The decimation filter acts as an anti-aliasing filter: components above fs/2 are suppressed before the samples are formed. The nominal frequency range of the microphone is 60 Hz to 15 kHz; below 60 Hz the sensitivity decreases regardless of fs.

Sampling rates

The I2S bit clock (SCK) is generated by the FPGA by dividing the 50 MHz reference frequency. An I2S frame contains 64 SCK cycles (32 cycles for each of the left and right channels), so fs takes a discrete set of values:

fs = 50 MHz / (128·H),   H = 8…50;    fSCK = 64·fs = 0.5…3.125 MHz
fs, kHzfs/2, kHzApplication
48.8324.4Full audio range and high-frequency components; largest amount of data
39.06; 32.5519.5; 16.3Full operating range of the microphone (up to 15 kHz)
24.4112.2Speech, mechanical noise; continuous single-channel stream with 24-bit resolution
16.288.1Default value; engines, machinery, speech
12.21; 10.566.1; 5.3Low-frequency sources; 10.56 kHz is the maximum for continuous four-channel recording (16 bits)
7.813.9Low-frequency components; largest fraction of the signal available for processing

All microphones share the SCK and WS signals; the samples of the four channels belong to the same I2S frame. The channels are synchronous, which is required for cross-correlation analysis and direction-of-arrival estimation.

Data path

4 × INMP441
I2S, 24 bits
→ FPGA
packing: 12 bytes per sample
→ FIFO
2048 words × 96 bits
→ UART
1 Mbit/s, 8N2
→ CH340C
USB
→ fpgad

The exchange is initiated by the computer: a command (5-byte frame) requests one window. The FPGA acknowledges the command and then transmits the header AA 55 AA 55, the window number, the loss counter (2 bytes each) and W samples of 12 bytes (4 channels × 3 bytes). A window is accepted if exactly 12·W + 8 bytes are received.

Windowed mode

The windowed mode is used because the data rate required for a continuous stream exceeds the channel capacity:

Rreq = 4 channels × 3 bytes × fs;    RUART = 106 bit/s / 11 bits = 90,909 bytes/s (8N2: 11 bits per byte)
fs = 48.83 kHz: Rreq = 585,938 bytes/s = 6.4·RUART
fs = 16.28 kHz: Rreq = 195,313 bytes/s = 2.1·RUART
fs = 7.81 kHz: Rreq = 93,750 bytes/s = 1.03·RUART

Continuous transfer of four 24-bit channels is impossible at any value of fs. Therefore the FPGA operates in single-shot capture mode:

  1. on command, W consecutive samples of all channels are written into the FIFO buffer at the rate fs;
  2. transfer of samples from the FIFO to the UART starts immediately after the first sample is written and proceeds at the channel rate;
  3. after receiving the window, the computer processes it and requests the next window.

Within a window the samples follow without gaps and the channels are synchronous. Between windows the signal is not acquired.

Fig. 3. Timing diagram of the windowed mode based on measurements: signal acquisition and window transfer intervals.

Channel rate. The CH340C USB-UART converter loses data at 2 Mbit/s; at 1.5 Mbit/s rare losses occur in blocks aligned to USB packet boundaries (32 bytes). The operating rate is 1 Mbit/s. Incomplete windows (on average one in 150–300) are detected by their length and excluded from processing; their number is displayed as an error counter.

Maximum window length. The FIFO buffer of 2048 × 96 bits = 196,608 bits occupies 24 of the 30 M9K embedded memory blocks of the EP4CE6 FPGA. This limits the window length to 2048.

Streaming mode. Listening and continuous recording use a streaming mode with reduced data volume: one channel (16 bits — up to 43 kHz, 24 bits — up to 28.8 kHz) or four 16-bit channels at fs up to 10.8 kHz.

Timing characteristics

Twin = W/fs;    Ttx = (12·W + 8)·11 / 106 s;    Tcycle ≈ max(Twin, Ttx) + Tex,   Tex = 5…30 ms
duty factor η = Twin / Tcycle

Tex includes command transmission, acknowledgement and window processing. Measurement results:

fs, kHzWTwin, msTtx, msTcycle, msWindows/sη
48.832048422703003.314 %
48.832565343925.613 %
24.4151221688112.326 %
16.281024631351526.641 %

Ttx does not depend on fs, while Twin is inversely proportional to fs. Consequently, the duty factor η increases as fs decreases. If the spectrum of the signal under study is limited to 8 kHz, fs = 16.28 kHz is preferable.

Window length

CharacteristicW = 256…512W = 1024…2048
Result update rate10–25 windows/s2–7 windows/s
Frequency resolution fs/W at fs = 16.28 kHz64…32 Hz16…8 Hz
Number of periods of low-frequency components in a windowsmalllarge
Fraction of the window occupied by the filter transientlargesmall
Accuracy of direction-of-arrival estimationlowhigh

The frequency resolution of the discrete Fourier transform of a window of length W equals fs/W: components separated by less than fs/W are not resolved. The accuracy of direction estimation is determined by the window duration W/fs, so W = 2048 and fs = 10.56…24.41 kHz are preferable for it.

Pause and test generator

The pause between windows increases the window request period and does not affect window contents. It is used for long-term monitoring to reduce the load.

The test generator replaces the microphone signals by sequences generated in the FPGA: ch0 — sample counter (increment 1); ch1 — counter with inverted sign; ch2 — constant 0x123456; ch3 — the low byte of the counter repeated in the three bytes of the word. The sequences make it possible to verify the integrity of the data path: loss or shift of bytes breaks the counter increment. In this mode dBFS levels have no physical meaning.

Choosing a mode

Taskfs, kHzW
Level monitoring16.281024
Sources with bandwidth up to 2–4 kHz (engines, machinery)10.56…16.281024–2048
High-resolution spectral analysis7.81…16.282048
Direction-of-arrival estimation10.56…24.412048
Acquisition of fast level changes16.28…24.41256–512
Analysis of high-frequency components (up to 24 kHz)39.06…48.83as required
Data path verificationanyany; test generator