MAL.Filter

Previous  Next

 

ref_arr_out = MAL.Filter( [BYREF arr_out       AS ARRAY],

                           BYREF arr_in        AS ARRAY,

                          [BYVAl nType         AS INTEGER=ML_AVERAGE],

                          [BYVAL nLength       AS INTEGER=5],

                          [BYVAL nLowCutoff    AS INTEGER=0],

                          [BYVAL nHighCutoff   AS INTEGER=0],

                          [BYVAL nPoint        AS INTEGER=ML_ALL],

                          [BYVAL nFrameOffset  AS INTEGER=0] ) AS REFERENCE

 


 

The MAL.Filter function applies a digital filter or data smoothing to the data set.  The following filter are available:

 

' Filter Types

CONST ML_AVERAGE        = 51   ' Smoothing - Moving Average Filter

CONST ML_MEDIAN         = 52   ' Smoothing - Moving Median Filter

CONST ML_SMOOTHING      = 53   ' Smoothing - Smoothing

CONST ML_LOWPASS        = 54   ' Digital   - Lowpass Filter

CONST ML_HIGHPASS       = 55   ' Digital   - Higpass Filter

CONST ML_BANDPASS       = 56   ' Digital   - Bandpass Filter

CONST ML_NOTCH          = 57   ' Digital   - Notch Filter

 

The nLength parameter is valid for all filters and smothing.  The cutoff frequencies are only available for the digital filters.  The Digital filters will use the current frame rate set by a call to MAL.FrameRate

 

Example:

 

OPTION EXPLICIT ON

OPTION BASE 1

 

' Include C3D Support

$INCLUDE "MyBASIC2_C3DFile"

$LIBRARY "MyBASIC2_C3DFileLib"

 

' Needed to extract and Display Version

$LIBRARY "MyBASIC2_ExtLib"

 

' Include the MaxMAL Library

$INCLUDE "MyBASIC2_MaxMAL"

$LIBRARY "MyBASIC2_MaxMALLib"

 

' Forward Declare PrintArray and DisplayVersion

DECLARE SUB PrintArray

DECLARE SUB DisplayVersion

 

' Declare variables and arrays

DIM nPoints AS INTEGER

DIM nFrames AS INTEGER

DIM hFile   AS INTEGER

 

' Test File

CONST cFileName = "e:\walk8Invalids3.c3d"

 

CLS

 

' Display the current Library Version

CALL DisplayVersion()

 

' Open the Test File

hFile = C3DFile.Open( cFileName );

 

IF NOT hFile > 0 THEN

  PRINT "Error Opening File ";cFileName,

  STOP

ENDIF

 

' Get the no of points and frames

nFrames = C3DFile.GetNoOfFrames( hFile )

nPoints = C3DFile.GetNoOfPoints( hFile )

 

' Dimension the arrays

DIM Position(nFrames,nPoints,3)     AS REAL

DIM Normalized(nFrames,nPoints,3)   AS REAL

DIM Interpolated(nFrames,nPoints,3) AS REAL

DIM Filtered(nFrames,nPoints,3)     AS REAL

 

' Get the Point Coordinates from C3D file

IF C3DFile.GetPoints( hFile, Position ) <> nFrames THEN

  C3DFile.Close( hFile )

  PRINT "Error Reading ";nPoints;" from file ";cFileName,

  STOP

ENDIF

 

' Set the Frame Rate to use in the MaxMAL Library

MAL.FrameRate( C3DFile.GetFrameRate( hFile ) )

 

' Display the Position Coordinates

CALL PrintArray( REF( Position ) )

 

' Interpolate the data

MAL.Interpolate( Interpolated, Position, ML_SPLINE, 60, 2 )

CALL PrintArray( REF( Interpolated ) )

 

' Smooth the data with moving average (Default)

MAL.Filter( Filtered, Interpolated )

CALL PrintArray( REF( Filtered ) )

 

' Normalize the Data

MAL.Normalize( Normalized, Filtered )

CALL PrintArray( REF( Normalized ) )

 

' Just Normalize Point #1

CALL PrintArray( MAL.Normalize( Filtered, 3, TRUE, 1  ) )

 

' Close File

C3DFile.Close( hFile )

 

END

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Print an array with up to 3 dimensions.  Array is passed as a reference

'

SUB PrintArray( arr AS REFERENCE )

  RUN( "ArrayPlot",  arr, TRUE )

END SUB

 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Display the MaxMAL Extension Library Version

'

SUB DisplayVersion()

  DIM major AS INTEGER

  DIM minor AS INTEGER

  DIM build AS INTEGER

  DIM qfe   AS INTEGER

 

  major = BYTE.HI( WORD.HI( MAL.Version() ) )

  minor = BYTE.LO( WORD.HI( MAL.Version() ) )

  build = BYTE.HI( WORD.LO( MAL.Version() ) )

  qfe   = BYTE.LO( WORD.LO( MAL.Version() ) )

 

  PRINT "Library Version: ";FORMAT( "%d, %d, %d, %d", major, minor, build, qfe ),

  PRINT "Option Flags:    ";FORMAT( "0x%08X", MAL.Version( TRUE ) ),

END SUB