# Plugins, Fits, and Filters

## Managing Plugins

Plugins provide added functionality to &kst;. By default, &kst; comes packaged with an extensive selection of built-in plugins. In addition, a simple plugin API allows for easy creation of third-party plugins.

&kst; plugins are usually comprised of an object file and a .desktop file. For plugins which are available system-wide the object and .desktop files should be stored in `/usr/lib/kde3/` and `/usr/share/services/kst/` respectively (this may vary depending on how your system is configured).

## Built-in Plugins

### Overview

Kst plugins are powerful tools which can perform a lot of tasks, such as data fitting, interpolation, statistics, and signal processing including periodogram, correlations, convolution and filters, etc. There are over 25 built-in plugins available in &kst; currently.

### Using Built-in Plugins

All plugins can be created from Data New Plugins... or from the Data Manager, and all data objects resulting from plugins can be seen in the Data Manager.

To quickly apply fit or filter plugins to a set of data, you can right click on the data plot under any mouse modes, and choose the Fit or Filter submenu in the context menu.

The following sections describe the purpose, key algorithms or formulae used to perform calculations, and inputs and outputs for each plugin.

## Fit Plugins

Kst provides lots of algorithms to perform data fitting. All fitting plugins output a vector of best fitted parameters, covariances, and Chi^2/Nu. These values can be seen by selecting the Data View Fit Results

Note: The weight is not the same as the error. It is given as 1/yError^2.

### Fit any non-linear function

This plugin is used to fit a set of data using the Levenberg-Marquardt algorithm.

non-linear fit
non-linear fit

#### Inputs

X Array (vector)

  The x array of the input data set

Y Array (vector)

  The y array of the input data set

Formula y= (string)

  The formula of the curve used to fit the data set

  The default string is `a*x^3 + b*x^2 - c*x +d`

Parameters (string)

  Use a string to specify the parameter representation letters in the fitting formula. The plugin will later output the fitted values for these parameters.

  The default string is `a, b, c, d` corresponding to the default formula string.

Init values (string)

  Use a string to specify the initial guess

  The default string is `1, 1, 1, 1`

Tolerance (scalar)

  Tolerance is a number to indicate the precision of fitting; if the precision reaches the tolerance value, the curve fitting will stop.

  The default tolerance is `1e-4`.

Max iterations (scalar)

  Specify the maximum number of iterations to indicate when the curve fitting should stop.

  The default max iterations is `2`.

#### Outputs

Y Fitted (vector)

  The Y values of the fitted curve

Residuals (vector)

  The array of residuals

Parameters (vector)

  The best fitted values of the model parameters specified in the inputs.

Covariance (vector)

  The covariance matrix of the model parameters, returned row after row in the vector.

chi^2/nu (scalar)

  The sum of squares of residuals, divided by the degrees of freedom

### Fit exponential weighted

The Fit exponential weighted plugin performs a weighted non-linear least-squares fit to an exponential model

An initial estimate of `a=1.0`, `=0`, and `b=0` is used. The plugin subsequently iterates to the solution until a precision of `1.0e-4` is reached or 500 iterations have been performed.

Plugins - Fit exponential weighted

#### Inputs

X Array (vector)

  The array of x values for the data points to be fitted.

Y Array (vector)

  The array of y values for the data points to be fitted.

Weights Array (vector)

  The array of weights to use for the fit.

#### Outputs

Y Fitted (vector)

  The array of fitted y values.

Residuals (vector)

  The array of residuals.

Parameters (vector)

  The best fit parameters `a`, , and `b`.

Covariance (vector)

  The covariance matrix of the model parameters, returned row after row in the vector.

chi^2/nu (scalar)

  The weighted sum of squares of the residuals, divided by the degrees of freedom.

### Fit exponential

The Fit exponential plugin is identical in function to the Fit exponential weighted plugin with the exception that the weight value `wi` is equal to `1` for all index values `i`. As a result, the Weights (vector) input does not exist.

### Fit Gaussian weighted

The Fit Gaussian weighted plugin performs a weighted non-linear least-squares fit to a Gaussian model:

