TUdataFilter TCL UTILITIES USER MANUAL TUdataFilter
SYNOPSIS
Transfers a set of data to a regular grid
PACKAGE
TCLUTILS
NAME
TUdataFilter
USAGE
TUdataFilter  Data nP Filter FOps FData
INPUT DEFINITIONS
Data - The input data array.
nP - The number of elements in the input data array.
Filter - The filter to use on the data. The defined filters are:
SAVITZKYGOLAY - A Savitzky-Golay filter.
MOVINGWINDOW - A moving window filter.
FOps - Filter options. These depend on the type of filter selected.
SAVITZKYGOLAY - Index 0 : A length of the filter to the right of the data point being processed.
Index 1 : A length of the filter to the left of the data point being processed.
Index 2 : A order of the smoothing polynomial.
MOVINGWINDOW - Index 0 : A length of the right of the of the data point being processed.
Index 1 : A length of the left of the of the data point being processed.
FData - The filtered data array.
RETURN DEFINITION
NONE
DESCRIPTION
TUdataFilter preforms 1-D filtering on an input data array and returns the filtered data in a separate array. The filtering technique can be either a Savitzky-Golay filtering (an extrememly good low-pass filtering technique) or a Moving Window (Box Car) filter. In both cases the filter length below and above the filtered point can be separately set. When using Savitzky-Golay filtering the input data set have a length of 2N.
ERRORS
None Generated
Partial C BACKING
Yes
EXAMPLE(S)
EXAMPLE 1: Graphical representation of an underfilled grid.
# GENERATE some data and add some random noise to it

set T 0.0
for { set nP 0 } { $nP < 512 } { set T [expr $T + .1] ; incr nP } {
   set rV [TUdataRnd1 V 1 PN 0.50] 
   set X($nP) $T
   set R($nP) [expr cos($T) + sin(2*$T) + cos($T) * cos($T)]
   set D($nP) [expr $R($nP) + $rV]
}

# FILTER data using a moving window

set fOps(0) 5
set fOps(1) 5
TUdataFilter D $nP MOVINGWINDOW fOps fDMW

# FILTER data using a Savitzky-Golay filter

set fOps(0) 6
set fOps(1) 6
set fOps(2) 2
TUdataFilter D $nP SAVITZKYGOLAY fOps fDSG

# TURN on plotting   

GraphicsOn TK ETones 
GenWindow 1 0.15 0.15 0.0 0.85 0.85 0.0  2. -1.5 0. 14.0 3.0 0.
DefinePlot 1 1 -1 -1
 
# PLOT the noisey data in white 

set oP [list $GphInfo(White) NONE]
Plot2D 1 Xb Yb X D 0 [expr $nP -1] LINE $oP 

# PLOT the noisey data in noiseless data in green  

set oP [list $GphInfo(Green) NONE]
Plot2D 1 Xb Yb X R 0 [expr $nP -1] LINE $oP 

# PLOT the MovingWindow filtered data in red

set oP [list $GphInfo(Red) NONE]
Plot2D 1 Xb Yb X fDMW 0 [expr $nP -1] LINE $oP 

# PLOT the Savitzky-Golay filtered data in cyan

set oP [list $GphInfo(Cyan) NONE HOLD HOLD 10 *]
Plot2D 1 Xb Yb X fDSG 0 [expr $nP -1] LINE $oP 

# PUT up plot axis and plot annotation

PlotOutlines 1 [list "X" 1.0 "Y" 1.0] [list BOT BOT BOTH BOTH]

# PUT up some labels

WinClip 1 0
TextProp 12 HOLD HOLD
TexT 1 2.5 3.2 0.0 right ORIGINAL $GphInfo(Green)
TexT 1 2.5 3.45 0.0 right "WITH NOISE" $GphInfo(White)
TexT 1 13.5 3.2 0.0 left "MOVING WINDOW" $GphInfo(Red)
TexT 1 13.5 3.45 0.0 left SAVITZKY-GOLAY $GphInfo(Cyan)
update
      
Sept 4, 2003