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

Design a FIR filter with rectangular window.

Syntax
C#
Visual Basic
public static void FirImpulse([In] TVec H, double[] W, TFilterType FilterType, double FS);

Compute a FIR impulse response filter (no window applied) and place the result in H. The transition regions are defined with the W array. There must be at least one (lowpass, highpass) and at most two (bandpass, bandstop) transition regions (2 or 4 elements). Filter type is defined with TFilterType. The length of the filter H.Length must be preset. Filters of even length (odd order), must have a stop band next to the nyquist (FS/2) frequency. 20*Log10(Ripple) is also the required attenuation of the stop band in decibel. FS is the sampling frequency.

Impulse responses of FIR filters.

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 h = new Vector(0); Vector response = new Vector(0); Vector x = new Vector(0); double FS = 2; int n = 41; //lowpass design with cutoff frequency SignalUtils.FirImpulse(h.Size(n), new double[1] {0.5}, TFilterType.ftLowpass,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); x = MtxExpr.Ramp(response.Length, TMtxFloatPrecision.mvDouble, 0, 1.0/response.Length); MtxVecTee.DrawIt(x,response,"Lowpass with cutoff at 0.5",false); //lowpass design with transition band SignalUtils.FirImpulse(h.Size(n), new double[2] {0.3,0.5}, TFilterType.ftLowpass,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response,"Lowpass with transition band: 0.3-0.5",false); //Highpass design with cutoff frequency SignalUtils.FirImpulse(h.Size(n), new double[1] {0.5}, TFilterType.ftHighpass,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response,"Highpass with cutoff at 0.5",false); //Highpass design with transition band SignalUtils.FirImpulse(h.Size(n), new double[2] {0.3,0.5}, TFilterType.ftHighpass,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response,"Highpass with transition band: 0.3-0.5",false); //Bandpass design with transition bands SignalUtils.FirImpulse(h.Size(n), new double[4] {0.3,0.4,0.5,0.6}, TFilterType.ftBandpass,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response,"Bandpass with transitoin band: 0.3-0.4, 0.5-0.6",false); //Bandstop design with transition bands SignalUtils.FirImpulse(h.Size(n), new double[4] {0.3,0.4,0.5,0.6}, TFilterType.ftBandstop,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response,"Bandstop with transition bands: 0.3-0.4, 0.5-0.6",false); //Hilbert III SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftHilbertIII,FS); SignalUtils.FrequencyResponse(h,null,response,8,false,TSignalWindowType.wtRectangular,0); MtxVecTee.DrawIt(x,response,"Hilbert III",false); //Hilbert IV n++; //n must be even SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftHilbertIV,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response,"Hilbert IV", false); //Differentiator III n--; // n must be odd SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftDifferentiatorIII,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response, "Differentiator III",false); //Differentiator IV n++; //n must be even SignalUtils.FirImpulse(h.Size(n), new double[1] {0}, TFilterType.ftDifferentiatorIV,FS); SignalUtils.FrequencyResponse(h, null, response, 8, false, TSignalWindowType.wtRectangular, 0); MtxVecTee.DrawIt(x,response, "Differentiator IV", false); }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!