An initial estimate of `a=`(maximum of the y values), `=`(mean of the x values), and `=`(the midpoint of the x values) is used. The plugin subsequently iterates to the solution until a precision of `1.0e-4` is reached or 500 iterations have been performed.

Plugins - Fit Gaussian

#### Inputs

X Array (vector)

  The array of x values for the data points to be fitted.

Y Array (vector)

  The array of y values for the data points to be fitted.

Weights Array (vector)

  The array of weights to use for the fit.

#### Outputs

Y Fitted (vector)

  The array of fitted y values.

Residuals (vector)

  The array of residuals.

Parameters (vector)

  The best fit parameters , , and `a`.

Covariance (vector)

  The covariance matrix of the model parameters, returned row after row in the vector.

chi^2/nu (scalar)

  The weighted sum of squares of the residuals, divided by the degrees of freedom.

### Fit Gaussian

The Fit Gaussian plugin is identical in function to the Fit Gaussian weighted plugin with the exception that the weight value `wi` is equal to `1` for all index values `i`. As a result, the Weights (vector) input does not exist.

### Fit gradient weighted

The gradient weighted plugin performs a weighted least-squares fit to a straight line model without a constant term:

The best-fit is found by minimizing the weighted sum of squared residuals:

for `b`, where `wi` is the weight at index `i`.

Plugins - Fit Gradient

#### Inputs

X Array (vector)

  The array of x values for the data points to be fitted.

Y Array (vector)

  The array of y values for the data points to be fitted.

Weights Array (vector)

  The array containing weights to be used for the fit.

#### Outputs

Y Fitted (vector)

  The array of y values for the points representing the best-fit line.

Residuals (vector)

  The array of residuals, or differences between the y values of the best-fit line and the y values of the data points.

Parameters (vector)

  The parameter `b` of the best-fit.

Covariance (vector)

  The estimated covariance matrix, returned row after row, starting with row 0.

Y Lo (vector)

  The corresponding value in Y Fitted minus the standard deviation of the best-fit function at the corresponding x value.

Y Hi (vector)

  The corresponding value in Y Fitted plus the standard deviation of the best-fit function at the corresponding x value.

chi^2/nu (scalar)

  The value of the sum of squares of the residuals, divided by the degrees of freedom.

### Fit gradient

The Fit linear plugin is identical in function to the Fit gradient weighted plugin with the exception that the weight value `wi` is equal to `1` for all index values `i`. As a result, the Weights (vector) input does not exist.

### Fit linear weighted

The Fit linear weighted plugin performs a weighted least-squares fit to a straight line model:

The best-fit is found by minimizing the weighted sum of squared residuals:

for `a` and `b`, where `wi` is the weight at index `i`.

Plugins - Fit linear

#### Inputs

X Array (vector)

  The array of x values for the data points to be fitted.

Y Array (vector)

  The array of y values for the data points to be fitted.

Weights Array (vector)

  The array containing weights to be used for the fit.

#### Outputs

Y Fitted (vector)

  The array of y values for the points representing the best-fit line.

Residuals (vector)

  The array of residuals, or differences between the y values of the best-fit line and the y values of the data points.

Parameters (vector)

  The parameters `a` and `b` of the best-fit.

Covariance (vector)

  The estimated covariance matrix, returned row after row, starting with row 0.

Y Lo (vector)

  The corresponding value in Y Fitted minus the standard deviation of the best-fit function at the corresponding x value.

Y Hi (vector)

  The corresponding value in Y Fitted plus the standard deviation of the best-fit function at the corresponding x value.

chi^2/nu (scalar)

  The value of the sum of squares of the residuals, divided by the degrees of freedom.

### Fit linear

The Fit linear plugin is identical in function to the Fit linear weighted plugin with the exception that the weight value `wi` is equal to `1` for all index values `i`. As a result, the Weights (vector) input does not exist.

### Fit Lorentz weighted

The Fit Lorentz weighted plugin performs a weighted non-linear least-squares fit to a Lorentzian model:

