SignalUtils.MedianFilter Method

Overload List

#SignatureDescription
1void MedianFilter(TVec Src, TVec Dst, ref TMedianState State)Filter data with a median filter.
2void MedianFilter(TVec Src, TVec Dst, Int32 MaskSize)Filter data in Src with a median filter and place the result in Dst.
└ indexed: void MedianFilter(TVec Src, TVec Dst, Int32 MaskSize, Int32 SrcIndex, Int32 DstIndex, Int32 Len)
3void MedianFilter(TVec Data, Int32 MaskSize, Int32 DataIndex, Int32 Len)Filter data in Data with a median filter from DataIndex to DataIndex+Len and place the result back in the Data.

Overload 1: void MedianFilter(TVec Src, TVec Dst, ref TMedianState State)

Filter data with a median filter.

#NameTypeDescription
1SrcTVecsource TVec
2DstTVecsource TVec
3StateTMedianState (ref)

Result: stored in self (calling object)

Remarks:

Filter data in Src with a median filter configured with a call to MedianInit routine and place the result in the Dst. The length of the Dst will be set to match the Length of the Src. This MedianFilter routine can be used to filter streaming data.

Each output sample is the median of the current sample and the MaskSize-1 preceding samples of the stream. The delay line is initialized to zero by Dew.Signal.Units.SignalUtils.MedianInit and is carried across consecutive calls, so filtering a signal in chunks of any size gives the same result as filtering it in one call.

Overload 2: void MedianFilter(TVec Src, TVec Dst, Int32 MaskSize)

Filter data in Src with a median filter and place the result in Dst.

#NameTypeDescription
1SrcTVecsource TVec
2DstTVecsource TVec
3MaskSizeInt32

Result: stored in self (calling object)

Remarks:

MaskSize defines the size of the mask for the filter. This MedianFilter routine can be used to filter a block of data. The size of Dst is automatically adjusted.

Each output sample is the median of the current sample and the MaskSize-1 preceding samples; samples preceding the block are taken equal to its first sample. An even MaskSize is reduced to the next lower odd value.

Indexed: void MedianFilter(TVec Src, TVec Dst, Int32 MaskSize, Int32 SrcIndex, Int32 DstIndex, Int32 Len)

Filter data in Src from SrcIndex to SrcIndex+Len with a median filter and place the result in Dst from DstIndex position on.

#NameTypeDescription
1SrcTVecsource TVec
2DstTVecsource TVec
3MaskSizeInt32
4SrcIndexInt32source start index
5DstIndexInt32destination start index
6LenInt32element count

Result: stored in self (calling object)

Remarks:

MaskSize defines the size of the mask for the filter. This MedianFilter routine can be used to filter a block of data. The size of Dst is not adjusted.

Each output sample is the median of the current sample and the MaskSize-1 preceding samples; samples preceding the block are taken equal to its first sample. An even MaskSize is reduced to the next lower odd value. If MaskSize exceeds the length of Dst, it is reduced to Len.

Overload 3: void MedianFilter(TVec Data, Int32 MaskSize, Int32 DataIndex, Int32 Len)

Filter data in Data with a median filter from DataIndex to DataIndex+Len and place the result back in the Data.

#NameTypeDescription
1DataTVecsource TVec
2MaskSizeInt32
3DataIndexInt32
4LenInt32element count

Result: stored in self (calling object)

Remarks:

Set the mask size of the median filter to MaskSize. If Len is MtxVecEOA, the maximum length of the Data vector will be used.

Each output sample is the median of the current sample and the MaskSize-1 preceding samples; samples preceding the block are taken equal to its first sample. An even MaskSize is reduced to the next lower odd value.

Examples
using Dew.Math;
using Dew.Math.Editors;
using Dew.Math.Units;
using Dew.Signal;
using Dew.Signal.Units;
using Dew.Math.Tee;
using Dew.Signal.Tee;

private void button1_Click(object sender, EventArgs e)
{
    Vector b = new Vector(0);
    Vector c = new Vector(0);

    b.Size(300);

    b.SetSubRange(0,150);
    b.Ramp(0,1);
    b.SetSubRange(150,150);
    b.Ramp(150,-1);            //creates a triangle

    b.SetFullRange();
    SignalUtils.MedianFilter(b,c,9);
    SignalUtils.MedianFilter(b,9,0,Math387.MtxVecEOA); //Alternative (in-place)
    if (!(b.Equal(c,0))) throw new Exception("Not equal");
}
See Also: SignalUtils.MedianInit, SignalUtils.MedianFree