tatb06-fft package#
Submodules#
tatb06-fft.dft module#
Contains DFT and inverse DFT algorithms
- tatb06_fft.dft.dft(a: numpy.typing.ArrayLike, variant: str = 'explicit') numpy.typing.NDArray.numpy.complex128[source]#
Computes the Fourier transform of the input data using the DFT-matrix
- Parameters:
a (ArrayLike) – Input array, can be real or complex
variant (str) – The implementation used, can be ‘explicit’ or ‘implicit’. (Default ‘explicit’)
- Returns:
The transformed array
- Return type:
NDArray[complex128]
- tatb06_fft.dft.idft(a: numpy.typing.ArrayLike, variant: str = 'explicit') numpy.typing.NDArray.numpy.complex128[source]#
Computes the inverse Fourier transform of the input data using the DFT-matrix
- Parameters:
a (ArrayLike) – Input array, can be real or complex
variant (str) – The implementation used, can be ‘explicit’ or ‘implicit’. (Default ‘explicit’)
- Returns:
The transformed array
- Return type:
NDArray[complex128]
tatb06-fft.fft module#
Contains algorithms for the FFT
- tatb06_fft.fft.fft(a: numpy.typing.ArrayLike, variant: str = 'python_iter') tuple[numpy.typing.NDArray.numpy.complex128, int][source]#
Computes the Fourier transform of the input data using the Cooley–Tukey FFT algorithm.
Pads the input array with zeros at the tail if its length is not a power of two.
- Parameters:
a (ArrayLike) – Input array, can be real or complex
variant (str) – The implementation used, can be ‘python_iter’, ‘python_recur’, ‘rust_iter’, ‘rust_recur’, ‘rust_parallell’. (Default ‘python_iter’).
- Returns:
A tuple containing the transformed array and with how many zeros the array was padded.
- Return type:
tuple[NDArray[complex128], int]
- tatb06_fft.fft.ifft(a: numpy.typing.ArrayLike, variant: str = 'python_iter') tuple[numpy.typing.NDArray.numpy.complex128, int][source]#
Computes the inverse Fourier transform of the input data using the Cooley–Tukey FFT algorithm
Pads the input array with zeros at the center (i.e. at the high frequencies) if its length is not a power of two.
- Parameters:
a (ArrayLike) – Input array, can be real or complex
variant (str) – The implementation used, can be ‘python_iter’, ‘python_recur’, ‘rust_iter’, ‘rust_recur’, ‘rust_parallell’. (Default ‘python_iter’).
- Returns:
A tuple containing the transformed array and with how many zeros the array was padded.
- Return type:
tuple[NDArray[complex128], int]
tatb06-fft.tools module#
Contains helper functions for generating signals, plotting, and measuring function execution time
- tatb06_fft.tools.generate_cosine_signal(parameters: list[tuple[float, float]], resolution: int) numpy.typing.NDArray.numpy.float64[source]#
Generates a signal on [0,1] using multiple cosine waves with the given parameters.
- Parameters:
parameters (list[tuple[float, float]]) – A list containing the amplitudes and frequencies for the different cosine waves. The layout should be [(amp1, freq1), (amp2, freq2), …].
resolution (int) – How many samples of the signal to return
- Return type:
NDArray[float64]
- tatb06_fft.tools.generate_sine_signal(parameters: list[tuple[float, float]], resolution: int) numpy.typing.NDArray.numpy.float64[source]#
Generates a signal on [0,2*pi] using multiple sine waves with the given parameters.
- Parameters:
parameters (list[tuple[float, float]]) – A list containing the amplitudes and frequencies for the different sine waves. The layout should be [(amp1, freq1), (amp2, freq2), …].
resolution (int) – How many samples of the signal to return
- Return type:
NDArray[float64]
- tatb06_fft.tools.plot_magnitude_stem(a: numpy.typing.ArrayLike, title: str = '', reorder: bool = True, show: bool = True) None[source]#
Plots a magnitude stem of the input data in a new figure.
- Parameters:
a (ArrayLike) – Input array, can be real or complex
title (str) – Title of the figure
show (bool) – If set to True, run plt.show() after plotting the stem. Should be False if you want to plot multiple plots
- Reorder:
If set to True, reorder the data using reorder_frequencies() before plotting.
- tatb06_fft.tools.reorder_frequencies(a: numpy.typing.ArrayLike) numpy.typing.ArrayLike[source]#
Moves the second half of the frequency data to the front for correct visualization.
In the output of the FFT algorithm, the first half of the data corresponds to the frequencies 0 to N/2, and the second half corresponds to -N/2 to just below 0, which is why the reordering is needed.
- Parameters:
a (ArrayLike) – Input array, can be real or complex
- tatb06_fft.tools.time_function(f, args, n_samples=5)[source]#
Runs the given function a number of times and returns the average execution time.
- Parameters:
f – The function to measure
args (list) – A list containing the positional arguments sent to the function
n_samples – The number of samples to take, i.e. how many times the function is run
- Returns:
The mean execution time of the function calls