An initial estimate of `a=`(maximum of the y values), `x0=`(mean of the x values), and `=`(the midpoint of the x values) is used. The plugin subsequently iterates to the solution until a precision of `1.0e-4` is reached or 500 iterations have been performed.

Plugins - Fit Lorentzian

#### Inputs

X Array (vector)

  The array of x values for the data points to be fitted.

Y Array (vector)

  The array of y values for the data points to be fitted.

Weights Array (vector)

  The array of weights to use for the fit.

#### Outputs

Y Fitted (vector)

  The array of fitted y values.

Residuals (vector)

  The array of residuals.

Parameters (vector)

  The best fit parameters `x0`, , and `a`.

Covariance (vector)

  The covariance matrix of the model parameters, returned row after row in the vector.

chi^2/nu (scalar)

  The weighted sum of squares of the residuals, divided by the degrees of freedom.

### Fit Lorentz

The Fit Lorentz plugin is identical in function to the Fit Lorentz weighted plugin with the exception that the weight value `wi` is equal to `1` for all index values `i`. As a result, the Weights (vector) input does not exist.

### Fit polynomial weighted

The Fit polynomial weighted plugin performs a weighted least-squares fit to a polynomial model:

where `n` is the degree of the polynomial model.

Plugins - Fit Polynomial

#### Inputs

X Array (vector)

  The array of x values for the data points to be fitted.

Y Array (vector)

  The array of y values for the data points to be fitted.

Weights Array (vector)

  The array of weights to use for the fit.

Order (scalar)

  The order, or degree, of the polynomial model to use.

#### Outputs

Y Fitted (vector)

  The array of fitted y values.

Residuals (vector)

  The array of residuals.

Parameters (vector)

  The best fit parameters `c0`, `c1`,..., `cn`.

Covariance (vector)

  The covariance matrix of the model parameters, returned row after row in the vector.

chi^2/nu (scalar)

  The weighted sum of squares of the residuals, divided by the degrees of freedom.

### Fit polynomial

The Fit polynomial plugin is identical in function to the Fit polynomial weighted plugin with the exception that the weight value `wi` is equal to `1` for all index values `i`. As a result, the Weights (vector) input does not exist.

### Fit sinusoid weighted

The Fit sinusoid weighted plugin performs a least-squares fit to a sinusoid model:

where `T` is the specified period, and `n=2+2H`, where `H` is the specified number of harmonics.

Plugins - Fit Sinusoid

#### Inputs

X Array (vector)

  The array of x values for the data points to be fitted.

Y Array (vector)

  The array of y values for the data points to be fitted.

Weights (vector)

  The array of weights to use for the fit.

Harmonics (scalar)

  The number of harmonics of the sinusoid to fit.

Period (scalar)

  The period of the sinusoid to fit.

#### Outputs

Y Fitted (vector)

  The array of fitted y values.

Residuals (vector)

  The array of residuals.

Parameters (vector)

  The best fit parameters `c0`, `c1`,..., `cn`.

Covariance (vector)

  The covariance matrix of the model parameters, returned row after row in the vector.

chi^2/nu (scalar)

  The weighted sum of squares of the residuals, divided by the degrees of freedom.

### Fit sinusoid

The Fit sinusoid plugin is identical in function to the Fit sinusoid weighted plugin with the exception that the weight value `wi` is equal to `1` for all index values `i`. As a result, the Weights (vector) input does not exist.

## Interpolation Plugins

Interpolation is a way to construct new data points within a data set. All Kst interpolation plugins take two vectors x and y, and a desired values x', then find the interpolation functions which fit x and y, and evaluate functions to get the corresponding y' value (interpolated y) for each x' value.

### Interpolation Akima spline

The Interpolation Akima spline plugin generates a non-rounded Akima spline interpolation for the supplied data set, using natural boundary conditions.

Plugins - Akima Spline

#### Inputs

X Array (vector)

  The array of x values of the data points to generate the interpolation for.

Y Array (vector)

  The array of y values of the data points to generate the interpolation for.

X' Array (vector)

  The array of x values for which interpolated y values are desired.

