Пример #1
0
    private static void r4vec_sft_test()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    R4VEC_SFT_TEST tests R4VEC_SFTB and R4VEC_SFTF.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    10 June 2010
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        const float ahi   = 5.0f;
        const float alo   = 0.0f;
        float       azero = 0;
        int         i;
        const int   n = 36;

        Console.WriteLine("");
        Console.WriteLine("R4VEC_SFT_TEST");
        Console.WriteLine("  R4VEC_SFTF computes the forward slow Fourier transform.");
        Console.WriteLine("  R4VEC_SFTB computes the backward slow Fourier transform.");
        Console.WriteLine("");
        Console.WriteLine("  The number of data values, N = " + n + "");

        int seed = 123456789;

        float[] x = UniformRNG.r4vec_uniform_ab_new(n, alo, ahi, ref seed);

        typeMethods.r4vec_print_part(n, x, 10, "  The original data:");
        //
        //  Compute the slow Fourier transform of the data.
        //
        float[] a = new float[n / 2];
        float[] b = new float[n / 2];

        Slow.r4vec_sftf(n, x, ref azero, ref a, ref b);

        Console.WriteLine("");
        Console.WriteLine("  A (cosine) coefficients:");
        Console.WriteLine("");

        Console.WriteLine("  " + 0.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                          + "  " + azero.ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");

        for (i = 0; i < n / 2; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + a[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        Console.WriteLine("");
        Console.WriteLine("  B (sine) coefficients:");
        Console.WriteLine("");

        for (i = 0; i < n / 2; i++)
        {
            Console.WriteLine("  " + i.ToString(CultureInfo.InvariantCulture).PadLeft(4)
                              + "  " + b[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + "");
        }

        //
        //  Now try to retrieve the data from the coefficients.
        //
        float[] z = Slow.r4vec_sftb(n, azero, a, b);

        typeMethods.r4vec_print_part(n, z, 10, "  The retrieved data:");
    }