Skip to content

Cosine Transforms

psambit9791 edited this page Dec 10, 2023 · 7 revisions

Forward Cosine Transform

The DiscreteCosine and FastCosine classes decomposes a finite sequence of data points in terms of a sum of cosine functions of different frequencies. This is different from the Fourier transform which decomposes the input signal into both sine and cosine functions.

This class incorporates 4 of the 8 types of transforms - Type I - IV. Refer to this link for more details about each type - and their utlities.

The examples provided here use this signal:

$\sin(40\pi t) + \frac{1}{2}\sin(400\pi t)$

signal

CODE

STANDARD NORMALIZATION

If using DCT, we can use all types 1 to 4, while performing the transformation:

DiscreteCosine dct = new DiscreteCosine(signal); //signal is a double[]

// Type 1 
dct.transform(1);
double[] outputType1 = dct.getMagintude()

// Type 2 
dct.transform(2);
double[] outputType2 = dct.getMagintude()

// Type 3
dct.transform(3);
double[] outputType3 = dct.getMagintude()

// Type 4
dct.transform(4);
double[] outputType4 = dct.getMagintude()

Fast Cosine Transform is a more efficient implementation but only exists for Type 1 Transform. This acts as a wrapper on top of Apache Math 3's implementation of FastCosineTransformer

FastCosine f1 = new FastCosine(signal); //signal is a double[]
f1.transform();
double[] out = f1.getMagnitude();

dft

ORTHOGONAL NORMALIZATION

If using DCT, we can use all types 1 to 4, while performing the transformation:

DiscreteCosine dct = new DiscreteCosine(signal, DiscreteCosine.Normalization.ORTHOGONAL); //signal is a double[]
dct.transform(1); // Type can be 1, 2, 3 or 4
double[] outputType1 = dct.getMagintude()

Fast Cosine Transform is a more efficient implementation but only exists for Type 1 Transform. This acts as a wrapper on top of Apache Math 3's implementation of FastCosineTransformer

FastCosine f1 = new FastCosine(signal, FastCosine.Normalization.ORTHOGONAL); //signal is a double[]
f1.transform();
double[] out = f1.getMagnitude();

dft


Inverse Cosine Transform

Clone this wiki locally