Skip to content

Sine Transforms

psambit9791 edited this page Dec 18, 2023 · 7 revisions

Forward Sine Transform

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

This library implements 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:

DiscreteSine dst = new DiscreteSine(signal); //signal is a double[]

// Type 1 
dst.transform(1);
// OR
dst.transform();
double[] outputType1 = dst.getOutput()

// Type 2 
dst.transform(2);
double[] outputType2 = dst.getOutput()

// Type 3
dst.transform(3);
double[] outputType3 = dst.getOutput()

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

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

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

dft

ORTHOGONAL NORMALIZATION

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

Fast Sine Transform is again limited to Type 1.

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

dft


Inverse Sine Transform

Inverse Sine Transforms are used to recover the original signal from a Sine Transformed signal. Similar to Sine Transform, JDSP provides InverseDiscreteSine and InverseFastSine; to be used with DiscreteSine and FastSine respectively.

If the normalisation is set to ORTHOGONAL, the output of the the inverse transform is in the same scale as the original signal. If not, the scale may change.

The examples provided here use this as the original signal:

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

Example Usage

For this example, we will try and perform the forward and inverse transform to see how it operates and compare the outputs visually.

CODE

STANDARD NORMALIZATION

DiscreteSine dst = new DiscreteSine(original_signal); //original_signal is a double[]
dst.transform(1); // Type can be 1, 2, 3 or 4
double[] outputType1 = dst.getOutput()

InverseDiscreteSine idst = new InverseDiscreteSine(outputType1);
idst.transform(1); // Must be the same as the type used for DST
double[] recovered_signal = idst.getOutput();

If using InverseFastSine, we can only use the Type 1 transform.

FastSine f1 = new FastSine(original_signal); //original_signal is a double[]
f1.transform();
double[] out = f1.getOutput();

InverseFastSine if1 = new InverseFastSine(out);
if1.transform();
double[] reconstructed = if1.getOutput();

dft

ORTHOGONAL NORMALIZATION

DiscreteSine dst = new DiscreteSine(original_signal, DiscreteSine.Normalization.ORTHOGONAL); //original_signal is a double[]
dst.transform(1); // Type can be 1, 2, 3 or 4
double[] outputType1 = dst.getOutput()

InverseDiscreteSine idst = new InverseDiscreteSine(outputType1, InverseDiscreteSine.Normalization.ORTHOGONAL);
idst.transform(1); // Must be the same as the type used for DST
double[] recovered_signal = idst.getOutput();

If using InverseFastSine, we can only use the Type 1 transform.

FastSine f1 = new FastSine(original_signal, FastSine.Normalization.ORTHOGONAL); //original_signal is a double[]
f1.transform();
double[] out = f1.getOutput();

InverseFastSine if1 = new InverseFastSine(out, InverseFastSine.Normalization.ORTHOGONAL);
if1.transform();
double[] reconstructed = if1.getOutput();

dft

Clone this wiki locally