Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.FFTWithSize

View Source On Gitee
class mindspore.ops.FFTWithSize(signal_ndim, inverse, real, norm='backward', onesided=True, signal_sizes=())[source]

Fourier transform, can be adjusted by parameters to achieve FFT/IFFT/RFFT/IRFFT.

For fft, it computes the following expression:

X[ω1,,ωd]=n1=0N11nd=0Nd1x[n1,,nd]ej 2πi=0dωiniNi,

where d = signal_ndim is number of dimensions for the signal, and Ni is the size of signal dimension i.

For ifft, it computes the following expression:

X[ω1,,ωd]=1i=1dNin1=0N11nd=0Nd1x[n1,,nd]e j 2πi=0dωiniNi,

where d = signal_ndim is number of dimensions for the signal, and Ni is the size of signal dimension i.

Note

  • FFT/IFFT requires complex64 or complex128 inputs, return complex64 or complex128 outputs.

  • RFFT requires bool, uint8, int8, int16, int32, int64, float32 and float64 inputs, return complex64 or complex128 outputs.

  • IRFFT requires complex64 or complex128 inputs, return float32 or float64 outputs.

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • signal_ndim (int) – The number of dimensions in each signal, this controls how many dimensions of the fourier transform are realized, can only be 1, 2 or 3.

  • inverse (bool) –

    Whether it is the inverse transformation, used to select from FFT and RFFT or IFFT and IRFFT.

    • when set to True: IFFT and IRFFT.

    • when set to False: FFT and RFFT.

  • real (bool) –

    Whether it is the real transformation, combines with inverse to select a specific transformation mode:

    • inverse is False , real is False : corresponds to FFT.

    • inverse is True , real is False : corresponds to IFFT.

    • inverse is False , real is True : corresponds to RFFT.

    • inverse is True , real is True : corresponds to IRFFT.

  • norm (str, optional) –

    The normalization, optional values: [ "backward" , "forward" , "ortho" ]. Default value: "backward" .

    • "backward" has the direct transforms unscaled and the inverse transforms scaled by 1/n, where n is the input x’s element numbers.

    • "ortho" has both direct and inverse transforms are scaled by 1/n.

    • "forward" has the direct transforms scaled by 1/n and the inverse transforms unscaled.

  • onesided (bool, optional) – Controls whether the input is halved to avoid redundancy. Default: True .

  • signal_sizes (tuple, optional) –

    Size of the original signal (the signal before rfft, no batch dimension), only in IRFFT mode and set onesided to True requires the parameter, the following conditions must be satisfied. Default: () .

    • The length of signal_sizes is equal to the signal_ndim of the IRFFT: len(signal_sizes)=signal_ndim.

    • The last dimension of signal_sizes divided by 2 is equal to the last dimension of the IRFFT input: signal_size[1]/2+1=x.shape[1].

    • signal_sizes has exactly the same dimensions as the input shape except for the last dimension: signal_sizes[:1]=x.shape[:1].

Inputs:
  • x (Tensor) - The dimension of the input tensor must be greater than or equal to signal_ndim.

Outputs:

A tensor containing the complex-to-complex, real-to-complex or complex-to-real Fourier transform result.

Raises
  • TypeError – If the input type of FFT/IFFT/IRFFT is not one of: complex64, complex128.

  • TypeError – If the input type is not Tensor.

  • ValueError – If x dimension is less than signal_ndim.

  • ValueError – If signal_ndim is greater than 3 or less than 1.

  • ValueError – If norm is none of “backward”, “forward” or “ortho”.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> # case FFT: signal_ndim: 1, inverse: False, real: False.
>>> fft_in = Tensor(np.array([2, 1, 2]), mindspore.complex64)
>>> fft_net = ops.FFTWithSize(signal_ndim=1, inverse=False, real=False)
>>> fft_output = fft_net(fft_in)
>>> print(fft_output)
[5.        +0.j         0.5       +0.86602545j 0.50000006-0.8660255j ]
>>> # case IFFT: signal_ndim: 1, inverse: True, real: False.
>>> ifft_in = fft_output
>>> ifft_net = ops.FFTWithSize(signal_ndim=1, inverse=True, real=False)
>>> ifft_output = ifft_net(ifft_in)
>>> print(ifft_output)
[2.        -1.9868216e-08j 0.99999994+0.0000000e+00j
 1.9999999 +7.9472862e-08j]
>>> # case RFFT2D: signal_ndim: 2, inverse: False, real: True.
>>> rfft_in = Tensor(np.array([[2, 1, 2], [3, 1, 6]]), mindspore.float32)
>>> rfft_net = ops.FFTWithSize(signal_ndim=2, inverse=False, real=True)
>>> rfft_output = rfft_net(rfft_in)
>>> print(rfft_output)
[[ 1.5000000e+01+1.1920929e-07j -2.3841858e-07+5.1961522e+00j]
 [-5.0000000e+00-2.9802322e-08j  9.9999988e-01-3.4641016e+00j]]
>>> # case IRFFT2D: signal_ndim: 2, inverse: True, real: True.
>>> irfft_in = rfft_output
>>> irfft_net = ops.FFTWithSize(signal_ndim=2, inverse=True, real=True, signal_sizes=rfft_in.shape)
>>> irfft_output = irfft_net(irfft_in)
>>> print(irfft_output)
[[2.         1.         2.        ]
 [3.         0.99999994 5.9999995 ]]