www.pudn.com > FIRDsgn.rar > DrawMag.cpp
//######################################################################## // This program is provided "as is" without any express // or implied warranty of any kind with respect to this software. // In particular the author shall not be liable for any direct, // indirect, special, incidental or consequential damages arising // in any way from use of the software. // // // Author : Jialong He, // Date : July, 1999. // // Contact : Jialong_He@bigfoot.com, Jialong_He@homemail.com // Web Page : www.bigfoot.com/~Jialong_He //######################################################################## // DrawMag.cpp : implementation file // #include "stdafx.h" #include "FIRDsgn.h" #include "DrawMag.h" #include#define FFTSize 1024 #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDrawMag CDrawMag::CDrawMag() { m_BrushBlack.lbStyle = BS_SOLID; m_BrushBlack.lbColor = RGB(0, 0, 0); m_BrushBlack.lbHatch = 0; m_BrushCross.lbStyle = BS_HATCHED; m_BrushCross.lbColor = RGB(0, 255, 0); m_BrushCross.lbHatch = HS_CROSS; MagArr = NULL; MagLen = 0; } CDrawMag::~CDrawMag() { delete [] MagArr; } BEGIN_MESSAGE_MAP(CDrawMag, CWnd) //{{AFX_MSG_MAP(CDrawMag) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDrawMag message handlers void CDrawMag::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; dc.SetPolyFillMode(WINDING); CBrush brushBlack(m_BrushBlack.lbColor); // CBrush brushCross(HS_CROSS, RGB(0, 0, 0)); GetClientRect(rect); dc.FillRect(&rect, &brushBlack); // dc.SelectObject(&brushCross); // dc.Rectangle(rect); //------------------------------ // draw grid in green color //------------------------------ int x, y, xstep, ystep; int H = rect.Height(); int W = rect.Width(); CPen GreenPen(PS_DOT, 1, RGB(0, 255, 0)); dc.SelectObject(&GreenPen); xstep = W / 10; for (x=0; x real = wrecur_real; xj->imag = wrecur_imag; xj++; wtemp_real = wrecur_real*w_real - wrecur_imag*w_imag; wrecur_imag = wrecur_real*w_imag + wrecur_imag*w_real; wrecur_real = wtemp_real; } } /* start fft */ le = n; windex = 1; for (l = 0 ; l < m ; l++) { le = le/2; /* first iteration with no multiplies */ for(i = 0 ; i < n ; i = i + 2*le) { xi = x + i; xip = xi + le; temp.real = xi->real + xip->real; temp.imag = xi->imag + xip->imag; xip->real = xi->real - xip->real; xip->imag = xi->imag - xip->imag; *xi = temp; } /* remaining iterations use stored w */ wptr = w + windex - 1; for (j = 1 ; j < le ; j++) { u = *wptr; for (i = j ; i < n ; i = i + 2*le) { xi = x + i; xip = xi + le; temp.real = xi->real + xip->real; temp.imag = xi->imag + xip->imag; tm.real = xi->real - xip->real; tm.imag = xi->imag - xip->imag; xip->real = tm.real*u.real - tm.imag*u.imag; xip->imag = tm.real*u.imag + tm.imag*u.real; *xi = temp; } wptr = wptr + windex; } windex = 2*windex; } /* rearrange data by bit reversing */ j = 0; for (i = 1 ; i < (n-1) ; i++) { k = n/2; while(k <= j) { j = j - k; k = k/2; } j = j + k; if (i < j) { xi = x + i; xj = x + j; temp = *xj; *xj = *xi; *xi = temp; } } return (0); } //==================================================== // calculate impulse response of FIR filter //==================================================== int CDrawMag::imp_response(double *FCoef, int FNum) { COMPLEX *Sig; int Cnt, RtCode; if (FNum > FFTSize ) { return(-1); // error } Sig = new COMPLEX[FFTSize]; if (Sig == NULL) { return(-1); // error } //--------------------------- // copy coefficients to Sig //--------------------------- for (Cnt=0; Cnt