The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



MovingAverageSmooth


Unit: SDL_math2
Class: none
Declaration: procedure MovingAverageSmooth (SourceVec: TVector; FirstElem, LastElem: integer; DestVec: TVector; WindowSize: integer);

The procedure MovingAverageSmooth smoothes a series of data by replacing the center value of a data window by the mean of all data points in this window ("moving average"). This window is then shifted over the entire series one by one, thus calculating a smoothed representation of the original data series.

The number of data points (window width) used for estimating the smoothed data can be adjusted by setting the parameter WindowSize. The window size has to be an odd number and greater than or equal to 3; any invalid number triggers an ESDLMath2Error exception (see below). The source data series is contained in the vector SourceVec. You may restrict the range of data to be submitted to the smoothing algorithm by setting the parameters FirstElem, and LastElem properly. The resulting smoothed data series is stored in the vector DestVec (starting at position 1). Please note that the first, and the last (WindowSize div 2) elements cannot be smoothed and are replaced by the nearest available smoothed value.

MovingAverageSmooth may create the following exceptions of type ESDLMath2Error:

'MovingAverageSmooth: either SourceVec or DestVec is undefined'
'MovingAverageSmooth: specified range for smoothing is smaller than the length of the smoothing windows'
'MovingAverageSmooth: length of smoothing window is out of range'
'MovingAverageSmooth: length of smoothing window must be odd'

Following is an example for smoothing a data series of 185 points. The elements between 30 and 155 are submitted to the smoothing algorithm using a smoothing window size of 25 elements. Note that the first 12 (=WindowSize div 2), and the last 12 elements of the smoothed series are constant.



Last Update: 2023-Feb-06