Iterator

The streaming.iterator module is a private module. Most algorithms for streams are implemented here using basic iterators.

streaming._iterator.blocks(iterable, nblock, noverlap=0)[source]

Partition iterable into blocks.

Parameters:
  • iterable – Iterable.
  • nblock – Samples per block.
  • noverlap – Amount of samples to overlap
Returns:

Blocks.

streaming._iterator.convolve_overlap_add(signal, impulse_responses, nhop, ntaps, initial_values=None)[source]

Convolve iterable signal with time-variant impulse_responses.

Parameters:
  • signal – Signal in blocks of size nblock.
  • impulse_responses – Impulse responses of length ntaps.
  • nhop – Impulse responses is updated every nhop samples. This should correspond to the blocksize of signal.
  • ntaps – Length of impulse responses.

:param initial_values. Value to use before convolution kicks in. :returns: Convolution.

This function implements the overlap-add method. Time-variant impulse_responses is supported. Each item (`block) in signal corresponds to an impulse response (ir) in impulse_responses.

This implementation of overlap-add buffers only one segment. Therefore, only nblock>=ntaps is supported.

Warning

This function cannot be used when ntaps > nblock.

See also

convolve_overlap_save()

streaming._iterator.convolve(signal, impulse_responses, nblock, ntaps=None, initial_values=None)[source]

Convolve signal with impulse response.

Parameters:
  • signal – Signal, not in blocks.
  • impulse_responses – Impulse responses of length ntaps.
  • nblock – Blocksize to use for the convolution.
  • ntaps – Length of impulse responses.

:param initial_values. Value to use before convolution kicks in.

Note

This function takes samples and yields samples. It wraps convolve_overlap_add() and therefore requires a blocksize for computing the convolution.

streaming._iterator.convolve_overlap_discard(signal, impulse_response, nblock_in=None, nblock_out=None)[source]

Convolve signal with linear time-invariant impulse_response using overlap-discard method.

Parameters:
  • signal – Signal. Can either consists of blocks or samples. nblock_in should be set to the block size of the signal.
  • impulse_response – Linear time-invariant impulse response of filter.
  • nblock_in – Actual input blocksize of signal. Should be set to None is signal is sample-based.
  • nblock_out – Desired output blocksize.
Returns:

Convolution of signal with impulse_response.

Return type:

Generator consisting of arrays.

Setting the input blocksize can be useful because this gives control over the delay of the process. Setting the output blocksize is convenient because you know on beforehand the output blocksize. Setting neither will result in blocksize of one, or individual samples. This will be slow. Setting both is not possible.

Note

The overlap-discard method is more commonly known as overlap-save.

streaming._iterator.diff()

Differentiate iterator.

streaming._iterator.interpolate_linear()

Interpolate y for x at new positions xnew.

streaming._iterator.filter_ba(x, b, a)[source]

Apply IIR filter to x.

Parameters:
  • x – Signal.
  • b – Numerator coefficients.
  • a – Denominator coefficients.
Returns:

Filtered signal.

streaming._iterator.filter_ba_reference(x, b, a)[source]

Filter signal x with linear time-invariant IIR filter that has numerator coefficients b and denominator coefficients a.

Parameters:
  • b – Numerator coefficients.
  • a – Denominator coefficients. The first value is always a zero.
  • x – Signal.
Returns:

Filtered signal.

This function applies a linear time-invariant IIR filter using the difference equation

streaming._iterator.filter_sos(x, sos)[source]

Apply IIR filter to x.

Parameters:
  • x – Signal.
  • sos – Second-order sections.
Returns:

Filtered signal.

streaming._iterator.vdl(signal, times, delay, initial_value=0.0)[source]

Variable delay line which delays signal at ‘times’ with ‘delay’.

Parameters:
  • signal (Iterator) – Signal to be delayed.
  • delay (Iterator) – Delay.
  • initial_value – Sample to yield before first actual sample is yielded due to initial delay.

Note

Times and delay should have the same unit, e.g. both in samples or both in seconds.