aspcore.fouriertransform

Methods for discrete Fourier transform, and linear convolution and correlation in the frequency domain

The forward transforms will operate on the last axis, and put the resulting frequency axis first. The inverse transforms will operate on the first axis and put the resulting time axis last. A time domain sample can be accessed as time_signal[…,n] A frequency domain sample can be accessed as freq_signal[f,…]

The motivation is that the methods are build for multichannel audio processing, where the assumption is that only 1-D FFTs are needed. The most common use case is that time domain processing operates directly on the last axis, and frequency domain processing operates on the channel axes, but broadcasts over the frequency axis. This behaviour for the transforms results in much fewer transpositions, and makes the code more readable.

Important

Note the time convention, which is not the same as in the numpy.fft module. This is to achieve consistency with the acoustics literature that is used for the sound field analysis modules. The definition of the DFT is u(k) = sum_{n=0}^{N-1} u[n] e^{i 2pi k n / N}, for frequency bins k = 0, 1, …, N-1, and the definition of the Inverse DFT is u[n] = rac{1}{N} sum_{k=0}^{N-1} u(k) e^{-i 2pi k n / N}.

It can be viewed as a direct consequence of choosing the definition of a plane wave propagating in the d direction to be u(r) = e^{i k r^T d}, where k is the wavenumber.

The following methods can be helpful for filtering using frequency-domain filters when multiple channels are involved. When possible, for correlation and convolution the functions will zero-pad the signals correctly in order to avoid circular convolution.

In particular, the functions can be useful frequency domain adaptive filters, where overlap-save is used for both linear convolutions and correlations. It can be tricky there to get the zero-padding right.

References

Functions

convolve_euclidian_ff(freq_filter, freq_signal)

Convolves every channel of input with every channel of the filter

convolve_euclidian_ft(freq_filter, time_signal)

Convolves every channel of input with every channel of the filter

convolve_sum(freq_filter, time_signal)

Performs linear convolution between a time-domain signal and a frequency-domain filter

correlate_cartesian_tt(time_filter, time_signal)

Computes the linear correlation between two time-domain signals

correlate_euclidian_ff(freq_filter, freq_signal)

Correlates every channel of input with every channel of the filter

correlate_euclidian_ft(freq_filter, time_signal)

Correlates every channel of input with every channel of the filter

correlate_euclidian_tf(time_filter, freq_signal)

Correlates every channel of input with every channel of the filter

correlate_sum_ff(freq_filter, freq_signal)

Computes linear correlation between two frequency-domain signals

correlate_sum_ft(freq_filter, time_signal)

Computes linear correlation between a time-domain signal and a frequency-domain filter

correlate_sum_tf(time_filter, freq_signal)

Computes linear correlation between a frequency-domain signal and a time-domain filter

correlate_sum_tt(time_filter, time_signal)

Computes linear correlation between two time-domain signals

dft_vector(freq_idx, dft_len)

All exponential values to calculate the DFT for a specific frequency bin

fft(time_sig[, n])

Computes the FFT

get_angular_freqs(num_freq, samplerate)

Returns the angular frequencies associated with the sampled frequencies of the DFT

get_freqs(num_freq, samplerate)

Returns the sampled frequencies in Hz for a discrete Fourier transform

get_real_angular_freqs(num_freq, samplerate)

Returns angular frequencies associated with the real frequencies of the DFT

get_real_freqs(num_freq, samplerate)

Returns the real sampled frequencies in Hz for a discrete Fourier transform

get_real_wavenum(num_freq, samplerate, c)

Get wave numbers associated with the real frequencies of the DFT

get_wavenum(num_freq, samplerate, c)

Returns the wave numbers associated with the sampled frequencies of the DFT

idft_vector(freq_idx, dft_len)

All exponential values to calculate the IDFT for a specific output time step

ifft(freq_signal)

Computes the inverse FFT

insert_negative_frequencies(freq_signal, even)

Inserts the values associated with negative frequencies.

irfft(freq_signal[, n])

Inverse FFT, and moves the first axis to the last axis

rfft(time_sig[, n])

Computes the real FFT