#### Outputs

Y Interpolated (vector)

  The interpolated y values.

### Interpolation Akima spline periodic

The interpolation akima periodic plugin generates a non-rounded Akima spline interpolation for the supplied data set, using periodic boundary conditions. The input and output options are the same as those for Interpolation Akima spline.

### Interpolation cubic spline

The Interpolation cubic spline plugin generates a cubic spline interpolation for the supplied data set, using natural boundary conditions. The input and output options are the same as those for Interpolation Akima spline.

### Interpolation cubic spline periodic

The Interpolation cubic spline periodic plugin generates a cubic spline interpolation for the supplied data set, using periodic boundary conditions. The input and output options are the same as those for Interpolation Akima spline.

### Interpolation linear

The Interpolation linear plugin generates a linear interpolation for the supplied data set. The input and output options are the same as those for Interpolation Akima spline.

### Interpolation polynomial

The Interpolation polynomial plugin generates a polynomial interpolation for the supplied data set. The number of terms in the polynomial used is equal to the number of points in the supplied data set. The input and output options are the same as those for Interpolation Akima spline.

## Filter Plugins

Kst has a number of built-in filters.

### Generic Filter

This plugin filters a set of data by using the bilinear transformation formula.

#### Inputs

Y (vector)

  The array of data to filter

Sampling interval(s) (scalar)

  The time periods for sampling of the input vector, reciprocal of the sampling frequency

Numerator/Denominator(increasing order) (string)

  A string of numbers separated by commas to indicate the coefficients of the polynomial as numerator/denominator in the transform formula. For example, if you have a polynomial: 2*z^2 + 3*z + 5, you will need to specify the string: 2,3,5. To input the string, click on the icon

  create string

  to construct a string with value 2,3,5

#### Outputs

Filtered (vector)

  an array of filtered data

### Band-pass filter

The Butterworth band-pass plugin filters a set of data by calculating the Fourier transform of the data and scaling the spectral amplitudes using the following function G(f)

Bandpass formula

where `f` is the frequency, `fc` is the central frequency to filter around, `b` is the bandwidth to pass, and `n` is the order of the Butterworth filter. The inverse Fourier transform is then calculated using the scaled spectral amplitudes to give a filtered dataset.

Plugins - Bandpass Filter

#### Inputs

Y (vector)

  The array of values to filter.

Order (scalar)

  The order of the Butterworth filter to use.

Central frequency/sample rate (scalar)

  The frequency to filter around.

Band width (scalar)

  The width of the band to pass. This should be the difference between the desired high cutoff frequency and the low cutoff frequency.

#### Outputs

Filtered (vector)

  The array of filtered data values.

### Band-stop filter

The Butterworth band-stop effectively removes signals in a given frequency range from an input vector. The options are the same as for the Band-pass filter except that the scaling function G(f) which is used is now given by:

Bandstop formula

### High-pass filter

The Butterworth high-pass plugin effectively removes signals below a given cutoff frequency from a data vector. It does this by by calculating the Fourier transform of the data and rescaling the the spectral amplitudes using the following following function G(f)

Highpass formula

where `f` is the frequency, `fc` is the high frequency cutoff, and `n` is the order of the Butterworth filter. The inverse Fourier transform is then calculated using the new filtered frequency responses.

Plugins - High pass

#### Inputs

Y (vector)

  The array of values to filter.

Order (scalar)

  The order of the Butterworth filter to use.

Cutoff frequency/sample rate (scalar)

  The cutoff frequency (`fc`).

#### Outputs

Filtered (vector)

  The array of filtered data values.

### Low-pass filter

The Butterworth low-pass filter effectively removes signals above a given frequency cutoff from an input vector. The options are the same as for the High-pass filter except that the scaling function G(f) which is used is now given by:

Autocorrelation formula

### Despike Filter

This plugin is used to find and remove spikes in a data set.

plugins-Edit Despike Filter

#### Inputs

Y (vector)

  Select the data vector needed to be smoothed.

Spacing (scalar)

  Specify the width of the spikes.

