Skip to content

Conversation

@cval26
Copy link
Contributor

@cval26 cval26 commented Feb 16, 2023

This PR adds two functions that return the integer frequency (or wavenumber) values involved in the discrete Fourier transform performed, in the same order as the Fourier coefficients are returned by the corresponding transform calls. In particular,

  1. fftfreq(n) returns the frequency values that correspond to the coefficients calculated by fft(n) or equivalently zfftf(n, ...), in the standard order (zero frequency first).
  2. rfftfreq(n) returns the frequency values that correspond to the coefficients calculated by rfft(n) or equivalently dfftf(n, ...), in the standard order (zero frequency first).

My main motivation for writing fftfreq is its use in spectral methods for integrating PDEs, where multiplying the original Fourier coefficients by the imaginary unit and their frequencies is used to calculate the Fourier coefficients of the derivative of the original data. That property is also employed in two of the tests included for fftfreq.

Note that the functions return the integer frequency values; they do not divide by the FFT's length. Returning integer values also has the benefit that when/if multiplied by the user's real or complex data, the result gets automatically promoted to the real or complex precision used.

All tests run successfully in my local build.

@cval26
Copy link
Contributor Author

cval26 commented Feb 24, 2023

I apologize for the diff noise in the documentation file fftpack.md. My editor must have removed the trailing whitespace automatically from various lines, and I didn't realize that before committing.

My intended changes are from line 1383 downward.

EDIT: any updates on this? @zoziha

@zoziha
Copy link
Contributor

zoziha commented Feb 26, 2023

Thank you @cval26 . It looks good.

@zoziha zoziha merged commit c1a11e9 into fortran-lang:main Feb 26, 2023
@cval26 cval26 deleted the fft-frequencies branch February 26, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants