~jtaylor/ubuntu/precise/python-numpy/multiarch-fix-818867

« back to all changes in this revision

Viewing changes to numpy/fft/helper.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-10-07 10:19:13 UTC
  • mfrom: (7.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20101007101913-8b1kmt8ho4upcl9s
Tags: 1:1.4.1-5
* debian/patches/10_use_local_python.org_object.inv_sphinx.diff
  - fixed small typo in description
* debian/patches/changeset_r8364.diff
  - fix memory corruption (double free); thanks to Joseph Barillari for the
    report and to Michael Gilbert for pushing resolution; Closes: #581058

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
def fftshift(x,axes=None):
13
13
    """
14
 
    Shift zero-frequency component to center of spectrum.
 
14
    Shift the zero-frequency component to the center of the spectrum.
15
15
 
16
16
    This function swaps half-spaces for all axes listed (defaults to all).
17
 
    If len(x) is even then the Nyquist component is y[0].
 
17
    Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even.
18
18
 
19
19
    Parameters
20
20
    ----------
21
21
    x : array_like
22
22
        Input array.
23
23
    axes : int or shape tuple, optional
24
 
        Axes over which to shift.  Default is None which shifts all axes.
 
24
        Axes over which to shift.  Default is None, which shifts all axes.
 
25
 
 
26
    Returns
 
27
    -------
 
28
    y : ndarray
 
29
        The shifted array.
25
30
 
26
31
    See Also
27
32
    --------
28
 
    ifftshift
 
33
    ifftshift : The inverse of `fftshift`.
 
34
 
 
35
    Examples
 
36
    --------
 
37
    >>> freqs = np.fft.fftfreq(10, 0.1)
 
38
    >>> freqs
 
39
    array([ 0.,  1.,  2.,  3.,  4., -5., -4., -3., -2., -1.])
 
40
    >>> np.fft.fftshift(freqs)
 
41
    array([-5., -4., -3., -2., -1.,  0.,  1.,  2.,  3.,  4.])
 
42
 
 
43
    Shift the zero-frequency component only along the second axis:
 
44
 
 
45
    >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
 
46
    >>> freqs
 
47
    array([[ 0.,  1.,  2.],
 
48
           [ 3.,  4., -4.],
 
49
           [-3., -2., -1.]])
 
50
    >>> np.fft.fftshift(freqs, axes=(1,))
 
51
    array([[ 2.,  0.,  1.],
 
52
           [-4.,  3.,  4.],
 
53
           [-1., -3., -2.]])
29
54
 
30
55
    """
31
56
    tmp = asarray(x)
43
68
 
44
69
def ifftshift(x,axes=None):
45
70
    """
46
 
    Inverse of fftshift.
 
71
    The inverse of fftshift.
47
72
 
48
73
    Parameters
49
74
    ----------
50
75
    x : array_like
51
76
        Input array.
52
77
    axes : int or shape tuple, optional
53
 
        Axes over which to calculate.  Defaults to None which is over all axes.
 
78
        Axes over which to calculate.  Defaults to None, which shifts all axes.
 
79
 
 
80
    Returns
 
81
    -------
 
82
    y : ndarray
 
83
        The shifted array.
54
84
 
55
85
    See Also
56
86
    --------
57
 
    fftshift
 
87
    fftshift : Shift zero-frequency component to the center of the spectrum.
 
88
 
 
89
    Examples
 
90
    --------
 
91
    >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3)
 
92
    >>> freqs
 
93
    array([[ 0.,  1.,  2.],
 
94
           [ 3.,  4., -4.],
 
95
           [-3., -2., -1.]])
 
96
    >>> np.fft.ifftshift(np.fft.fftshift(freqs))
 
97
    array([[ 0.,  1.,  2.],
 
98
           [ 3.,  4., -4.],
 
99
           [-3., -2., -1.]])
58
100
 
59
101
    """
60
102
    tmp = asarray(x)
71
113
 
72
114
def fftfreq(n,d=1.0):
73
115
    """
74
 
    Discrete Fourier Transform sample frequencies.
 
116
    Return the Discrete Fourier Transform sample frequencies.
75
117
 
76
118
    The returned float array contains the frequency bins in
77
119
    cycles/unit (with zero at the start) given a window length `n` and a
78
 
    sample spacing `d`.
79
 
    ::
 
120
    sample spacing `d`::
80
121
 
81
 
      f = [0,1,...,n/2-1,-n/2,...,-1]/(d*n)         if n is even
82
 
      f = [0,1,...,(n-1)/2,-(n-1)/2,...,-1]/(d*n)   if n is odd
 
122
      f = [0, 1, ..., n/2-1, -n/2, ..., -1] / (d*n)         if n is even
 
123
      f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n)   if n is odd
83
124
 
84
125
    Parameters
85
126
    ----------
90
131
 
91
132
    Returns
92
133
    -------
93
 
    out : ndarray, shape(`n`,)
94
 
        Sample frequencies.
 
134
    out : ndarray
 
135
        The array of length `n`, containing the sample frequencies.
95
136
 
96
137
    Examples
97
138
    --------
98
 
    >>> signal = np.array([-2.,  8., -6.,  4.,  1., 0.,  3.,  5.])
 
139
    >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float)
99
140
    >>> fourier = np.fft.fft(signal)
100
 
    >>> n = len(signal)
 
141
    >>> n = signal.size
101
142
    >>> timestep = 0.1
102
143
    >>> freq = np.fft.fftfreq(n, d=timestep)
103
144
    >>> freq