Fft and rfft in Tensorflow (one-dimensional data as an example)

tf.signal.fft

tf.signal.fft(
    input, name=None
)

Computes a one-dimensional discrete Fourier transform (DFT) from the innermost dimension

parameter

Input : tensor of type complex64 and complex128 (Tensor)
name : name of operation (optional)

return

A Tensor of the same type as Input.

Instructions:

a = tf.ones([4])
a_complex = tf.complex(a,tf.zeros(a.shape))  #先构造一个复数
b = tf.signal.fft(a_complex)

output
insert image description here

tf.signal.rfft

tf.signal.rfft(
    input_tensor, fft_length=None, name=None
)

Computes a one-dimensional real discrete Fourier transform (DFT) according to the innermost dimension

parameter

Input: Tensor of type float32 or float64 (Tensor)
fft_length: length of FFT
name: name of operation (optional)

return

A tensor of type Tcomplex

Instructions:

pred2 = np.random.rand(10,1)*2000
pred2 = tf.convert_to_tensor(pred2) #先构造一个实数Tensor
pred2_fft = tf.signal.rfft(pred2)

output
insert image description here

The difference between fft and rfft

We know that DFT is performed on a one-dimensional sequence, and the obtained amplitude-frequency value is mirror-symmetrical at N/2+1.
If the shape of the input sequence is (10,)
tf.signal.fft also gets (10,)
insert image description here

tf.signal.rfft gets (6,)
insert image description here

Guess you like

Origin blog.csdn.net/aa2962985/article/details/123858409