示例#1
0
void WFIR::WindowData(double *Data, int N, TWindowType WindowType, double Alpha,
        double Beta, bool UnityGain)
{
    if (WindowType == wtNONE)
        return;

    int j, M, TopWidth;
    double dM, *WinCoeff;

    if (WindowType == wtKAISER || WindowType == wtFLATTOP)
        Alpha = 0.0;

    if (Alpha < 0.0)
        Alpha = 0.0;
    if (Alpha > 1.0)
        Alpha = 1.0;

    if (Beta < 0.0)
        Beta = 0.0;
    if (Beta > 10.0)
        Beta = 10.0;

    WinCoeff = new (std::nothrow) double[N + 2];
    if (WinCoeff == 0)
    {
        std::cerr
                << "Failed to allocate memory in FFTFunctions::WindowFFTData() "
                << std::endl;
        return;
    }

    TopWidth = (int) (Alpha * (double) N);
    if (TopWidth % 2 != 0)
        TopWidth++;
    if (TopWidth > N)
        TopWidth = N;
    M = N - TopWidth;
    dM = M + 1;

    // Calculate the window for N/2 points, then fold the window over (at the bottom).
    // TopWidth points will be set to 1.
    if (WindowType == wtKAISER)
    {
        double Arg;
        for (j = 0; j < M; j++)
        {
            Arg = Beta * sqrt(1.0 - pow(((double) (2 * j + 2) - dM) / dM, 2.0));
            WinCoeff[j] = Bessel(Arg) / Bessel(Beta);
        }
    }

    else if (WindowType == wtSINC)  // Lanczos
    {
        for (j = 0; j < M; j++)
            WinCoeff[j] = Sinc((double) (2 * j + 1 - M) / dM * M_PI);
        for (j = 0; j < M; j++)
            WinCoeff[j] = pow(WinCoeff[j], Beta);
    }

    else if (WindowType == wtSINE)  // Hanning if Beta = 2
    {
        for (j = 0; j < M / 2; j++)
            WinCoeff[j] = sin((double) (j + 1) * M_PI / dM);
        for (j = 0; j < M / 2; j++)
            WinCoeff[j] = pow(WinCoeff[j], Beta);
    }

    else if (WindowType == wtHANNING)
    {
        for (j = 0; j < M / 2; j++)
            WinCoeff[j] = 0.5 - 0.5 * cos((double) (j + 1) * M_2PI / dM);
    }

    else if (WindowType == wtHAMMING)
    {
        for (j = 0; j < M / 2; j++)
            WinCoeff[j] = 0.54 - 0.46 * cos((double) (j + 1) * M_2PI / dM);
    }

    else if (WindowType == wtBLACKMAN)
    {
        for (j = 0; j < M / 2; j++)
        {
            WinCoeff[j] = 0.42 - 0.50 * cos((double) (j + 1) * M_2PI / dM)
                    + 0.08 * cos((double) (j + 1) * M_2PI * 2.0 / dM);
        }
    }

    // See: http://www.bth.se/fou/forskinfo.nsf/0/130c0940c5e7ffcdc1256f7f0065ac60/$file/ICOTA_2004_ttr_icl_mdh.pdf
    else if (WindowType == wtFLATTOP)
    {
        for (j = 0; j <= M / 2; j++)
        {
            WinCoeff[j] = 1.0
                    - 1.93293488969227 * cos((double) (j + 1) * M_2PI / dM)
                    + 1.28349769674027
                            * cos((double) (j + 1) * M_2PI * 2.0 / dM)
                    - 0.38130801681619
                            * cos((double) (j + 1) * M_2PI * 3.0 / dM)
                    + 0.02929730258511
                            * cos((double) (j + 1) * M_2PI * 4.0 / dM);
        }
    }

    else if (WindowType == wtBLACKMAN_HARRIS)
    {
        for (j = 0; j < M / 2; j++)
        {
            WinCoeff[j] = 0.35875 - 0.48829 * cos((double) (j + 1) * M_2PI / dM)
                    + 0.14128 * cos((double) (j + 1) * M_2PI * 2.0 / dM)
                    - 0.01168 * cos((double) (j + 1) * M_2PI * 3.0 / dM);
        }
    }

    else if (WindowType == wtBLACKMAN_NUTTALL)
    {
        for (j = 0; j < M / 2; j++)
        {
            WinCoeff[j] = 0.3535819
                    - 0.4891775 * cos((double) (j + 1) * M_2PI / dM)
                    + 0.1365995 * cos((double) (j + 1) * M_2PI * 2.0 / dM)
                    - 0.0106411 * cos((double) (j + 1) * M_2PI * 3.0 / dM);
        }
    }

    else if (WindowType == wtNUTTALL)
    {
        for (j = 0; j < M / 2; j++)
        {
            WinCoeff[j] = 0.355768
                    - 0.487396 * cos((double) (j + 1) * M_2PI / dM)
                    + 0.144232 * cos((double) (j + 1) * M_2PI * 2.0 / dM)
                    - 0.012604 * cos((double) (j + 1) * M_2PI * 3.0 / dM);
        }
    }

    else if (WindowType == wtKAISER_BESSEL)
    {
        for (j = 0; j <= M / 2; j++)
        {
            WinCoeff[j] = 0.402 - 0.498 * cos(M_2PI * (double) (j + 1) / dM)
                    + 0.098 * cos(2.0 * M_2PI * (double) (j + 1) / dM)
                    + 0.001 * cos(3.0 * M_2PI * (double) (j + 1) / dM);
        }
    }

    else if (WindowType == wtTRAPEZOID) // Rectangle for Alpha = 1  Triangle for Alpha = 0
    {
        int K = M / 2;
        if (M % 2)
            K++;
        for (j = 0; j < K; j++)
            WinCoeff[j] = (double) (j + 1) / (double) K;
    }

    // This definition is from http://en.wikipedia.org/wiki/Window_function (Gauss Generalized normal window)
    // We set their p = 2, and use Alpha in the numerator, instead of Sigma in the denominator, as most others do.
    // Alpha = 2.718 puts the Gauss window response midway between the Hanning and the Flattop (basically what we want).
    // It also gives the same BW as the Gauss window used in the HP 89410A Vector Signal Analyzer.
    // Alpha = 1.8 puts it quite close to the Hanning.
    else if (WindowType == wtGAUSS)
    {
        for (j = 0; j < M / 2; j++)
        {
            WinCoeff[j] = ((double) (j + 1) - dM / 2.0) / (dM / 2.0) * 2.7183;
            WinCoeff[j] *= WinCoeff[j];
            WinCoeff[j] = exp(-WinCoeff[j]);
        }
    }

    else // Error.
    {
        std::cerr << "Incorrect window type in WindowFFTData" << std::endl;
        delete[] WinCoeff;
        return;
    }

    // Fold the coefficients over.
    for (j = 0; j < M / 2; j++)
        WinCoeff[N - j - 1] = WinCoeff[j];

    // This is the flat top if Alpha > 0. Cannot be applied to a Kaiser or Flat Top.
    if (WindowType != wtKAISER && WindowType != wtFLATTOP)
    {
        for (j = M / 2; j < N - M / 2; j++)
            WinCoeff[j] = 1.0;
    }

    // This will set the gain of the window to 1. Only the Flattop window has unity gain by design.
    if (UnityGain)
    {
        double Sum = 0.0;
        for (j = 0; j < N; j++)
            Sum += WinCoeff[j];
        Sum /= (double) N;
        if (Sum != 0.0)
            for (j = 0; j < N; j++)
                WinCoeff[j] /= Sum;
    }

    // Apply the window to the data.
    for (j = 0; j < N; j++)
        Data[j] *= WinCoeff[j];

    delete[] WinCoeff;

}
示例#2
0
mat dBessel(double w, int order){
    mat AB_ = Bessel(w,order);
    AB_(1,1) = AB_(0,0);
    AB_(1,0) = 0;
    return AB_;
}
示例#3
0
mat Bessel_d(double T, double w, int order){
    return Tustin(T,w,Bessel(w,order));
}
示例#4
0
static double BlackmanBessel(const double x, const double support)
{
	return(Blackman(x/support,support)*Bessel(x,support));
}