Average¶
- class acoular.process.Average¶
Bases:
InOut
Calculates the average across consecutive time samples or frequency snapshots.
The average operation is performed differently depending on the source type. If the source is a time domain source (e.g. derived from
SamplesGenerator
), the average is calculated over a certain number of time samples given bynaverage
. If the source is a frequency domain source (e.g. derived fromSpectraGenerator
), the average is calculated over a certain number of snapshots given bynaverage
.Examples
For estimate the RMS of a white noise (time-domain) signal, the average of the squared signal can be calculated:
>>> import acoular as ac >>> import numpy as np >>> >>> signal = ac.WNoiseGenerator(sample_freq=51200, numsamples=51200, rms=2.0).signal() >>> ts = ac.TimeSamples(data=signal[:, np.newaxis], sample_freq=51200) >>> tp = ac.TimePower(source=ts) >>> avg = ac.Average(source=tp, naverage=512) >>> mean_squared_value = next(avg.result(num=1)) >>> rms = np.sqrt(mean_squared_value)[0, 0] >>> print(rms) 1.9985200025816718
Here, each evaluation of the generator created by the
result()
method of theAverage
object via thenext()
function returnsnum=1
average across a snapshot of 512 samples.If the source is a frequency domain source, the average is calculated over a certain number of snapshots, defined by
naverage
.>>> fft = ac.RFFT(source=ts, block_size=64) >>> ps = ac.AutoPowerSpectra(source=fft) >>> avg = ac.Average(source=ps, naverage=16) >>> mean_power = next(avg.result(num=1)) >>> print(np.sqrt(mean_power.sum())) 2.0024960894399295
Here, the generator created by the
result()
method of theAverage
object returns the average across 16 snapshots in the frequency domain.Number of samples (time domain source) or snapshots (frequency domain source) to average over, defaults to 64.
- sample_freq = Property(depends_on='source.sample_freq, naverage')¶
Sampling frequency of the output signal, is set automatically.
- numsamples = Property(depends_on='source.numsamples, naverage')¶
Number of samples (time domain) or snapshots (frequency domain) of the output signal. Is set automatically.
- result(num)¶
Python generator that yields the output block-wise.
- Parameters:
- numinteger
This parameter defines the size of the blocks to be yielded (i.e. the number of samples per block).
- Returns:
- Average of the output of source.
Yields samples in blocks of shape (num, numchannels). The last block may be shorter than num.