Pre-processing & Synthesis

Provides a demonstration of using the pre-processing and signal generation tools available in JDSP

Detrend

Image

Constant

Linear

                    
Detrend d1 = new Detrend(signal, "constant");
double[] out = d1.detrendSignal();
                    
                  
                    
Detrend d1 = new Detrend(signal, "linear");
double[] out = d1.detrendSignal();
                    
                  

Polynomial (Power 2)

Polynomial (Power 5)

                    
int power = 2;
Detrend d1 = new Detrend(signal, power);
double[] out = d1.detrendSignal();
                    
                  
                    
int power = 5;
Detrend d1 = new Detrend(signal, power);
double[] out = d1.detrendSignal();
                    
                  

Smoothing

Image

Rectangular Smoothing

Triangular Smoothing

                    
String mode = "rectangular";
int wsize = 11;
Smooth s1 = new Smooth(signal, wsize, mode);
double[] out = s1.smoothSignal();
                    
                  
                    
String mode = "triangular";
int wsize = 11;
Smooth s1 = new Smooth(signal, wsize, mode);
double[] out = s1.smoothSignal();
                    
                  

Decimate

Non-Zero Phase Shift

Zero Phase Shift

Image
Image
                    
int Fs = 100;
int factor = 5;
boolean zero = false;
Decimate d = new Decimate(signal, Fs, zero);
double[] out = d.decimate(factor);
                    
                  
                    
int Fs = 100;
int factor = 5;
boolean zero = true;
Decimate d = new Decimate(signal, Fs, zero);
double[] out = d.decimate(factor);
                    
                  

Resample

FFT-based Resampling

Polyphase Filter-based Resampling

Image
Image
                    
Resample rs = new Resample(this.signal, 100);
double[] resampled = rs.resampleSignal();
                    
                  
                    
Resample rs = new Resample(100, 20, "constant");
double[] resampled = rs.resampleSignal(this.signal);
                    
                  

Convolution

Real Convolution

Complex Convolution

                    
double[] signal = {2, 8, 0, 4, 1, 9, 9, 0};
double[] kernel = {1, 3, 1, 3};
Convolution con = new Convolution(signal, kernel);

double[] full = con.convolve("full"); // Or use con.fastConvolve("full")
double[] same = con.convolve("same"); // Or use con.fastConvolve("same")
double[] valid = con.convolve("valid"); // Or use con.fastConvolve("valid")
                    
                  
                    
public double[][] complexSignal1 = {{1, 2}, {2, 2}, {3, -3}, {4, 1}, {5, -4}};
public double[][] complexKernel1 = {{1, 2}, {2, 4}, {5, -2}, {4, 7}};
Complex[] sg = UtilMethods.matToComplex(this.complexSignal1);
Complex[] krn = UtilMethods.matToComplex(this.complexKernel1);
ComplexConvolution c1 = new ComplexConvolution(sg, krn);

double[][] full = UtilMethods.complexTo2D(c1.convolve("full"));
double[][] same = UtilMethods.complexTo2D(c1.convolve("same"));
double[][] valid = UtilMethods.complexTo2D(c1.convolve("valid"));
                    
                  
Output
Output
                    
full: [2, 14, 26, 18, 37, 16, 49, 39, 36, 27,  0]
same: [14, 26, 18, 37, 16, 49, 39, 36]
valid: [18, 37, 16, 49, 39]
                    
                  
                    
full: [-3+4j, -8+14j, 14+23j, 24+36j, 20+25j, 81+18j, 26+2j, 48+19j]
same: [-8+14j, 14+23j, 24+36j, 20+25j, 81+18j]
valid: [24+36j, 20+25j]
                    
                  

Deconvolution

Real Deconvolution

Complex Deconvolution

                    
double[] convolved_full = {2.0, 14.0, 26.0, 18.0, 37.0, 16.0, 49.0, 39.0, 36.0, 27.0, 0.0};
double[] kernel = {1, 3, 1, 3};
Deconvolution dcon1 = new Deconvolution(convolved_full, kernel);
double[] recovered_full = dcon1.deconvolve("full");

