Monday, June 27, 2011

How to remove line trend in java

Preamble

This method is equivalent to the detrend method of Matlab. It requires the commons math jar from Apache.


Download link

http://commons.apache.org/math/index.html

public static double[] detrend(double[] x, double[] y) {
        
        if (x.length != y.length)
            throw new IllegalArgumentException("The x and y data elements needs to be of the same length");
        
        SimpleRegression regression = new SimpleRegression();
        
        for (int i = 0; i < x.length; i++) {
            regression.addData(x[i], y[i]);
        }
        
        double slope = regression.getSlope();
        double intercept = regression.getIntercept();
        
        for (int i = 0; i < x.length; i++) {
            //y -= intercept + slope * x 
            y[i] -= intercept + (x[i] * slope);
        }
        return y;
    }

Thursday, June 16, 2011

How to draw different signal encodings in java

Preamble

This articles will show how different signals which include, NRZL, NRZI, Bipolar AMI, Psedoternay, Manchester and Differential Manchester are displayed.

JDK and eclipse compatibility

JDK version 1.3 with eclipse 3.3 is the minimum requirement.

Project overview
 
The downloadable zip file contains an eclipse project which has a MainFrame class for GUI and a DigitalSignalEncoding class which does all the magic. This project uses Swing for GUI and graphics 2D.for drawing the signals.

Each encoding corresponds to a method in the DigitalSignalEncoding class which makes it fairly simple to understand. However, if you have any question; please post comment.

Unzip the downloadable and load in the eclipse project. Make a run configuration for MainFrame class and you are all set. The input can be given in decimal or binay format based on the selected option. Once the input is provided hitting enter key will display the signal.

If different encoding needs to be displayed for the same given input, the selection in the drop down needs to be changed.

Enjoy, if you like it please appreciate!


Sunday, June 12, 2011

How to do auto source formatting in eclipse (RCP) on Save button

Click to download src
Click to download plugin jar

JDK and eclipse compatibility

JDK version 1.6 with eclipse 3.3 is the minimum requirement.

Preamble

Download using the download link. Drop the jar in eclipse's plugin folder and restart for changes to take affect.

Overview of plugin

The plugin provides two functionalities, Save and Save all.

The default is the save option, i.e when Ctrl+S is pressed or clicked through menu or toolbar. The code will be automatically saved in the current view.

In the case of save all, when Ctrl+Shift+S is pressed or clicked through menu or toolbar. The code will be automatically saved in all the dirty editors and the current view is preserved.

Change of Settings

The settings can be changed by going to "Auto Code Formatter" option in Window->Preferences section.

Enjoy, if you like it please appreciate!