/************************************************************** * Program to demonstrate the Butterworth filter * * (removing frequencies greater than Fc) * * * * C++ version with graphic results by J-P Moreau, Paris * * (www.jpmoreau.fr) * * * * (use with tgfft.mak and graph2d.cpp) * * ----------------------------------------------------------- * * SAMPLE RUN: * * * * Input data file (tfft.dat): * * * * (The test signal contains 3 frequencies: 50, 250, 500 hz) * * * * 1024 * * 0.00000000000000E+0000 0.00000000000000E+0000 * * 1.95503421309917E-0004 3.53914399999776E+0001 * * 3.91006842619834E-0004 5.95684899999760E+0001 * * 5.86510263929974E-0004 6.54621699999552E+0001 * * 7.82013685239669E-0004 5.24038399999845E+0001 * * ... ... * * 1.98826979472187E-0001 2.77372500000183E-0001 * * 1.99022482893497E-0001 -2.43361500000174E+0000 * * 1.99217986314807E-0001 -4.84236799999780E+0000 * * 1.99413489736116E-0001 -6.02247899999929E+0000 * * 1.99608993157426E-0001 -5.45615399999951E+0000 * * 1.99804496578736E-0001 -3.22824200000105E+0000 * * 2.00000000000045E-0001 -2.96010699999982E-0003 * * * * Output file (tfilter.lst): * * * * Time Input Signal Filtered Signal * * ------------------------------------------------------- * * 0.0000 0.000000 0.000000 * * 0.0002 35.391440 0.158005 * * 0.0004 59.568490 1.278083 * * 0.0006 65.462170 5.003994 * * 0.0008 52.403840 12.809453 * * 0.0010 26.229620 24.336649 * * ... ... ... * * 0.1988 0.277373 -2.224546 * * 0.1990 -2.433615 -0.802179 * * 0.1992 -4.842368 0.588941 * * 0.1994 -6.022479 1.320860 * * 0.1996 -5.456154 1.036090 * * 0.1998 -3.228242 -0.213007 * * 0.2000 -0.002960 -1.978450 * * * * Note: The cut off frequency Fc is 500 hz, the filter order * * is 4 (A Fourier analysis of the filtered signal shows * * that frequencies greater than Fc are satisfactorily * * removed but with a slight time shift of the signal). * **************************************************************/ #include #include #include HDC hdc; RECT rect; HPEN hpen, hpenOld; //Functions used here of Graph2D.cpp void CourbeXY(int,int,float *,double,double); void Legendes (int,char *,char *,char *,int,int,char *,int,int,char *); //"home made" graphic commands for hdc environment used by above functions void DrawPixel(int ix,int iy) { //sorry, no other available command found Rectangle(hdc,rect.left+ix,rect.top+iy, rect.left+ix+2,rect.top+iy+1); } void Swap(int *i1,int *i2) { int it; it=*i1; *i1=*i2; *i2=it; } void DrawLine(int ix1,int iy1,int ix2,int iy2) { int i,il,ix,iy; double dx,dy; if (ix2 2.0*Pi) { m=int(Arg/2.0/Pi); Arg=Arg-(m*2.0*Pi); } Omega= tan(Arg); OmegaSq=Omega*Omega; Modn=(n % 2); if (Modn==0) temp=HALF; else temp=ZERO; Ns2=n/2; *NSections=Ns2+Modn; *Tg=ZERO; if (n>1) for (i=1; i