SciPy - idst() Function



The scipy.fft.idst() method calculates the Inverse Discrete Sine Transform (IDST), which converts frequency-domain data back to spatial domain. It reverses the DST transformation to recover the original data, emphasizing odd-symmetric components.

IDST is essential for reconstructing signals, it proves vital in audio processing applications and vibration analysis or the numerical problem solving field to have data altered by DST perfectly rebuilt.

There are four types of transforms possible with the idst method. Type 1 is self-inverse and corresponds to DST Type 1. Type 2 is used most commonly and acts as the inverse of DST Type 3. Type 3 is the inverse of DST Type 2 but Type 4 is built for applications that require tight symmetry.

IDST is perfectly compatible with DST, and it provides lossless transformation and reconstruction. It is also used with FFT for the evaluation and handling of mixed-symmetry signals.

Syntax

The syntax for the SciPy idst() method is as follows −

.idst(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, orthogonalize=None)

Parameters

This method accepts the following parameters −

  • x − Input array to be transformed from the frequency domain to the spatial domain.

  • type − Specifies the type of IDST (1, 2, 3, or 4).

  • n − Length of the transform; pads or truncates input data if specified.

  • axis − Axis for the IDST in multi-dimensional arrays (default: last axis).

  • norm − The normalization mode allows control over scaling: "backward" (default, no scaling), "ortho" (unitary scaling for energy preservation), and "forward" (scales the output by 1/n, where n is the transform length).

  • overwrite_x − Modifies input to save memory if True. Fact: IDCT, when paired with DCT, provides perfect reconstruction of the original data if no coefficients are modified.

  • workers − Number of threads to use for parallel computation. Default is 1.

  • orthogonalize − Allows explicit orthogonalization for advanced use cases. Default is None.

Return Value

Transformed Array − Returns the IDST-transformed array in the spatial domain, corresponding to the original input before the DST transformation.

Example 1

This example demonstrates how the IDST may recover spatial-domain data from frequency-domain coefficients, thereby reversing the DST transformation.

In the below code, the frequency-domain array is fed into idst(), and the rebuilt spatial data is printed. The result corresponds to the original data before the DST transformation.

import numpy as np
import scipy.fft
from scipy.fft import idst

freq_data = [19.52241113, -10.3354213, -4, 1.20368834]
result = scipy.fft.idst(freq_data)
print("Reconstructed data using IDST:", result)

When we run above program, it produces following result

Reconstructed data using IDST: [-0.73275429  2.91424979  6.86929511  2.62044687]

Example 2

The n parameter in idst() controls the length of the transform, allowing the input data to be padded with zeros or truncated to match the specified length.

In this code, the length of the frequency-domain array is 5. The IDST reconstructs the spatial-domain data with n=5 and retains any padding or truncation applied in the DST transformation. The output is the original values along with zero-padding for elements beyond the length of the input data set.

import numpy as np
import scipy.fft
from scipy.fft import idst

freq_data = [32.84612239, -19.08678615, -7.5, 1.11489023, 0]
result = idst(freq_data, n=5)
print("Reconstructed data with padded input:", result)

Following is an output of the above code −

Reconstructed data with padded input: [-1.21524505  1.08950308  8.06922448  8.61267443  2.84819807]

Example 3

This example demonstrates the perfect reconstruction property of the combination of DST and IDST.

in the below code, the original data is modified using dst() and then rebuilt using idst(). The final output is that of the input, so data integrity is maintained.

from scipy.fft import dst

original_data = [3, 6, 9, 12]
freq_data = dst(original_data, norm='ortho')
reconstructed_data = dst(freq_data, norm='ortho')

print("Original Data:", original_data)
print("Frequency Data (DST):", freq_data)
print("Reconstructed Data (IDST):", reconstructed_data)

Output of the above code is as follows −

Original Data: [3, 6, 9, 12]
Frequency Data (DST): [13.85819299 -6.          5.74025149 -3.        ]
Reconstructed Data (IDST): [ 3.  6.  9. 12.]
scipy_discrete_fourier_transform.htm
Advertisements