NSigma (scalar)

  If a data point value varies from its neighboring data points by NSigma times more, it will be counted as a spike.

#### Outputs

Despiked (vector)

  This plugin outputs a smoothed data set with all specified spikes removed.

## Signal Processing Plugins

Kst provides various plugins to help you easily process signals.

### Autocorrelation

The autocorrelation plugin calculates correlation values between a series (vector) and a lagged version of itself, using lag values from `floor(-(N-1)/2)` to `floor((N-1)/2)`, where `N` is the number of points in the data set. The time vector is not an input as it is assumed that the data is sampled at equal time intervals. The correlation value `r` at lag `k` is:

Autocorrelation formula

Plugins - Autocorrelation

#### Inputs

Array (vector)

  The array `x` of values to calculate correlation values for.

#### Outputs

Step Value (vector)

  The array of step, or lag values.

Auto-correlated (vector)

  The array of correlation values calculated using the corresponding step number in the Step Number vector.

### Crosscorrelation

The crosscorrelation plugin calculates correlation values between two series (vectors) `x` and `y`, using lag values from `floor(-(N-1)/2)` to `floor((N-1)/2)`, where `N` is the number of elements in the longer vector. The shorter vector is padded to the length of the longer vector using `0`s. The time vector is not an input as it is assumed that the data is sampled at equal time intervals. The correlation value `r` at lag `k` is:

crosscorrelation formula

Plugins - Cross-correlation

#### Inputs

Array One (vector)

  The array `x` used in the cross-correlation formula.

Array Two (vector)

  The array `y` used in the cross-correlation formula.

#### Outputs

Step value (vector)

  The array of step, or lag values.

Correlation (vector)

  The array of correlation values calculated using the corresponding step number in the Step value vector.

### Cross Power Spectrum

The cross power spectrum plugin takes two vectors and calculates the FFT of their cross-correlation values.

Plugins - CrossPowerSpectrum

#### Inputs

Vector One/Two

  The two vectors used to calculate the cross power spectrum

FFT Length= 2^ (scalar)

  Refers to FFT options in Spectrum

Sample rate (scalar)

  Refers to FFT options in Spectrum

#### Outputs

Cross Spectrum: Real(vector)

  The real part of the calculated cross power spectrum.

Cross Spectrum: Imaginary (vector)

  The imaginary part of the calculated cross power spectrum.

Frequency (vector)

  The frequency vector of the output cross power spectrum.

### Convolution

The convolution plugin generates the convolution of one vector with another. The convolution of two functions `f` and `g` is given by:

The order of the vectors does not matter, since `f*g=g*f`. In addition, the vectors do not need to be of the same size, as the plugin will automatically interpolate smallest vector to the larger length.

Plugins - Convolution

#### Inputs

Array One (vector)

  One of the pair of arrays to take the convolution of.

Array Two (vector)

  One of the pair of arrays to take the convolution of.

#### Outputs

Convolved (vector)

  The convolution of the two input vectors.

### Deconvolution

The deconvolution plugin generates the deconvolution of one vector with another. Deconvolution is the inverse of convolution. Given the convolved vector `h` and another vector `g`, the deconvolution `f` is given by:

The vectors do not need to be of the same size, as the plugin will automatically extrapolate the shorter vector. The shorter vector is assumed to be the response function `g`.

Plugins - Deconvolution

#### Inputs

Array One (vector)

  One of the pair of arrays to take the deconvolution of.

Array Two (vector)

  One of the pair of arrays to take the deconvolution of.

#### Outputs

Deconvolved (vector)

  The deconvolution of the two input vectors.

### Periodogram

The periodogram plugin produces the periodogram of a given data set. Periodogram is an estimate of the spectral density of a signal.

Plugins - Periodogram

#### Inputs

Time Array (vector)

  The array of time values of the data points to generate the interpolation for.

Data Array (vector)

  The array of data values, dependent on the time values of the data points to generate the interpolation for.

Oversampling factor (scalar)

  The factor to oversample by.

Average Nyquist frequency factor (scalar)

  The average Nyquist frequency factor.

