Skip to content

komm.fourier_transform

Computes the Fourier transform. This function applies a shift to the spectrum (so that the zero frequency component is at the center) and scales the output by a given time step. Both the spectrum and the corresponding frequency bins are returned.

Note

This is a simple wrapper around numpy.fft functions.

Parameters:

  • waveform (ArrayLike)

    The input array representing the waveform to be transformed.

  • time_step (float)

    The time step between samples in the waveform.

  • nfft (int | None)

    The number of points in the FFT. If None, it defaults to the size of the input along the specified axis.

  • axis (int)

    The axis along which to compute the Fourier transform. Default is the last axis.

Returns:

  • spectrum (NDArray[complexfloating])

    The spectrum correponding to the input waveform.

  • frequencies (NDArray[floating])

    The corresponding frequency bins.

Examples:

>>> spectrum, frequencies = komm.fourier_transform([1, 2, 3, 4], time_step=0.1)
>>> spectrum
array([-0.2+0.j , -0.2-0.2j,  1. +0.j , -0.2+0.2j])
>>> frequencies
array([-5. , -2.5,  0. ,  2.5])