DewDSPMasterNET
RemoveDC Routines
Summary
Remove the DC component.

Unit
SignalUtils

Declaration
Function RemoveDC(SrcDst: TVec; Index: integer; Len: integer = MtxVecEOA): TVec;

Description
Subtract the mean value of Data from Data. Works for stationary signals. Use a highpass FIR filter for signals with varying mean value or call the DCFilter routine, for an IIR version of the DC filter. Removing the DC component without applying a true FIR or IIR filter is often convinient prior to frequency analysis, because there is no run-in or run-out and no filter delay.
Categories
FIR filters
 See Also 
FirFilter 
KaiserImpulse 
RemezImpulse 

Example 1

The sampling frequency is 256 Hz. A tone has a frequency 6Hz, amplitude 1 and DC offset is 4.
uses MtxExpr, Math387, MtxVec, SignalUtils, MtxVecTee, MtxVecEdit; procedure TForm1.Button1Click(Sender: TObject); var b,c,Response1, Response2: Vector; begin Tone(b, 256,6/256,0,1); b := b + 4; //generate 6 periods within 256 samples, Phase = 0, Amplt = 1 c.Copy(b); RemoveDC(b); DrawIt([c,b],['Original signal','Signal without DC']); FrequencyResponse(c,nil,Response1,1,True); FrequencyResponse(b,nil,Response2,1,True); DrawIt([Response1, Response2],['Spectrum: original signal','Spectrum: signal without DC']); end;
#include "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project #include "MtxVecEdit.hpp" #include "MtxVecTee.hpp" #include "SignalUtils.hpp" void __fastcall TForm1::BitBtn1Click(TObject *Sender) { Vector b,c, Response1, Response2; b = Sin(Ramp(256,0,2*PI*6/256)) + 4; c->Copy(b); RemoveDC(b); DrawIt(OPENARRAY(TVec*,(c,b)),OPENARRAY(AnsiString,("Original signal","Signal without DC"))); FrequencyResponse(c,NULL,Response1,1,true); FrequencyResponse(b,NULL,Response2,1,true); DrawIt(OPENARRAY(TVec*,(Response1,Response2)),OPENARRAY(AnsiString,("Spectrum: original signal","Spectrum: without DC"))); }
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 Response1 = new Vector(0); Vector Response2 = new Vector(0); SignalUtils.Tone(b, 256, 6.0 / 256, 0, 1, false); b = b + 4; c.Copy(b); SignalUtils.RemoveDC(b); TeeChart.DrawIt(new TVec[2] {c,b}, new string[2] {"Original signal","Signal without DC"},"Time signals", false); SignalUtils.FrequencyResponse(c, null, Response1, 1, true, TSignalWindowType.wtRectangular, 0); SignalUtils.FrequencyResponse(b, null, Response2, 1, true, TSignalWindowType.wtRectangular, 0); TeeChart.DrawIt(new TVec[2] {Response1,Response2}, new string[2] {"Spectrum: original signal","Spectrum: signal without DC"}, "Frequency spectrum", false); }


Declaration
Procedure RemoveDC(Src, Dst: TVec; SrcIndex, DstIndex: integer; Len: integer = MtxVecEOA);

Description
Not-in-place version of the RemoveDC method with source and destination indexes. The Src data is preserved, the destination will hold the result. If Len is not specified, the maximum possible value will be used.
Declaration
Procedure RemoveDC(Src, Dst: TVec);

Description
Not-In-place version of the RemoveDC method.
Declaration
Function RemoveDC(SrcDst: TVec): TVec;

Description
In-place version of the RemoveDC method.

Copyright 2008 Dew Research
http://www.dewresearch.com