logBinSpectrum.logBinSpectrum

logBinSpectrum.logBinSpectrum(f, y, N, f_min, f_max)[source]

Perform logarithmic binning of spectral data.

This function bins spectral data using logarithmically spaced frequency intervals. The zero frequency component is handled separately in the first bin.

Parameters:
  • f (numpy.ndarray) – Frequency array [Hz] Must be monotonically increasing First element should be 0 Hz

  • y (numpy.ndarray) – Spectral values array Must be same length as f

  • N (int) – Number of logarithmic bins Must be > 1

  • f_min (float) – Minimum frequency for binning [Hz] Must be > 0

  • f_max (float) – Maximum frequency for binning [Hz] Must be > f_min

Returns:

[f_out, y_out] where: f_out : numpy.ndarray

Logarithmically binned frequencies [Hz] Length = N f_out[0] = 0 for zero frequency

y_outnumpy.ndarray

Binned spectral values Length = N y_out[0] = y[0] for zero frequency

Return type:

list

Notes

  1. Bin edges are calculated as: exp(linspace(log(f_min), log(f_max), N))

  2. Bin centers are geometric means of edges

  3. Values within each bin are arithmetically averaged

  4. Warnings are suppressed during computation

  5. NaN is used for empty bins

Examples

>>> f = np.linspace(0, 10, 1000)
>>> y = np.sin(2*np.pi*f)
>>> f_binned, y_binned = logBinSpectrum(f, y, 20, 0.1, 10)