You are here: Symbol Reference > Dew Namespace > Dew.Signal Namespace > Dew.Signal.Units Namespace > Classes > SignalUtils Class > SignalUtils Methods > DcFilter Method > SignalUtils.DcFilter Method (double, TCplx, double)
Dew Signal for .NET
ContentsIndexHome
PreviousUpNext
SignalUtils.DcFilter Method (double, TCplx, double)

State parameter holds the filter state.

Syntax
C#
Visual Basic
public static double DcFilter(double NewValue, ref TCplx State, double alpha);

NewValue is the next sample and alpha is typically between 0.99 and 0.9999 and must be < 1. Big alpha will cause longer filter delay and more ringing. State should be initialized to zero before the routine is called for the first time.

DC filtering.

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); Vector num = new Vector(0); Vector x = new Vector(0); Vector den = new Vector(0); Vector Response = new Vector(0); int n; int i; TIirState IirState = new TIirState(); TCplx DCState; SignalUtils.Tone(b,300,5.0/300,0,1,false); //generate sine with 5 periods in 300 samples // Alternative: // b.RandGauss; b = b + 2; c.Copy(b); n = 10; SignalUtils.DcFilter(0.95,num,den); SignalUtils.IirInit(num,den,ref IirState,false); int bLength = b.Length; for (i = 0; i < (bLength/n); i++) //only to test the streaming { b.SetSubRange(i*n,n); c.SetSubRange(i*n,n); SignalUtils.IirFilter(b,c,ref IirState); } b.SetFullRange(); c.SetFullRange(); MtxVecTee.DrawIt(new TVec[2] { b, c }, new string[2] { "Unfiltered", "Filtered" }, "DC IirFilter", false); SignalUtils.FrequencyResponse(num,den,Response,64,false,TSignalWindowType.wtRectangular,0); MtxVecTee.DrawIt(Response,"Frequency response",false); SignalUtils.DcFilter(0.05,2,num,den); SignalUtils.IirInit(num,den,ref IirState,false); bLength = b.Length; for (i = 0; i < (bLength/n); i++) //only to test the streaming { b.SetSubRange(i*n,n); c.SetSubRange(i*n,n); SignalUtils.IirFilter(b,c,ref IirState); } b.SetFullRange(); c.SetFullRange(); MtxVecTee.DrawIt(new TVec[2] { b, c }, new string[2] { "Unfiltered", "Filtered" }, "DC IirFilter", false); SignalUtils.FrequencyResponse(num,den,Response,64,false,TSignalWindowType.wtRectangular,0); MtxVecTee.DrawIt(Response,"Frequency response",false); DCState = Math387.C_ZERO; for (i = 0; i < (b.Length); i++) //only to test the streaming { c.Values[i] = SignalUtils.DcFilter(b.Values[i],ref DCState,0.95); } MtxVecTee.DrawIt(new TVec[2] { b, c }, new string[2] { "Unfiltered", "Filtered" }, "DC IirFilter", false); }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!