Exemple #1
0
def fftshift(x, axes=None):
    """
    Shift the zero-frequency component to the center of the spectrum.
    This function swaps half-spaces for all axes listed (defaults to all).
    Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even.
    Parameters
    ----------
    x : array_like, Tensor
        Input array.
    axes : int or shape tuple, optional
        Axes over which to shift.  Default is None, which shifts all axes.
    Returns
    -------
    y : Tensor.
    """
    x = ops.convert_to_tensor_v2(x)
    if axes is None:
        axes = tuple(range(x.get_shape().ndims))
        shift = [dim // 2 for dim in x.shape]
    elif isinstance(axes, int):
        shift = x.shape[axes] // 2
    else:
        shift = [x.shape[ax] // 2 for ax in axes]

    return _roll(x, shift, axes)
def ifftshift(x, axes=None):
    #x = ops.convert_to_tensor_v2(x)
    if axes is None:
        axes = tuple(range(x.get_shape().ndims))[1:]
        shift = [-(dim // 2) for dim in x.shape.as_list()[1:]]
    elif isinstance(axes, int):
        shift = -(x.shape[axes] // 2)
    else:
        shift = [-(x.shape[ax] // 2) for ax in axes]

    return _roll(x, shift, axes)
Exemple #3
0
    def _ifftshift(self, x, axes=None):
        """
        The inverse of `fftshift`. Although identical for even-length `x`, the
        functions differ by one sample for odd-length `x`.
        Parameters
        ----------
        x : array_like, Tensor.
        axes : int or shape tuple, optional
            Axes over which to calculate.  Defaults to None, which shifts all axes.
        Returns
        -------
        y : Tensor.
        """
        if axes is None:
            axes = tuple(range(ndim(x)))
            shift = [-(dim // 2) for dim in tf.shape(x)]
        elif isinstance(axes, int):
            shift = -(tf.shape(x)[axes] // 2)
        else:
            shift = [-(tf.shape(x)[ax] // 2) for ax in axes]

        return _roll(x, shift, axes)