Calib#

class acoular.calib.Calib

Bases: InOut

Processing block for handling calibration data in *.xml or NumPy format.

This class implements the application of calibration factors to the data obtained from its source. The calibrated data can be accessed (e.g. for use in a block chain) via the result() generator. Depending on the source type, calibration can be performed in the time or frequency domain.

Examples

Consider calibrating a time signal by specifying the calibration factors in NumPy format. Assume that the following white noise signal is in Volt and the sensitivity of the virtual sensor is 1e-2 V/Pa. Then, the voltage signal can be converted to a calibrated sound pressure signal by multiplying it with a calibration factor of 100 Pa/V.

>>> import acoular as ac
>>> import numpy as np
>>>
>>> signal = ac.WNoiseGenerator(sample_freq=51200,
>>>                             num_samples=51200,
>>>                             rms=0.01).signal()
>>> ts = ac.TimeSamples(data=signal[:, np.newaxis], sample_freq=51200)
>>> calib = ac.Calib(source=ts)
>>> calib.data = np.array([100])
>>> print(next(calib.result(num=1)))
[[1.76405235]]

The calibrated data can then be further processed, e.g. by calculating the FFT of the calibrated data.

>>> fft = ac.RFFT(source=calib, block_size=16)
>>> print(next(fft.result(num=1)))
[[10.63879909+0.j          3.25957562-1.57652611j -2.27342854-3.39108312j
0.07458428+0.49657939j  1.772696  +3.92233098j  3.19543248+0.17988554j
0.3379041 -3.93342331j  0.93949242+2.5328611j   2.97352574+0.j        ]]

One could also apply the calibration after the FFT calculation.

>>> fft = ac.RFFT(source=ts, block_size=16)
>>> calib = ac.Calib(source=fft)
>>> calib.data = 100 * np.ones(ts.num_channels * fft.num_freqs)
>>> print(next(calib.result(num=1)))
[[10.63879909+0.j          3.25957562-1.57652611j -2.27342854-3.39108312j
0.07458428+0.49657939j  1.772696  +3.92233098j  3.19543248+0.17988554j
0.3379041 -3.93342331j  0.93949242+2.5328611j   2.97352574+0.j        ]]

This class serves as interface to load calibration data for the used microphone array. The calibration factors are stored as [Pa/unit].

file

Name of the .xml file to be imported.

num_mics

Number of microphones in the calibration data, is set automatically when read from file or when data is set.

data

Array of calibration factors, is set automatically when read from file. Can be set manually by specifying a NumPy array with shape (num_channels, ) if source yields time domain signals. For frequency domain signals, the expected shape is (num_channels * num_freqs).

invalid_channels

Channels that are to be treated as invalid.

channels

Channel mask to serve as an index for all valid channels, is set automatically.

digest

A unique identifier for the object, based on its properties. (read-only)

result(num)

Python generator that processes the source data and yields the time-signal block-wise.

This method needs to be implemented by the derived classes.

Parameters:
numint

This parameter defines the size of the blocks to be yielded (i.e. the number of samples per block)

Yields:
numpy.ndarray

Two-dimensional output data block of shape (num, sourcechannels) where sourcechannels is num_channels if the source data is in the time domain or sourcechannels is num_channels*num_freqs if the source data is in the frequency domain.

source

Data source; Generator or derived object.

sample_freq

Sampling frequency of output signal, as given by source.

num_channels

Number of channels in output, as given by source.

num_freqs

Number of frequencies in output, as given by source.

num_samples

Number of samples / snapshots in output, as given by source.

freqs

1-D array of frequencies

block_size

The length of the block used to calculate the spectra