14 #define M_PI 3.14159265358979323846 15 #define M_2PI 6.28318530717958647692 20 double OmegaC,
double BW,
TWindowType WindowType,
double WinBeta)
23 double Arg, OmegaLow, OmegaHigh;
28 for (j = 0; j < NumTaps; j++)
30 Arg = (double) j - (
double) (NumTaps - 1) / 2.0;
31 FirCoeff[j] = OmegaC *
Sinc(OmegaC * Arg *
M_PI);
38 for (j = 0; j < NumTaps; j++)
40 Arg = (double) j - (
double) (NumTaps - 1) / 2.0;
42 - OmegaC *
Sinc(OmegaC * Arg * M_PI);
48 for (j = 0; j < NumTaps; j++)
50 Arg = (double) j - (
double) (NumTaps - 1) / 2.0;
54 FirCoeff[j] =
cos(OmegaC * Arg *
M_PI) / M_PI / Arg
61 OmegaLow = OmegaC - BW / 2.0;
62 OmegaHigh = OmegaC + BW / 2.0;
63 for (j = 0; j < NumTaps; j++)
65 Arg = (double) j - (
double) (NumTaps - 1) / 2.0;
69 FirCoeff[j] = (
cos(OmegaLow * Arg *
M_PI)
70 -
cos(OmegaHigh * Arg * M_PI)) / M_PI / Arg;
75 OmegaLow = OmegaC - BW / 2.0;
76 OmegaHigh = OmegaC + BW / 2.0;
77 for (j = 0; j < NumTaps; j++)
79 Arg = (double) j - (
double) (NumTaps - 1) / 2.0;
81 - OmegaHigh *
Sinc(OmegaHigh * Arg * M_PI)
82 - OmegaLow *
Sinc(OmegaLow * Arg * M_PI);
90 WindowData(FirCoeff, NumTaps, WindowType, 0.0, WinBeta,
false);
99 double Sum = 0.0, XtoIpower;
101 for (i = 1; i < 10; i++)
103 XtoIpower = pow(x / 2.0, (
double) i);
105 for (j = 1; j <=
i; j++)
107 Sum += pow(XtoIpower / (
double) Factorial, 2.0);
117 if (x > -1.0E-5 && x < 1.0E-5)
174 double Beta,
bool UnityGain)
180 double dM, *WinCoeff;
195 WinCoeff =
new (std::nothrow)
double[N + 2];
199 <<
"Failed to allocate memory in FFTFunctions::WindowFFTData() " 204 TopWidth = (int) (Alpha * (
double) N);
205 if (TopWidth % 2 != 0)
217 for (j = 0; j < M; j++)
219 Arg = Beta *
sqrt(1.0 - pow(((
double) (2 * j + 2) - dM) / dM, 2.0));
224 else if (WindowType ==
wtSINC)
226 for (j = 0; j < M; j++)
227 WinCoeff[j] =
Sinc((
double) (2 * j + 1 - M) / dM *
M_PI);
228 for (j = 0; j < M; j++)
229 WinCoeff[j] = pow(WinCoeff[j], Beta);
232 else if (WindowType ==
wtSINE)
234 for (j = 0; j < M / 2; j++)
235 WinCoeff[j] =
sin((
double) (j + 1) *
M_PI / dM);
236 for (j = 0; j < M / 2; j++)
237 WinCoeff[j] = pow(WinCoeff[j], Beta);
242 for (j = 0; j < M / 2; j++)
243 WinCoeff[j] = 0.5 - 0.5 *
cos((
double) (j + 1) *
M_2PI / dM);
248 for (j = 0; j < M / 2; j++)
249 WinCoeff[j] = 0.54 - 0.46 *
cos((
double) (j + 1) *
M_2PI / dM);
254 for (j = 0; j < M / 2; j++)
256 WinCoeff[j] = 0.42 - 0.50 *
cos((
double) (j + 1) *
M_2PI / dM)
257 + 0.08 *
cos((
double) (j + 1) *
M_2PI * 2.0 / dM);
264 for (j = 0; j <= M / 2; j++)
267 - 1.93293488969227 *
cos((
double) (j + 1) *
M_2PI / dM)
269 *
cos((
double) (j + 1) *
M_2PI * 2.0 / dM)
271 *
cos((
double) (j + 1) *
M_2PI * 3.0 / dM)
273 *
cos((
double) (j + 1) *
M_2PI * 4.0 / dM);
279 for (j = 0; j < M / 2; j++)
281 WinCoeff[j] = 0.35875 - 0.48829 *
cos((
double) (j + 1) *
M_2PI / dM)
282 + 0.14128 *
cos((
double) (j + 1) *
M_2PI * 2.0 / dM)
283 - 0.01168 *
cos((
double) (j + 1) *
M_2PI * 3.0 / dM);
289 for (j = 0; j < M / 2; j++)
291 WinCoeff[j] = 0.3535819
292 - 0.4891775 *
cos((
double) (j + 1) *
M_2PI / dM)
293 + 0.1365995 *
cos((
double) (j + 1) *
M_2PI * 2.0 / dM)
294 - 0.0106411 *
cos((
double) (j + 1) *
M_2PI * 3.0 / dM);
300 for (j = 0; j < M / 2; j++)
302 WinCoeff[j] = 0.355768
303 - 0.487396 *
cos((
double) (j + 1) *
M_2PI / dM)
304 + 0.144232 *
cos((
double) (j + 1) *
M_2PI * 2.0 / dM)
305 - 0.012604 *
cos((
double) (j + 1) *
M_2PI * 3.0 / dM);
311 for (j = 0; j <= M / 2; j++)
313 WinCoeff[j] = 0.402 - 0.498 *
cos(
M_2PI * (
double) (j + 1) / dM)
314 + 0.098 *
cos(2.0 *
M_2PI * (
double) (j + 1) / dM)
315 + 0.001 *
cos(3.0 *
M_2PI * (
double) (j + 1) / dM);
324 for (j = 0; j < K; j++)
325 WinCoeff[j] = (
double) (j + 1) / (
double) K;
333 else if (WindowType ==
wtGAUSS)
335 for (j = 0; j < M / 2; j++)
337 WinCoeff[j] = ((double) (j + 1) - dM / 2.0) / (dM / 2.0) * 2.7183;
338 WinCoeff[j] *= WinCoeff[j];
339 WinCoeff[j] =
exp(-WinCoeff[j]);
345 std::cerr <<
"Incorrect window type in WindowFFTData" << std::endl;
351 for (j = 0; j < M / 2; j++)
352 WinCoeff[N - j - 1] = WinCoeff[j];
357 for (j = M / 2; j < N - M / 2; j++)
365 for (j = 0; j < N; j++)
369 for (j = 0; j < N; j++)
374 for (j = 0; j < N; j++)
375 Data[j] *= WinCoeff[j];
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
static void WindowData(double *Data, int N, TWindowType WindowType, double Alpha, double Beta, bool UnityGain)
Fixed< IntType, IntBits > exp(Fixed< IntType, IntBits > const &x)
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
static void BasicFIR(double *FirCoeff, int NumTaps, TPassTypeName PassType, double OmegaC, double BW, TWindowType WindowType, double WinBeta)
Fixed< IntType, IntBits > sqrt(Fixed< IntType, IntBits > const &x)
static double Bessel(double x)
static double Sinc(double x)