SSCI JavaScript Library

Smooth, deseasonalise and analyse data series

Filter Smoothing


Definition

ssci.smooth.filter()

This function applies a set of weights to a point and the surrounding points. The filter no longer needs to contain an odd number of weights with the central weight being applied to the current point. You can now specify where the filter should be applied.

Functions

.data(value)

The data to be loaded

.x([value])

Either specify the x function or return the x function if no value specified.

.y([value])

Either specify the y function or return the y function if no value specified.

.filter([array])

Either specify the filter or return the filter if no value specified. An array of values that describe the weights to apply. So a filter of [0.33, 0.34, 0.33] means that weights are applied as 0.33*(n-1), 0.34*n and 0.33*(n+1).

.limits([m1, m2])

Sets or gets the values for where the filter is applied. If supplied must be an array with 2 numbers - m1 and m2. m1 is the number denoting the index of the first number to apply weights to, relative to the current data point. m2 is the number denoting the index of the last number to apply weights to.

.end([value])

A boolean value that signifies whether to apply the filter to the end points of the series. If true then the filter is not applied to the end points. If false then the filter is applied assymetrically to the data. For end point n and using the filter above then weights are applied as 0.33*(n-1), 0.34*n and 0.33*n

.gain(value)

Return the gain for a period 'value' by the filter. The gain function calculates the weight the filter applies to a specific periodicity.

.phaseShift(value)

Returns the phase shift for period 'value' caused by the filter.

.left(value)

Set or get the function to calculate the weights for the left end of the data series if 'end' is false. The default is an asymmetric Henderson filter.

.right(value)

Set or get the function to calculate the weights for the right end of the data series if 'end' is false. The default is an asymmetric Henderson filter.

Example

Filter
Remove ends

Usage


//Add smoothed line
var dObj = ssci.smooth.filter()
                        .data(data)
                        .x(function(d){ return d.x; })
                        .y(function(d){ return d.y; })
                        .filter([0.33, 0.34, 0.33])
                        .end(true);

dObj();

//Difference the data
var dObj2 = ssci.smooth.filter()
                        .data(data)
                        .x(function(d){ return d.x; })
                        .y(function(d){ return d.y; })
                        .limits([-1, 0])
                        .filter([-1, 1])
                        .end(true);

dObj2();

var slines = d3.svg.line()
                .x(function(d) { return x_scale(d[0]); })
                .y(function(d) { return y_scale(d[1]); });
            
cht.append("path")
    .data(dObj.output())
    .attr("d", slines(dObj.output()))
    .attr("class","c_sline1";