Saturday, September 6, 2025
HomeLanguagesJavascriptTensorflow.js tf.spectral.rfft () Function

Tensorflow.js tf.spectral.rfft () Function

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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS