Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.spectral.rfft() function is used for RFFT(real value input Fast Fourier transform) i.e. it computes the 1-dimensional DFT(Discrete Fourier transform) over the inner-most dimension of the real input value.
Syntax:
tf.spectral.rfft(input, fftLength)
Parameters:
- input: The complex input on which an rfft is being performed.
- fftLength: It is an optional parameter.
Return Value: It returns the result for the computation of the 1-dimensional DFT(Discrete Fourier transform) over the inner-most dimension of the real input value.
Example 1:
Javascript
// Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Initializing a real 1D input values const real = tf.tensor1d([2, 4, 6]); // Calling the .spectral.rfft() function real.rfft().print(); |
Output:
Tensor [12 + 0j, -2.999999 + 1.7320514j]
Example 2:
Javascript
// Importing the tensorflow library import * as tf from "@tensorflow/tfjs" // Using a real 1D input values for // the .rfft() function tf.tensor1d([1, 2, 3, 4]).rfft().print(); |
Output:
Tensor [10 + 0j, -2 + 2j, -2 + 0j]
Reference: https://js.tensorflow.org/api/latest/#spectral.rfft