#### Outputs

Frequency (vector)

  The frequency vector.

Periodogram (vector)

  The frequency response vector for the periodogram.

## Calculus Plugins

There are some plugins which can be used to do basic calculus.

### Cumulative Sum (integral)

This plugin sums up the input vector cumulatively over a chosen time step which is the time interval between two neighboring data points of the input vector. As the time step becomes smaller, the calculated sum will approach this integral: cumulative sum formulate

,where x is the input data vector.

#### Inputs

InputVector

  The vector used to calculate the cumulative sum.

Scale factor(time step) (scalar)

  The interval size for each step of calculating the cumulative sum

#### Outputs

Cumulative Sum (vector)

  This array stores values of the cumulative sum for each step.

### Fixed Step Differentiation

This plugin calculates derivative values with respect to time for an input vector. As time step becomes smaller, the output vector will reach the values of dx/dt, where x is the input vector.

plugins-Edit fixed step differentiation

#### Inputs

inputVector

  the data vector to take derivative of

Time step (scalar)

  Specify the size of the time interval between any two neighbor values in the input vector

#### Outputs

Derivative (vector)

  This plugin outputs the derivative values for every time step.

## Miscellaneous Plugins

### Bin

The bin plugin group elements of a single data vector into bins of a specified size. The value of each bin is the mean of the elements belonging to the bin. For example, if the bin size is `3`, and the input vector is `[9,2,7,3,4,74,5,322,444,2,1]`, then the outputted bins would be `[6,27,257]`. Note that any elements remaining at the end of the input vector that do not form a complete bin (in this case, elements `2` and `1`), are simply discarded.

plugins- - Bin

#### Inputs

Input Vector (vector)

  The vector to bin.

