RFFT#

class acoular.fprocess.RFFT

Bases: BaseSpectra, SpectraOut

Compute the one-sided Fast Fourier Transform (FFT) for real-valued multichannel time data.

The FFT is performed block-wise, dividing the input data into blocks of length specified by the block_size attribute. A window function can be optionally applied to each block before the FFT calculation, controlled via the window attribute.

This class provides flexibility in scaling the FFT results for different use cases, such as preserving amplitude or energy, by setting the scaling attribute.

source

Data source; an instance of SamplesGenerator or a derived object. This provides the input time-domain data for FFT processing.

workers

The number of workers to use for FFT calculation. If set to a negative value, all available logical CPUs are used. Default is None, which relies on the scipy.fft.rfft() implementation.

scaling

Defines the scaling method for the FFT result. Options are:

  • 'none': No scaling is applied.

  • 'energy': Compensates for energy loss in the FFT result due to truncation, doubling the values for frequencies other than DC and the Nyquist frequency.

  • 'amplitude': Scales the result so that the amplitude of discrete tones is independent of the block size.

block_size

The length of each block of time-domain data used for the FFT. Must be an even number. Default is 1024.

num_freqs

The number of frequency bins in the FFT result, calculated as block_size // 2 + 1.

num_samples

The total number of snapshots (blocks) available in the FFT result, determined by the size of the input data and the block size.

freqs

A 1-D array containing the Discrete Fourier Transform sample frequencies corresponding to the FFT output.

digest

A unique identifier based on the process properties.

result(num=1)

Yield the FFT results block-wise as multi-channel spectra.

This generator processes the input data block-by-block, applying the specified window function and FFT parameters. The output consists of the FFT spectra for each block, scaled according to the selected scaling method.

Parameters:
numint, optional

Number of multi-channel spectra (snapshots) per block to return. Default is 1.

Yields:
numpy.ndarray

A block of FFT spectra with shape (num, num_channels * num_freqs). The final block may contain fewer than num spectra if the input data is insufficient to fill the last block.

Notes

  • The generator compensates for energy or amplitude loss based on the scaling attribute.

  • If the input data source provides fewer samples than required for a complete block, the remaining spectra are padded or adjusted accordingly.

fftfreq()

Compute and return the Discrete Fourier Transform sample frequencies.

This method generates the frequency values corresponding to the FFT bins for the configured block_size and sampling frequency from the data source.

Returns:
numpy.ndarray or None

Array of shape ( block_size / 2 + 1,) containing the sample frequencies. If source is not set, returns None.

Examples

Using normally distributed data for time samples as in TimeSamples.

>>> import numpy as np
>>> from acoular import TimeSamples
>>> from acoular.spectra import PowerSpectra
>>>
>>> data = np.random.rand(1000, 4)
>>> ts = TimeSamples(data=data, sample_freq=51200)
>>> print(ts.num_channels, ts.num_samples, ts.sample_freq)
4 1000 51200.0
>>> ps = PowerSpectra(source=ts, block_size=128, window='Blackman')
>>> ps.fftfreq()
array([    0.,   400.,   800.,  1200.,  1600.,  2000.,  2400.,  2800.,
        3200.,  3600.,  4000.,  4400.,  4800.,  5200.,  5600.,  6000.,
        6400.,  6800.,  7200.,  7600.,  8000.,  8400.,  8800.,  9200.,
        9600., 10000., 10400., 10800., 11200., 11600., 12000., 12400.,
       12800., 13200., 13600., 14000., 14400., 14800., 15200., 15600.,
       16000., 16400., 16800., 17200., 17600., 18000., 18400., 18800.,
       19200., 19600., 20000., 20400., 20800., 21200., 21600., 22000.,
       22400., 22800., 23200., 23600., 24000., 24400., 24800., 25200.,
       25600.])
sample_freq

Sampling frequency of the output signal, delegated from source.

num_channels

Number of time microphones, delegated from source.

window

Window function applied during FFT. Can be one of:

  • 'Rectangular' (default)

  • 'Hanning'

  • 'Hamming'

  • 'Bartlett'

  • 'Blackman'

overlap

Overlap factor for FFT block averaging. One of:

  • 'None' (default)

  • '50%'

  • '75%'

  • '87.5%'

precision

Precision of the FFT, corresponding to NumPy dtypes. Default is 'complex128'.