Overload List
| # | Signature | Description |
|---|---|---|
| 1 | void FirFilter(TCplx Src, ref TCplx Dst, ref TFirState FIRState) | Filter data with a FIR filter. |
| 2 | void FirFilter(TVec Src, TVec Dst, ref TFirState FIRState) | Filter data with a FIR filter. |
| 3 | void FirFilter(TVec Data, TVec FirTaps, Int32 UpSample, Int32 DownSample) | Filter Data with a FIR filter and place the result back in the Data. |
| 4 | void FirFilter(Double Src, ref Double Dst, ref TFirState FIRState) | Filter data with a FIR filter. |
Overload 1: void FirFilter(TCplx Src, ref TCplx Dst, ref TFirState FIRState)
Filter data with a FIR filter.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Src | TCplx | scalar |
| 2 | Dst | TCplx (ref) | output |
| 3 | FIRState | TFirState (ref) |
Result: stored in self (calling object)
Filter real TCplx sample and place the filtered result in Dst sample.
Overload 2: void FirFilter(TVec Src, TVec Dst, ref TFirState FIRState)
Filter data with a FIR filter.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Src | TVec | source TVec |
| 2 | Dst | TVec | source TVec |
| 3 | FIRState | TFirState (ref) |
Result: stored in self (calling object)
Filter data in Src and place the result in Dst. FirState must be initialized with a call to FirInit. This version of FirFilter routine can filter streaming blocks of data.
Overload 3: void FirFilter(TVec Data, TVec FirTaps, Int32 UpSample, Int32 DownSample)
Filter Data with a FIR filter and place the result back in the Data.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Data | TVec | source TVec |
| 2 | FirTaps | TVec | source TVec |
| 3 | UpSample | Int32 | |
| 4 | DownSample | Int32 |
Result: stored in self (calling object)
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).
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);
}
Overload 4: void FirFilter(Double Src, ref Double Dst, ref TFirState FIRState)
Filter data with a FIR filter.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Src | Double | scalar |
| 2 | Dst | Double (ref) | output |
| 3 | FIRState | TFirState (ref) |
Result: stored in self (calling object)
Filter real Src sample and place the filtered result in Dst sample.