
- SciPy - Home
- SciPy - Introduction
- SciPy - Environment Setup
- SciPy - Basic Functionality
- SciPy - Relationship with NumPy
- SciPy Clusters
- SciPy - Clusters
- SciPy - Hierarchical Clustering
- SciPy - K-means Clustering
- SciPy - Distance Metrics
- SciPy Constants
- SciPy - Constants
- SciPy - Mathematical Constants
- SciPy - Physical Constants
- SciPy - Unit Conversion
- SciPy - Astronomical Constants
- SciPy - Fourier Transforms
- SciPy - FFTpack
- SciPy - Discrete Fourier Transform (DFT)
- SciPy - Fast Fourier Transform (FFT)
- SciPy Integration Equations
- SciPy - Integrate Module
- SciPy - Single Integration
- SciPy - Double Integration
- SciPy - Triple Integration
- SciPy - Multiple Integration
- SciPy Differential Equations
- SciPy - Differential Equations
- SciPy - Integration of Stochastic Differential Equations
- SciPy - Integration of Ordinary Differential Equations
- SciPy - Discontinuous Functions
- SciPy - Oscillatory Functions
- SciPy - Partial Differential Equations
- SciPy Interpolation
- SciPy - Interpolate
- SciPy - Linear 1-D Interpolation
- SciPy - Polynomial 1-D Interpolation
- SciPy - Spline 1-D Interpolation
- SciPy - Grid Data Multi-Dimensional Interpolation
- SciPy - RBF Multi-Dimensional Interpolation
- SciPy - Polynomial & Spline Interpolation
- SciPy Curve Fitting
- SciPy - Curve Fitting
- SciPy - Linear Curve Fitting
- SciPy - Non-Linear Curve Fitting
- SciPy - Input & Output
- SciPy - Input & Output
- SciPy - Reading & Writing Files
- SciPy - Working with Different File Formats
- SciPy - Efficient Data Storage with HDF5
- SciPy - Data Serialization
- SciPy Linear Algebra
- SciPy - Linalg
- SciPy - Matrix Creation & Basic Operations
- SciPy - Matrix LU Decomposition
- SciPy - Matrix QU Decomposition
- SciPy - Singular Value Decomposition
- SciPy - Cholesky Decomposition
- SciPy - Solving Linear Systems
- SciPy - Eigenvalues & Eigenvectors
- SciPy Image Processing
- SciPy - Ndimage
- SciPy - Reading & Writing Images
- SciPy - Image Transformation
- SciPy - Filtering & Edge Detection
- SciPy - Top Hat Filters
- SciPy - Morphological Filters
- SciPy - Low Pass Filters
- SciPy - High Pass Filters
- SciPy - Bilateral Filter
- SciPy - Median Filter
- SciPy - Non - Linear Filters in Image Processing
- SciPy - High Boost Filter
- SciPy - Laplacian Filter
- SciPy - Morphological Operations
- SciPy - Image Segmentation
- SciPy - Thresholding in Image Segmentation
- SciPy - Region-Based Segmentation
- SciPy - Connected Component Labeling
- SciPy Optimize
- SciPy - Optimize
- SciPy - Special Matrices & Functions
- SciPy - Unconstrained Optimization
- SciPy - Constrained Optimization
- SciPy - Matrix Norms
- SciPy - Sparse Matrix
- SciPy - Frobenius Norm
- SciPy - Spectral Norm
- SciPy Condition Numbers
- SciPy - Condition Numbers
- SciPy - Linear Least Squares
- SciPy - Non-Linear Least Squares
- SciPy - Finding Roots of Scalar Functions
- SciPy - Finding Roots of Multivariate Functions
- SciPy - Signal Processing
- SciPy - Signal Filtering & Smoothing
- SciPy - Short-Time Fourier Transform
- SciPy - Wavelet Transform
- SciPy - Continuous Wavelet Transform
- SciPy - Discrete Wavelet Transform
- SciPy - Wavelet Packet Transform
- SciPy - Multi-Resolution Analysis
- SciPy - Stationary Wavelet Transform
- SciPy - Statistical Functions
- SciPy - Stats
- SciPy - Descriptive Statistics
- SciPy - Continuous Probability Distributions
- SciPy - Discrete Probability Distributions
- SciPy - Statistical Tests & Inference
- SciPy - Generating Random Samples
- SciPy - Kaplan-Meier Estimator Survival Analysis
- SciPy - Cox Proportional Hazards Model Survival Analysis
- SciPy Spatial Data
- SciPy - Spatial
- SciPy - Special Functions
- SciPy - Special Package
- SciPy Advanced Topics
- SciPy - CSGraph
- SciPy - ODR
- SciPy Useful Resources
- SciPy - Reference
- SciPy - Quick Guide
- SciPy - Cheatsheet
- SciPy - Useful Resources
- SciPy - Discussion
SciPy - dst() Function
The scipy.fft.dst() method gives the Discrete Sine Transform, which is the mathematical procedure that uses sines to transform spatial data into the frequency domain. This transform is used typically to analyze data with odd symmetry by transforming it into frequency components for processing.
The scipy.fft.dst() method supports four types of DST, each useful for a different application. Type 1 is equivalent to an FFT for real, odd-symmetric inputs. Type 2 is the most commonly used transform and therefore the standard. Type 3 is the inverse transform, useful for reconstructing data. Type 4 is for advanced applications, where the symmetry needs to be more precise.
DST performs well with DCT or FFT for full signal analysis and processing, meaning both symmetric and odd-symmetric data sets can be processed efficiently.
DST is an important technique used for signal processing, image compression, and for problems of partial differential equations. It efficiently isolates the sine wave components especially in cases of unusual boundary conditions.
Syntax
The syntax for the SciPy dst() method is as follows −
.dst(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, orthogonalize=None)
Parameters
This method accepts the following parameters −
x − The input array (spatial-domain data to be transformed).
type − The type parameter in scipy.fft.dst defines the transform variant: Type 1 for FFT-like odd-symmetric inputs, Type 2 as standard, Type 3 as its inverse, and Type 4 for advanced symmetry.
n − Length of the transform; pads or truncates input data if specified.
axis − Axis for the DST 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
dst (ndarray of reals) − The DST-transformed array, representing the frequency-domain components of the input.
Example 1: Basic DST Transformation
This example demonstrates how the DST employs sine functions to transform spatial-domain data into frequency-domain representation. The output indicates the sine wave components of the input data.
The below code, is the basic example of using the dst() method on a simple array [1, 2, 3, 4]. The result displays frequency components represented as sine coefficients.
import numpy as np import scipy.fft from scipy.fft import dst data = [1, 2, 3, 4] result = scipy.fft.dst(data) print("DST of data:", result)
When we run above program, it produces following result
DST of data: [13.06562965 -5.65685425 5.411961 -4. ]
Example 2: DST on a 2D Array
This example applies DST on a 2D array of rows, transforming each row independently into its frequency domain representation.
The dst() function is applied row-wise to the array [[3, 5, 7], [8, 6, 4]] using the default axis (axis=-1). The output is a two-dimensional array with frequency coefficients for each row.
import numpy as np import scipy.fft from scipy.fft import dst data = [1, 3, 5, 7] result = dst(data, type=1) print("DST Type 1 of data:", result)
Following is an output of the above code
DST Type 1 of data: [ 24.6214683 -13.7638192 5.81234022 -3.24919696]
Example 3: Difference Between DST and DCT
DST and DCT are two transforms which change data from spatial domain into a frequency domain but they do have different basis functions, DST uses sine waves while assuming odd symmetry thus applies to odd boundary conditions; DCT uses cosine waves and assumes even symmetry-thus perfect for smooth data or image compression.
This code passes the same input array to both dst() and dct(). DST emphasizes odd-symmetric components with sine waves, whereas DCT emphasizes even-symmetric components with cosine waves, putting an emphasis on their unique frequency representation.
import numpy as np from scipy.fft import dst, dct data = [1, 3, 5, 3] # Symmetrical-like data # Applying DST dst_result = dst(data, norm='ortho') print("DST result:", dst_result) # Applying DCT dct_result = dct(data, norm='ortho') print("DCT result:", dct_result)
Output of the above code is as follows
DST result: [ 6.30864406 -2. 0.44834153 0. ] DCT result: [ 6. -1.84775907 -2. 0.76536686]
Example 4:
This example shows how dst() and fft can work together to analyze signals. While DST isolates the odd-symmetric sine wave components, FFT captures the whole spectrum of frequencies, which is ideal for high-resolution analysis in audio processing or in vibration analysis.
import numpy as np from scipy.fft import dst, fft # Create a composite signal: sine wave + cosine wave t = np.linspace(0, 1, 100, endpoint=False) signal = np.sin(2 * np.pi * 5 * t) + 0.5 * np.cos(2 * np.pi * 10 * t) # Apply DST (focuses on sine components) dst_result = dst(signal, norm='ortho') print("DST result (odd-symmetric sine components):", dst_result[:10]) # Apply FFT (captures both sine and cosine components) fft_result = fft(signal) print("FFT result (complete frequency spectrum):", np.abs(fft_result[:10]))
Output of the above code is as follows
DST result (odd-symmetric sine components): [ 3.62017374e-03 -2.88114656e-16 1.39539925e-02 1.73632957e-16 3.74298480e-02 2.38782243e-15 1.08797404e-01 2.20833496e-16 5.47468662e-01 6.98401123e+00] FFT result (complete frequency spectrum): [1.55431223e-14 1.00830176e-14 2.14580936e-14 1.97535756e-14 2.68418810e-15 5.00000000e+01 1.44296599e-14 1.42000103e-14 7.63415081e-15 3.87440389e-15]