You are here: Symbol Reference > Dew Namespace > Dew.Signal Namespace > Dew.Signal.Units Namespace > Classes > SignalUtils Class > SignalUtils Methods > FirFilter Method > SignalUtils.FirFilter Method ([In] TVec, [In] TVec, int, int)
Dew Signal for .NET
ContentsIndexHome
PreviousUpNext
SignalUtils.FirFilter Method ([In] TVec, [In] TVec, int, int)

Filter Data with a FIR filter and place the result back in the Data.

Syntax
C#
Visual Basic
public static void FirFilter([In] TVec Data, [In] TVec FirTaps, int UpSample, int DownSample);

This version of FirFilter can not be used to filter streaming data. The routine compensates for group delay and returns filtered data delayed by 0 (odd FIR length) or 0.5 samples (even FIR length).

Lowpass filter a signal with a FIR filter. Sampling frequency is 2Hz, cutoff frequency is 0.6 Hz. Stopand passband ripple is 0.001. 

 

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 h = new Vector(0); Vector Response1 = new Vector(0); Vector Response2 = new Vector(0); TFirState state = new TFirState(); int n; int i; double FS = 2; SignalUtils.Tone(b,300,6.0/300,0,1,false); // Alternative: try gaussian noise // b = MtxExpr.RandGauss(300); c.Size(b); OptimalFir.RemezImpulse(h, new double[2] { 0.5, 0.7 }, 0.001, TFilterType.ftLowpass, 1, FS,false); SignalUtils.FirInit(h,ref state,1,0,1,0); try { //Alternative 1, FIR streaming n = 10; int bLength = b.Length; //to prevente reevaluaton inside "for" for (i = 0; i < (bLength/n); i++) { b.SetSubRange(i*n,n); c.SetSubRange(i*n,n); SignalUtils.FirFilter(b,c,ref state); } } finally { c.SetFullRange(); b.SetFullRange(); SignalUtils.FirFree(ref state); } //Alternative 2 single block filter (does not require TFirState) // c.Copy(b); // SignalUtils.FirFilter(c,h,1,1); //Alternative 3 single block // c.Copy(b); // SignalUtils.FirFilter(b,c,state); MtxVecTee.DrawIt(new TVec[2] {b,c}, new string[2] {"Original signal","Filtered signal"},"Time signals", false); SignalUtils.FrequencyResponse(b, null, Response1, 1, true, TSignalWindowType.wtHanning, 0); SignalUtils.FrequencyResponse(c, null, Response2, 1, true, TSignalWindowType.wtHanning, 0); MtxVecTee.DrawIt(new TVec[2] {Response1,Response2}, new string[2] {"Spectrum: original signal","Spectrum: filtered signal"}, "Frequency spectrum", false); }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!