-
-
Notifications
You must be signed in to change notification settings - Fork 43
Cosine Transforms
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 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.
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.getOutput();
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.getOutput();
Inverse Cosine Transforms are used to recover the original signal from a Cosine Transformed signal. Similar to Cosine Transform, JDSP provides InverseDiscreteCosine and InverseFastCosine; to be used with DiscreteCosine and FastCosine 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.
For this example, we will try and perform the forward and inverse transform to see how it operates and compare the outputs visually.
STANDARD NORMALIZATION
DiscreteCosine dct = new DiscreteCosine(original_signal); //original_signal is a double[]
dct.transform(1); // Type can be 1, 2, 3 or 4
double[] outputType1 = dct.getMagintude()
InverseDiscreteCosine idct = new InverseDiscreteCosine(this.signal1);
idct.transform(1); // Must be the same as the type used for DCT
double[] recovered_signal = idct.getOutput();
If using InverseFastCosine, we can only use the Type 1 transform.
FastCosine f1 = new FastCosine(original_signal); //original_signal is a double[]
f1.transform();
double[] out = f1.getOutput();
InverseFastCosine if1 = new InverseFastCosine(out);
if1.transform();
double[] reconstructed = if1.getOutput();
ORTHOGONAL NORMALIZATION
DiscreteCosine dct = new DiscreteCosine(original_signal, DiscreteCosine.Normalization.ORTHOGONAL); //original_signal is a double[]
dct.transform(1); // Type can be 1, 2, 3 or 4
double[] outputType1 = dct.getMagintude()
InverseDiscreteCosine idct = new InverseDiscreteCosine(outputType1, InverseDiscreteCosine.Normalization.ORTHOGONAL);
idct.transform(1); // Must be the same as the type used for DCT
double[] recovered_signal = idct.getOutput();
If using InverseFastCosine, we can only use the Type 1 transform.
FastCosine f1 = new FastCosine(original_signal, FastCosine.Normalization.ORTHOGONAL); //original_signal is a double[]
f1.transform();
double[] out = f1.getOutput();
InverseFastCosine if1 = new InverseFastCosine(out, InverseFastCosine.Normalization.ORTHOGONAL);
if1.transform();
double[] reconstructed = if1.getOutput();
Wiki
-
Filters
- IIR Filters
- FIR Filters
- Kernel-Based Filter
- Adaptive Filters
-
Signals
-
Peak Detection
-
Transformations
-
Speech
-
Windowing