Acoular 25.04 documentation

BaseSpectra

«  spectra   ::   spectra   ::   PowerSpectra  »

BaseSpectra

class acoular.spectra.BaseSpectra

Bases: ABCHasStrictTraits

Base class for handling spectral data in Acoular.

This class defines the basic structure and functionality for computing and managing spectral data derived from time-domain signals. It includes properties for configuring the Fast Fourier Transformation (FFT), including overlap, and other parameters critical for spectral analysis.

source = Instance(SamplesGenerator)

Data source; an instance of SamplesGenerator or derived object.

sample_freq = Delegate('source')

Sampling frequency of the output signal, delegated from source.

num_channels = Delegate('source')

Number of time microphones, delegated from source.

window = Map(

Window function applied during FFT. Can be one of:

  • 'Rectangular' (default)

  • 'Hanning'

  • 'Hamming'

  • 'Bartlett'

  • 'Blackman'

overlap = Map({'None': 1, '50%': 2, '75%': 4, '87.5%': 8}, default_value='None', desc='overlap of FFT blocks')

Overlap factor for FFT block averaging. One of:

  • 'None' (default)

  • '50%'

  • '75%'

  • '87.5%'

block_size = Enum(

FFT block size. Must be one of: 128, 256, 512, 1024, … 65536. Default is 1024.

precision = Enum('complex128', 'complex64', desc='precision of the fft')

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

digest = Property(depends_on=['precision', 'block_size', 'window', 'overlap'])

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

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.])

«  spectra   ::   spectra   ::   PowerSpectra  »