Transforms

Provides a demonstration of using Fourier Transforms and Hilbert Transform through JDSP

Forward Fourier Transform

Image
Signal Used for this Demo
Image

Only Positive Values

Only Positive Complex Values

                    
_Fourier ft = new DiscreteFourier(signal);
// OR
_Fourier ft = new FastFourier(signal);
ft.transform();
boolean onlyPositive = true;
double[] out = ft.getOutput(onlyPositive); //Positive Absolute
                    
                  
                    
_Fourier ft = new DiscreteFourier(signal);
// OR
_Fourier ft = new FastFourier(signal);
ft.dft();
boolean onlyPositive = true;
double[][] out = ft.getComplex2D(onlyPositive); //Positive Complex
                    
                  

All Absolute Values

All Complex Values

                    
_Fourier ft = new DiscreteFourier(signal);
// OR
_Fourier ft = new FastFourier(signal);
ft.dft();
boolean onlyPositive = false;
double[] out = ft.getOutput(onlyPositive); //Full Absolute
                    
                  
                    
_Fourier ft = new DiscreteFourier(signal);
// OR
_Fourier ft = new FastFourier(signal);
ft.dft();
boolean onlyPositive = false;
double[][] out = ft.getComplex2D(onlyPositive); //Full Complex
                    
                  

Inverse Fourier Transform

Image
Sequence Used for this Demo
Image
                    
_InverseFourier ift = new InverseDiscreteFourier(complexSequence); //If transformed using DFT
// OR
_InverseFourier ift = new InverseFastFourier(complexSequence); //If transformed using FFT
ift.transform();
double[] outReal = ift.getReal(); //To get only the real component
double[] outAbsolute = ift.getOutput(); //To get the absolute value of the complex signal
double[][] out = ift.getComplex2D(); // To get the complex signal
                    
                  

Forward Sine Transform (Standard)

Image
Signal Used for this Demo
Image

Type 1

Type 2

                    
DiscreteSine f1 = new DiscreteSine(signal);
f1.transform(1);
// OR
FastSine f1 = new FastSine(signal);
f1.transform();

double[] output = f1.getOutput();
                    
                  
                    
DiscreteSine f1 = new DiscreteSine(signal)
f1.transform(2);
double[] output = f1.getOutput();
                    
                  

Type 3

Type 4

                    
DiscreteSine f1 = new DiscreteSine(signal)
f1.transform(3);
double[] output = f1.getOutput();
                    
                  
                    
DiscreteSine f1 = new DiscreteSine(signal)
f1.transform(4);
double[] output = f1.getOutput();
                    
                  

Inverse Sine Transform (Standard)

Image

Type 1

Type 2

                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput);
if1.transform(1);
// OR
InverseFastSine if1 = new InverseFastSine(transformOutput);
if1.transform();

double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput);
if1.transform(2);
double[] output = if1.getOutput();
                    
                  

Type 3

Type 4

                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput);
if1.transform(3);
double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput);
if1.transform(4);
double[] output = if1.getOutput();
                    
                  

Forward Sine Transform (Orthogonal)

Image
Signal Used for this Demo
Image

Type 1

Type 2

                    
DiscreteSine f1 = new DiscreteSine(signal, DiscreteSine.Normalization.ORTHOGONAL);
f1.transform(1);
// OR
FastSine f1 = new FastSine(signal, FastSine.Normalization.ORTHOGONAL);
f1.transform();

double[] output = f1.getOutput();
                    
                  
                    
DiscreteSine f1 = new DiscreteSine(signal, DiscreteSine.Normalization.ORTHOGONAL)
f1.transform(2);
double[] output = f1.getOutput();
                    
                  

Type 3

Type 4

                    
DiscreteSine f1 = new DiscreteSine(signal, DiscreteSine.Normalization.ORTHOGONAL)
f1.transform(3);
double[] output = f1.getOutput();
                    
                  
                    
DiscreteSine f1 = new DiscreteSine(signal, DiscreteSine.Normalization.ORTHOGONAL)
f1.transform(4);
double[] output = f1.getOutput();
                    
                  

Inverse Sine Transform (Orthogonal)

Image

Type 1

Type 2

                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput, InverseDiscreteSine.Normalization.ORTHOGONAL);
if1.transform(1);
// OR
InverseFastSine if1 = new InverseFastSine(transformOutput);
if1.transform();

double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput, InverseDiscreteSine.Normalization.ORTHOGONAL);
if1.transform(2);
double[] output = if1.getOutput();
                    
                  

Type 3

Type 4

                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput, InverseDiscreteSine.Normalization.ORTHOGONAL);
if1.transform(3);
double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteSine if1 = new InverseDiscreteSine(transformOutput, InverseDiscreteSine.Normalization.ORTHOGONAL);
if1.transform(4);
double[] output = if1.getOutput();
                    
                  

Forward Cosine Transform (Standard)

Image
Signal Used for this Demo
Image

Type 1

Type 2

                    
DiscreteCosine f1 = new DiscreteCosine(signal);
f1.transform(1);
// OR
FastCosine f1 = new FastCosine(signal);
f1.transform();

double[] output = f1.getOutput();
                    
                  
                    
DiscreteCosine f1 = new DiscreteCosine(signal)
f1.transform(2);
double[] output = f1.getOutput();
                    
                  

Type 3

Type 4

                    
DiscreteCosine f1 = new DiscreteCosine(signal)
f1.transform(3);
double[] output = f1.getOutput();
                    
                  
                    
DiscreteCosine f1 = new DiscreteCosine(signal)
f1.transform(4);
double[] output = f1.getOutput();
                    
                  

Inverse Cosine Transform (Standard)

Image

Type 1

Type 2

                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput);