double[] convolved_same = {14, 26, 18, 37, 16, 49, 39, 36};
double[] kernel = {1, 3, 1, 3};
Deconvolution dcon2 = new Deconvolution(convolved_same, kernel);
double[] recovered_same = dcon2.deconvolve("same");
                    
                  
                    
double[][] convolved_same = {{2.2, 2.2}, {2.3, -6.7}, {15.9, 4.94}, {10.7, -23.88}, {16.45, -3.01}}
double[] kernel = {1, 0, 1, 0.5};
ComplexDeconvolution dcon1 = new ComplexDeconvolution(convolved_same, kernel);
dcon1.deconvolve("same");
double[][] recovered_same = UtilMethods.complexTo2D(dcon1.getComplexOutput());
                    
                  
Output
Output
                    
recovered_full: [2.0, 8.0, 0.0, 4.0, 1.0, 9.0, 9.0, 0.0]
recovered_same: [2.0, 8.0, 0.0, 4.0, 1.0, 9.0, 9.0, 0.0]
                    
                  
                    
recovered_same: [-1.6+2.4j, 2.2+2.2j, 3.9-9.1j, 14.5+1.54j, 5.7-15.88j]
                    
                  

Correlation

Cross-Correlation

Auto-Correlation

                    
double[] signal = {2, 8, 0, 4, 1, 9, 9, 0};
double[] kernel = {1, 3, 1, 3};
CrossCorrelation cc = new CrossCorrelation(signal, kernel);

double[] full = cc.crossCorrelate("full"); // Or use cc.crossCorrelate("full")
double[] same = cc.crossCorrelate("same"); // Or use cc.crossCorrelate("same")
double[] valid = cc.crossCorrelate("valid"); // Or use cc.crossCorrelate("valid")
                    
                  
                    
double[] signal = {2, 8, 0, 4, 1, 9, 9, 0};
String mode = "full";
CrossCorrelation cc = new CrossCorrelation(signal);
double[] out = cc.crossCorrelate(mode); //Or use cc.fastCrossCorrelate(mode)
                    
                  
Output
Output
                    
full: [6, 26, 14, 38, 15, 40, 43, 37, 36,  9,  0]
same: [26, 14, 38, 15, 40, 43, 37, 36]
valid: [38, 15, 40, 43, 37]
                    
                  
                    
autocorr_output: [0, 18, 90, 74, 52, 77, 110, 247, 110, 77, 52, 74, 90, 18, 0]
                    
                  

Sine Wave

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
int f1 = 10;
double[] out = gp.generateSineWave(f1);
                    
                  

Cosine Wave

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
int f1 = 10;
double[] out = gp.generateCosineWave(f1);
                    
                  

Square Wave

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
int f1 = 10;
double[] out = gp.generateSquareWave(f1);
                    
                  

Sawtooth Signal

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
int f1 = 5;
double width = 1; //1 for pure sawtooth, 0.5 for triangular, 0 for reverse sawtooth
double[] out = gp.generateSawtooth(f1, width);
                    
                  

Gaussian Pulse

Image
                    
int Fs = 100;
Generate gp = new Generate(-1, 1, 2*Fs);
int f1 = 10;
double[] out = gp.generateGaussianPulse(f1);
                    
                  

Unit Impulse

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
double position = 0.5; //middle of the signal
double[] out = gp.generateUnitImpulse(position);
                    
                  

Morlet Wavelet

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
int points = 100;
double omega0 = 5; //central frequency
double scaling = 1;
double[] out = gp.generateMorlet(points, omega0, scaling);
                    
                  

Ricker Wavelet

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
int points = 100;
double width = 4;
double[] out = gp.generateRicker(points, width);
                    
                  

Paul Wavelet

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
int order = 4;
int width = 11;
double[] out = gp.generatePaul(order, width);
                    
                  

Chirp Signal

Image
                    
int Fs = 100;
Generate gp = new Generate(0, 1, Fs);
double f0 = 0;
double f1 = 10;
double[] out = gp.generateChirp(f0, f1);