cadencii.fft.makewt C# (CSharp) Method

makewt() static private method

static private makewt ( int nw, int ip, double w ) : void
nw int
ip int
w double
return void
        static void makewt( int nw, int* ip, double* w ) {
            //void makeipt(int nw, int *ip);
            int j, nwh, nw0, nw1;
            double delta, wn4r, wk1r, wk1i, wk3r, wk3i;

            ip[0] = nw;
            ip[1] = 1;
            if ( nw > 2 ) {
                nwh = nw >> 1;
                delta = atan( 1.0 ) / nwh;
                wn4r = cos( delta * nwh );
                w[0] = 1;
                w[1] = wn4r;
                if ( nwh == 4 ) {
                    w[2] = cos( delta * 2 );
                    w[3] = sin( delta * 2 );
                } else if ( nwh > 4 ) {
                    makeipt( nw, ip );
                    w[2] = 0.5 / cos( delta * 2 );
                    w[3] = 0.5 / cos( delta * 6 );
                    for ( j = 4; j < nwh; j += 4 ) {
                        w[j] = cos( delta * j );
                        w[j + 1] = sin( delta * j );
                        w[j + 2] = cos( 3 * delta * j );
                        w[j + 3] = -sin( 3 * delta * j );
                    }
                }
                nw0 = 0;
                while ( nwh > 2 ) {
                    nw1 = nw0 + nwh;
                    nwh >>= 1;
                    w[nw1] = 1;
                    w[nw1 + 1] = wn4r;
                    if ( nwh == 4 ) {
                        wk1r = w[nw0 + 4];
                        wk1i = w[nw0 + 5];
                        w[nw1 + 2] = wk1r;
                        w[nw1 + 3] = wk1i;
                    } else if ( nwh > 4 ) {
                        wk1r = w[nw0 + 4];
                        wk3r = w[nw0 + 6];
                        w[nw1 + 2] = 0.5 / wk1r;
                        w[nw1 + 3] = 0.5 / wk3r;
                        for ( j = 4; j < nwh; j += 4 ) {
                            wk1r = w[nw0 + 2 * j];
                            wk1i = w[nw0 + 2 * j + 1];
                            wk3r = w[nw0 + 2 * j + 2];
                            wk3i = w[nw0 + 2 * j + 3];
                            w[nw1 + j] = wk1r;
                            w[nw1 + j + 1] = wk1i;
                            w[nw1 + j + 2] = wk3r;
                            w[nw1 + j + 3] = wk3i;
                        }
                    }
                    nw0 = nw1;
                }
            }
        }