Bin Size (scalar)

  The size (# of elements) to have in each bin.

#### Outputs

Bins (vector)

  The array of means for each bin.

### Binned Map

The binned map can generate a surface count or plot of a two-variable function.

Plugins - Binnedmap

#### Settings

X,Y,Z (vector)

  X/Y vectors are used to specify values of the two independent variables in a function, and Z vector specifies the values of the dependent variable.

X/Y Binning: From/To (scalar)

  Specify the range of X/Y values.

Num X/Y bins (scalar)

  Specify the number of resolution grid for the output binned map.

#### Outputs

Binned Map (matrix)

  Binned Map is a matrix whose entries can be used to generate the surface contour plot of the Z vector.

Hits Map (matrix)

  Hits Map is a matrix whose values are specified by the number of points in each X/Y bin, and the image of Hits Map indicates the positions where Z values have been located in the X/Y plane.

### Chop

The chop plugin takes an input vector and divides it into two vectors. Every second element in the input vector is placed in one output vector, while all other elements from the input vector are placed in another output vector.

Plugins - Chop

#### Inputs

Array (vector)

  The array of values to perform the chop on.

#### Outputs

Odd Array (vector)

  The array containing the odd part of the input array (i.e. it contains the first element of the input array).

Even Array (vector)

  The array containing the even part of the input array (i.e. it does not contain the first element of the input array).

Difference Array (vector)

  The array containing the elements of the odd array minus the respective elements of the even array.

Index Array (vector)

  An index array has the same length as the other three output arrays.

### Convert time

The Convert time plugin converts a vector from one time format to another:

Plugins - Convert time

#### Inputs

Input vector

  The vector holding the time values to be converted.

Input time format (scalar)

  The time format of the values in the input vector. The formats are:

  - 0: standard C time
  - 1: TAI
  - 2: JD
  - 3: MJD
  - 4: RJD
  - 5: JY
  - 6: TAI (ns)
  - 7: TAI (2^-16 sec)
Output time format (scalar)

  The time format for the values in the output vector. The formats are the same as for the input time format.

#### Outputs

Output vector

  The vector holding the converted time values, which will be the same size as the input vector.

### Noise Addition

The Noise addition plugin adds a Gaussian random variable to each element of the input vector. The Gaussian distribution used has a mean of `0` and the specified standard deviation. The probability density function of a Gaussian random variable is:

Plugins - Noise addition

#### Inputs

Array (vector)

  The array of elements to which random noise is to be added.

Sigma (scalar)

  The standard deviation to use for the Gaussian distribution.

#### Outputs

Output Array (vector)

  The array of elements with Gaussian noise added.

### Normalization (Standard score)

This plugin subtracts the mean from the input vector and divides by the standard deviation.

plugins-Edit Normalization

#### Inputs

Vector In

  The vector to normalize

#### Outputs

Vector Out

  Output the original vector after normalizing.

### Phase

This plugin calculates the phase value for each data point of an input time array.

plugins-Edit Phase

#### Inputs

Time Array (vector)

  An array of time values

Data In Array (vector)

  Input data array corresponding to the time array

Period (scalar)

  Set the period of the input time array.

Zero Phase (scalar)

  Set the time for the zero phase.

#### Outputs

Phase Array (vector)

  An array of phase values corresponding to the input data values.

Data Out Array (vector)

  Output the original data set with values sorted by the phase array.

### Reverse

This plugin reverses the input vector.

plugins-Edit Reverse

#### Inputs

InputVector

  The vector to reverse.

#### Outputs

Output Vector

  The reversed vector.

### Shift

This plugin shifts the plot of an input vector forwards or backwards on the X axis.

plugins-Edit Phase

#### Inputs

InputVector

  The vector to shift.

Shift value(#points, negative allowed) (scalar)

  Specify the units to be shifted. Positive shifted value results right or forward shift. Negative shifted value results left or backwards shift.

#### Outputs

ShiftedVector

  Output the original vector after shifting by the units indicated above.

### Statistics

The statistics plugin calculates statistics for a given data set beyond those automatically calculated by &kst;. Most of the output scalars are named such that the values they represent should be apparent. Standard formulae are used to calculate the statistical values.

Plugins - Statistics

#### Inputs

Data Array (vector)

  The array of data whose statistic values needed to be calculated.

#### Outputs

Mean (scalar)

  The mean of the data values.

Minimum (scalar)

  The minimum value found in the data array.

Maximum (scalar)

  The maximum value found in the data array.

Variance (scalar)

  The variance of the data set.

Standard deviation (scalar)

  The standard deviation of the data set.

Median (scalar)

  The median of the data set.

Absolute deviation (scalar)

  The absolute deviation of the data set.

Skewness (scalar)

  The skewness of the data set.

Kurtosis (scalar)

  The kurtosis of the data set.

### Syncbin

This plugin groups y values of a data set into bins defined by x values.

plugins-Edit syncbin

#### Inputs

X in (vector)

  The X values of a set of data points

Y in (vector)

  The Y values of a set of data points

Number of Bins (scalar)

  Specify the number of bins used to group the data points

X min/X max (scalar)

  Specify min/max X values of a data set to indicate the range of data points needed to be grouped.

#### Outputs

X out (vector)

  The X values after binning. The X out vector is composed of the median values of the X elements in each bin

Y out (vector)

  The Y values after binning. The Y out vector is composed of the mean values of the Y elements in each bin

Y error (vector)

  This vector is composed of the standard deviations of the Y values in each bin.

N (vector)

  The N vector is composed of the number of data points in each bin.

## Using Plugins through KstScript

### Overview

Plugins can also be generated and edited through KstScript. See details in the Plugin class in the Working With KstScript chapter.

To create a new plugin, using the following syntax:

    plugin = new Plugin(Kst.pluginManager.modules["Plugin Name"])
    //the "Plugin Name" should be typed exactly as shown in the Create Plugin tab in the Data Manager.

To set input values of this plugin

    plugin.setInput(index of input, value of input);

You must validate the plugin before you can get its outputs. To validate the plugin, use the following method:

    plugin.validate();

The output values stored in Kst as an objectcollection. To get an output of this plugin, you need to specify its index:

    v = plugin.outputs[index of output];

To know the index of inputs and outputs, refer to their appearing orders in dialogs of plugins UI.

See two examples below of using plugins through KstScript

### Examples

#### KstScript of Statistics Plugin

    p = new Plugin(Kst.pluginManager.modules["Statistics"]);//create a new statistics plugin
    p.tagName = "Stat"; 			// this will be the plugin name in the data manager
    p.setInput(0, "x");			//x is the name of a vector whose various
                       			//statistical values are needed
    p.validate(); 				//validate the plugin
    s = new Scalar();
    s = p.outputs[0];			//to get the first output of this plugin, i.e the mean of x
    s.value					//the value of s will be printed on the screen, e.g. -4.12232621329268

#### KstScript Function of Using Interpolation Plugins

All Kst interpolation plugins have the same inputs and outputs; therefore, instead of writing lots of similar code to set inputs and get outputs for different interpolation schemes, we can write a kstScript function to do that.

The following is a KstScript function which needs 3 vectors: x, y, ix, and a string as inputs. The function will use the string to specify an interpolation plugin, and apply the specified interpolation scheme to x, y vectors in order to get the interpolated y values for ix vector. Then the function will plot y vs x, and interpolated y vs ix.

    //intplFuction.js
    function intpl(x,y,ix,intpl){
    //x is a vector used as X Array in interpolation plugins
    //y is a vector used as Y Array
    //ix is a vector used as X' Array
    //intpl is a string used to specify the name
    //of a specific interpolation plugin, such as "Interpolation akima spline".
    //construct a new interpolation plugin
     pl = new Plugin(Kst.pluginManager.modules[intpl]);
     pl.tagName = intpl+"plugin";
    //set the Inputs of the plugin
     pl.setInput(0,x);
     pl.setInput(1,y);
     pl.setInput(2,ix);
     pl.validate(); //validated the plugin

    iy = pl.outputs[0]; //gets the output vector from this plugin
    iy.tagName = "interpolated_y"; //call it interpolated_y vector in the data_manager
    //open a new window to plot x vs y and ix vs interpolated_y;
    w=new Window();
    p=new Plot(w);
    c1 = new Curve(x,y);
    c1.tagName = "y";
    c2 = new Curve(ix,iy);
    c2.tagName = "interpolated_y";
    p.curves.append(c1);
    p.curves.append(c2);
    p.xAxis.label = "X";
    p.yAxis.label = "Y";
    //edit the settings of the curves, such as line style, point style, etc
    //in order to make the two curves more distinguishable
    c1.hasPoints = true;
    c1.pointStyle = 3;
    c1.lineStyle = 1;
    c1.lineWidth = 2;
    c2.hasPoints = true;
    c2.pointStyle = 0;
    c2.lineWidth = 1;
    //add an legend
    l = new Legend(w);
    l.fontSize = 5;
    l.addCurve(c1);
    l.addCurve(c2);
       }

Let us see an example of using the above function. First, save the above script in a file called `intplFunction.js` in your home folder, and open a new text file to copy the following lines, then save this file as `intplTest.js` in your home folder.

    //intplTest.js
    //construct 2 vectors x and y, with y = sin(x) and x = {-10,-9,-8...0...8,9,10}
    x = new Vector();
    x.tagName = "x";
    y = new Vector();
    y.tagName = "y";
    x.resize(21);
    y.resize(21);
    var k=-10;
    for(var i=0; i<21; i++){
    x[i]=k;
    y[i]=Math.sin(x[i]);
    k++;}
    //construct the ix vector; ix={-10,-9.75,-9.25,-9,...0...9,9.25,9,75,10}
    //The y values of ix will be obtained by interpolation.
    ix=new Vector();
    ix.tagName = "ix";
    ix.resize(81);
    var k=-10;
    for(var i=0; i<81; i++){
    ix[i]=k;
    k = k+0.25;}
    //load intpl function script
    loadScript('/home/vyiwen/intplFunction.js');
    //call intpl function
    intpl(x,y,ix,"Interpolation cubic spline")

Open Kst, and load `intplTest.js` in the Java Console like this: `loadScript('/home/vyiwen/intplTest.js');`

After loading the script, you should see the plots below:

interpolation eg
interpolation eg