if1.transform(1);
// OR
InverseFastCosine if1 = new InverseFastCosine(transformOutput);
if1.transform();

double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput);
if1.transform(2);
double[] output = if1.getOutput();
                    
                  

Type 3

Type 4

                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput);
if1.transform(3);
double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput);
if1.transform(4);
double[] output = if1.getOutput();
                    
                  

Forward Cosine Transform (Orthogonal)

Image
Signal Used for this Demo
Image

Type 1

Type 2

                    
DiscreteCosine f1 = new DiscreteCosine(signal, DiscreteCosine.Normalization.ORTHOGONAL);
f1.transform(1);
// OR
FastCosine f1 = new FastCosine(signal, FastCosine.Normalization.ORTHOGONAL);
f1.transform();

double[] output = f1.getOutput();
                    
                  
                    
DiscreteCosine f1 = new DiscreteCosine(signal, DiscreteCosine.Normalization.ORTHOGONAL)
f1.transform(2);
double[] output = f1.getOutput();
                    
                  

Type 3

Type 4

                    
DiscreteCosine f1 = new DiscreteCosine(signal, DiscreteCosine.Normalization.ORTHOGONAL)
f1.transform(3);
double[] output = f1.getOutput();
                    
                  
                    
DiscreteCosine f1 = new DiscreteCosine(signal, DiscreteCosine.Normalization.ORTHOGONAL)
f1.transform(4);
double[] output = f1.getOutput();
                    
                  

Inverse Cosine Transform (Orthogonal)

Image

Type 1

Type 2

                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput, InverseDiscreteCosine.Normalization.ORTHOGONAL);
if1.transform(1);
// OR
InverseFastCosine if1 = new InverseFastCosine(transformOutput);
if1.transform();

double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput, InverseDiscreteCosine.Normalization.ORTHOGONAL);
if1.transform(2);
double[] output = if1.getOutput();
                    
                  

Type 3

Type 4

                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput, InverseDiscreteCosine.Normalization.ORTHOGONAL);
if1.transform(3);
double[] output = if1.getOutput();
                    
                  
                    
InverseDiscreteCosine if1 = new InverseDiscreteCosine(transformOutput, InverseDiscreteCosine.Normalization.ORTHOGONAL);
if1.transform(4);
double[] output = if1.getOutput();
                    
                  

Forward Short-Time Fourier Transform

                    
int frameLength = 5;
int overlap = 2;
ShortTimeFourier stft = new ShortTimeFourier(signal, frameLength, overlap);
stft.transform();
Complex[][] out = stft.getComplex(false);
_Fourier[] dfts = stft.getOutput();
                    
                  

Inverse Short-Time Fourier Transform

                    
int frameLength = 5;
int overlap = 2;
InverseShortTimeFourier istft = new InverseShortTimeFourier(dfts, frameLength, overlap);
istft.transform();
double[] outputReal = istft.getReal();
                    
                  

Hilbert Transform

Image
Sequence Used for this Demo
Image
Amplitude Envelope of the Signal
                    
Hilbert h = new Hilbert(signal);
h.transform();
// OR
h.transform(true); //To use DFT instead of FFT
double[][] analytical_signal = h.getOutput(); //Returns the analytical signal
double[] envelope = h.getAmplitudeEnvelope();
                    
                  
Image
Instantaneous Phase & Frequency of the Signal
                    
Hilbert h = new Hilbert(signal);
h.transform();
double[] phase = h.getInstantaneousPhase();
int Fs = 150; //Sampling Frequency of the original signal
double[] frequency = h.getInstantaneousFrequency(Fs);
                    
                  

Forward Continuous Wavelet Transform

                    
int[] widths = {1,  2,  3,  4,  5,  6,  7,  8,  9, 10};
ContinuousWavelet wR = new ContinuousWavelet(signal, widths);

### For Ricker Wavelet
double ignored_arg = 0.0;
Complex[][] out_cplx = wR.transform(ContinuousWavelet.waveletType.RICKER, ignored_arg);

### For Morlet Wavelet
double morlet_omega0 = 5.0;
Complex[][] out_cplx = wR.transform(ContinuousWavelet.waveletType.MORLET, morlet_omega0);

### For Paul Wavelet
double paul_order = 4.0;
Complex[][] out_cplx = wR.transform(ContinuousWavelet.waveletType.PAUL, paul_order);
                    
                  

Inverse Continuous Wavelet Transform

                    
int[] widths = {1,  2,  3,  4,  5,  6,  7,  8,  9, 10};
InverseContinuousWavelet icwt = new InverseContinuousWavelet(out_cplx, widths);

### For Ricker Wavelet
double ignored_arg = 0.0;
double[] signal = icwt.transform(InverseContinuousWavelet.waveletType.RICKER, ignored_arg);

### For Morlet Wavelet
double morlet_omega0 = 5.0;
double[] signal = icwt.transform(InverseContinuousWavelet.waveletType.MORLET, morlet_omega0);

### For Paul Wavelet
double paul_order = 4.0;
double[] signal = icwt.transform(InverseContinuousWavelet.waveletType.PAUL, paul_order);
                    
                  

Principal Component Analysis

Image
Signal Used for this Demo
Image
1-D Signal after PCA
                    
int dimensions = 1;
PCA p1 = new PCA(signal, dimensions);
p1.fit();
double[][] newSignal = p1.transform(signal); //Returns the reduced signal
                    
                  

Independent Component Analysis

Image
Source Signal and its transformation (input)
Image
Signals recovered after PCA
                    
ICA i1 = new ICA(signal, "logcosh", 1.0); //function can be "logcosh", "exp" or "cube"
i1.fit();
double[][] newSignal = i1.transform();