Friday, September 27, 2024
Google search engine
HomeLanguagesJavascriptTensorflow.js tf.spectral.fft () Function

Tensorflow.js tf.spectral.fft () 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.fft() function is used for FFT(Fast Fourier transform) i.e. it computes the specified 1-dimensional DFT(discrete Fourier transform) over the inner-most dimension of the input.

Syntax:  

tf.spectral.fft(input)

Parameters:

  • input: The complex input on which an fft is being performed.

Return Value: It returns the result for the computation of the specified 1-dimensional DFT(discrete Fourier transform) over the inner-most dimension of the input.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a real and imaginary 1D input values
const real = tf.tensor1d([1]);
const imag = tf.tensor1d([2]);
const x = tf.complex(real, imag);
  
// Calling the .spectral.fft() function
// over the input parameter value x
tf.spectral.fft(x).print();


Output:

Tensor
    [1 + 2j]

Example 2:

Javascript




// Importing the tensorflow library
import * as tf from "@tensorflow/tfjs"
  
// Using a real and imaginary 1D input values as the
// parameter for the .complex() function
const x = tf.complex(tf.tensor1d([1, 3, 5]), tf.tensor1d([2, 4, 6]));
  
// Calling the .spectral.fft() function
// over the input parameter value x
tf.spectral.fft(x).print();


Output:

Tensor
   [9 + 12j, -4.7320504 + -1.2679477j, 
   -1.2679505 + -4.7320504j]

Reference: https://js.tensorflow.org/api/latest/#spectral.fft

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

Recent Comments