Skip to content
This repository

DOC: add parameters, returns, examples to rfftfreq(), and format variables. #321

Closed
wants to merge 3 commits into from

2 participants

endolith Ralf Gommers
endolith

Also STY: spaces around operators

endolith

adapted from numpy fftfreq()

Ralf Gommers rgommers commented on the diff
scipy/fftpack/helper.py
((8 lines not shown))
12 12
13 13 f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2]/(d*n) if n is even
14 14 f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2,n/2]/(d*n) if n is odd
  15 +
  16 + Parameters
  17 + ----------
  18 + n : int
  19 + Window length.
  20 + d : scalar
1
Ralf Gommers Owner

Should be scalar, optional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
scipy/fftpack/helper.py
((12 lines not shown))
  16 + Parameters
  17 + ----------
  18 + n : int
  19 + Window length.
  20 + d : scalar
  21 + Sample spacing.
  22 +
  23 + Returns
  24 + -------
  25 + out : ndarray
  26 + The array of length `n`, containing the sample frequencies.
  27 +
  28 + Examples
  29 + --------
  30 + >>> sig = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
  31 + >>> fourier = scipy.fftpack.rfft(sig)
2
Ralf Gommers Owner

from scipy import fftpack
fourier = fftpack.rfft(sig)

Ralf Gommers Owner

How about naming this sig_fft instead of fourier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
scipy/fftpack/helper.py
((15 lines not shown))
  19 + Window length.
  20 + d : scalar
  21 + Sample spacing.
  22 +
  23 + Returns
  24 + -------
  25 + out : ndarray
  26 + The array of length `n`, containing the sample frequencies.
  27 +
  28 + Examples
  29 + --------
  30 + >>> sig = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
  31 + >>> fourier = scipy.fftpack.rfft(sig)
  32 + >>> n = fourier.size
  33 + >>> timestep = 0.1
  34 + >>> freq = scipy.fftpack.rfftfreq(n, d=timestep)
1
Ralf Gommers Owner

no scipy.`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Ralf Gommers
Owner

Merged in 217067d, thanks @endolith

endolith endolith deleted the branch
Clemens ClemensFMN referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 28 additions and 4 deletions. Show diff stats Hide diff stats

  1. +28 4 scipy/fftpack/helper.py
32 scipy/fftpack/helper.py
... ... @@ -1,18 +1,42 @@
1 1 __all__ = ['fftshift', 'ifftshift', 'fftfreq', 'rfftfreq']
2 2
3   -from numpy import array
  3 +from numpy import arange
4 4 from numpy.fft.helper import fftshift, ifftshift, fftfreq
5 5
6 6 def rfftfreq(n, d=1.0):
7 7 """DFT sample frequencies (for usage with rfft, irfft).
8 8
9 9 The returned float array contains the frequency bins in
10   - cycles/unit (with zero at the start) given a window length n and a
11   - sample spacing d::
  10 + cycles/unit (with zero at the start) given a window length `n` and a
  11 + sample spacing `d`::
12 12
13 13 f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2]/(d*n) if n is even
14 14 f = [0,1,1,2,2,...,n/2-1,n/2-1,n/2,n/2]/(d*n) if n is odd
  15 +
  16 + Parameters
  17 + ----------
  18 + n : int
  19 + Window length.
  20 + d : scalar, optional
  21 + Sample spacing. Default is 1.
  22 +
  23 + Returns
  24 + -------
  25 + out : ndarray
  26 + The array of length `n`, containing the sample frequencies.
  27 +
  28 + Examples
  29 + --------
  30 + >>> from scipy import fftpack
  31 + >>> sig = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
  32 + >>> sig_fft = fftpack.rfft(sig)
  33 + >>> n = sig_fft.size
  34 + >>> timestep = 0.1
  35 + >>> freq = fftpack.rfftfreq(n, d=timestep)
  36 + >>> freq
  37 + array([ 0. , 1.25, 1.25, 2.5 , 2.5 , 3.75, 3.75, 5. ])
  38 +
15 39 """
16 40 if not isinstance(n, int) or n < 0:
17 41 raise ValueError("n = %s is not valid. n must be a nonnegative integer." % n)
18   - return (array(range(1,n+1),dtype=int)//2)/float(n*d)
  42 + return (arange(1, n + 1, dtype=int) // 2) / float(n * d)

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.