Advanced maths

Discrete sine and cosine transform calculator with inverse

This calculator computes orthonormal discrete sine and cosine transforms of types I through IV and reconstructs the input with the transpose transform matrix.

Your numbers

2–64 values.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

This calculator computes orthonormal discrete sine and cosine transforms of types I through IV and reconstructs the input with the transpose transform matrix. Endpoint scaling is included in the definition, making coefficient energy equal to signal energy up to roundoff. It reports coefficients and reconstructed samples without deleting any band.

THE FORMULAc=Qx, x=Qᵀc, QᵀQ=I; type-II DCT uses Q_kj=sqrt(2/n) α_k cos(π(j+1/2)k/n).

A worked example

For values 1,2,3,4 and a type-II orthonormal DCT, the constant coefficient is five because the normalized constant basis is (1/2,1/2,1/2,1/2). The input energy is thirty. Applying the transpose to all four coefficients reconstructs the original four values.

Good to know

Real signals of length 2–64, types I–IV, orthonormal endpoint-orthogonalized convention. No default unnormalized library scaling, image block transform, coefficient thresholding or padding. The page does not infer physical boundary conditions from a sample list.

Cosine and sine bases imply different extensions

Cosine transforms correspond to even reflection conventions and sine transforms to odd ones, with the location of reflection depending on the type. The different half-sample shifts explain why type II and type IV coefficients differ for the same values. Choosing a type is part of defining the basis, not a cosmetic output preference.

The type-II cosine formula uses a half-index shift on the sample coordinate and a special normalization for the constant mode. Type-I cosine scaling also treats both endpoints differently. These endpoint factors are needed to make the matrix orthogonal; dropping them gives a related transform with a different inverse normalization.

The orthonormal type two DCT separates the constant component(1 + 2 + 3 + 4) / 2 = c0 = 5Constant-mode energy: 25Other coefficient energy: 30 − 25 = 5Forward Q; inverse Qᵀ; QᵀQ = I
For samples (1,2,3,4), the normalized constant vector is (1/2,1/2,1/2,1/2), so c0=5. Input energy is 30 and the remaining coefficient energy is five. Transpose synthesis restores all four original values.

The Discrete Fourier transform calculator for complex sequences covers a related task. This page focuses on discrete sine and cosine transform calculator with inverse with the method limits and worked example described below.

The inverse is determined by the matrix convention

With the orthonormal matrices used here, transposition is sufficient for inversion. Types I and IV are self-inverse, while types II and III are transpose partners within the same family. Applying type II twice is therefore not generally the inverse, despite both calls being valid forward transforms.

Some libraries combine a norm option with a separate endpoint-orthogonalization option. Matching only a transform name is not enough for coefficient comparison. This page consistently uses the fully orthogonalized matrices and checks reconstruction with those exact same basis entries, avoiding ambiguous hidden scale factors.

Energy and round-trip checks serve different purposes

The reconstruction maximum error measures the largest difference in the original sample coordinates. The energy comparison checks the sum of coefficient squares against the sum of sample squares. Both should be close under floating-point roundoff when the full coefficient vector is retained, but neither is a claim that compressed coefficients would preserve the signal.

The related complex DFT calculator represents data using rotating complex exponentials. A DCT or DST uses real basis functions and different implied reflection conventions. The returned values can be useful in compression or boundary-value calculations, but interpreting an individual coefficient requires the declared family, type and normalization.

A few questions, answered

Why does another package show doubled coefficients?

Its normalization or endpoint orthogonalization may differ. Compare both settings, not only the transform type.

Is type II its own inverse?

No. Under this convention type III is its transpose partner.

Find your calculator

Start typing to explore the library.