Filter data with a median filter.
Filter data in Src with a median filter and place the result in Dst. 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 atomatically adjusted.
Filter data in Data with a median filter from DataIndex to DataIndex+Len and place the result back in the Data. Set the mask size of the median filter to MaskSize. If Len is MtxVecEOA, the maximum length of the Data vector will be used.
Example 1
Median filter applied to a single block of data.
uses MtxExpr, Math387, MtxVec, SignalUtils, MtxVecTee, MtxVecEdit,OptimalFir;
procedure TForm1.Button1Click(Sender: TObject);
var b,c: Vector;
begin
b.Size(300);
b.SetSubRange(0,150);
b.Ramp(0,1);
b.SetSubRange(150,150);
b.Ramp(150,-1); //creates a triangle
b.SetFullRange;
MedianFilter(b,c,9);
MedianFilter(b,9); //Alternative (in-place)
if not b.Equal(c) then ERaise('Not equal');
end;
#include "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project
#include "MtxVecEdit.hpp"
#include "MtxVecTee.hpp"
#include "SignalUtils.hpp"
#include "OptimalFir.hpp"
#include <string.h>
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Vector b,c;
b->Size(300);
//creates a triangle:
b(0,149)->Ramp(0,1);
b(150,299)->Ramp(150,-1);
DrawIt(b);
MedianFilter(b,c,9);
MedianFilter(b,9); //Alternative (in-place)
if (!(b->Equal(c))) throw "Not equal";
}
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");
}
Declaration
Procedure MedianFilter(Src, Dst: TVec; State: TMedianState);
Description
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.
Declaration
Procedure MedianFilter(Src, Dst: TVec; MaskSize: integer; SrcIndex: integer; DstIndex: integer; Len: integer = -1);
Description
Filter data in Src from SrcIndex to SrcIndex+Len with a median filter and place the result in Dst from DstIndex position on. 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.