function transformBluestein(real, imag) {
    // Find a power-of-2 convolution length m such that m >= n * 2 + 1
    if (real.length !== imag.length)
        throw "Mismatched lengths";
    var i, j;
    var n = real.length;
    var m = 1;
    while (m < n * 2 + 1)
        m *= 2;

    // Trignometric tables
    var cosTable = new Array(n);
    var sinTable = new Array(n);
    for (i = 0; i < n; i++) {
        j = i * i % (n * 2); // This is more accurate than j = i * i
        cosTable[i] = Math.cos(Math.PI * j / n);
        sinTable[i] = Math.sin(Math.PI * j / n);
    }

    // Temporary vectors and preprocessing
    var areal = new Array(m);
    var aimag = new Array(m);
    for (i = 0; i < n; i++) {
        areal[i] = real[i] * cosTable[i] + imag[i] * sinTable[i];
        aimag[i] = -real[i] * sinTable[i] + imag[i] * cosTable[i];
    }
    for (i = n; i < m; i++)
        areal[i] = aimag[i] = 0;
    var breal = new Array(m);
    var bimag = new Array(m);
    breal[0] = cosTable[0];
    bimag[0] = sinTable[0];
    for (i = 1; i < n; i++) {
        breal[i] = breal[m - i] = cosTable[i];
        bimag[i] = bimag[m - i] = sinTable[i];
    }
    for (i = n; i <= m - n; i++)
        breal[i] = bimag[i] = 0;

    // Convolution
    var creal = new Array(m);
    var cimag = new Array(m);
    convolveComplex(areal, aimag, breal, bimag, creal, cimag);

    // Postprocessing
    for (i = 0; i < n; i++) {
        real[i] = creal[i] * cosTable[i] + cimag[i] * sinTable[i];
        imag[i] = -creal[i] * sinTable[i] + cimag[i] * cosTable[i];
    }
}
/* 
 * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
 * The vector can have any length. This requires the convolution function, which in turn requires the radix-2 FFT function.
 * Uses Bluestein's chirp z-transform algorithm.
 */
Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
The vector can have any length. This requires the convolution function, which in turn requires the radix-2 FFT function.
Uses Bluestein's chirp z-transform algorithm.
Computes the discrete Fourier transform ( DFT ) of the given complex vector storing the result back into the vector . The vector can have any length . This requires the convolution function which in turn requires the radix - 2 FFT function . Uses Bluestein ' s chirp z - transform algorithm .
function transformBluestein(real, imag) {
    if (real.length !== imag.length)
        throw "Mismatched lengths";
    var i, j;
    var n = real.length;
    var m = 1;
    while (m < n * 2 + 1)
        m *= 2;
    var cosTable = new Array(n);
    var sinTable = new Array(n);
    for (i = 0; i < n; i++) {
        j = i * i % (n * 2); 
        cosTable[i] = Math.cos(Math.PI * j / n);
        sinTable[i] = Math.sin(Math.PI * j / n);
    }
    var areal = new Array(m);
    var aimag = new Array(m);
    for (i = 0; i < n; i++) {
        areal[i] = real[i] * cosTable[i] + imag[i] * sinTable[i];
        aimag[i] = -real[i] * sinTable[i] + imag[i] * cosTable[i];
    }
    for (i = n; i < m; i++)
        areal[i] = aimag[i] = 0;
    var breal = new Array(m);
    var bimag = new Array(m);
    breal[0] = cosTable[0];
    bimag[0] = sinTable[0];
    for (i = 1; i < n; i++) {
        breal[i] = breal[m - i] = cosTable[i];
        bimag[i] = bimag[m - i] = sinTable[i];
    }
    for (i = n; i <= m - n; i++)
        breal[i] = bimag[i] = 0;
    var creal = new Array(m);
    var cimag = new Array(m);
    convolveComplex(areal, aimag, breal, bimag, creal, cimag);
    for (i = 0; i < n; i++) {
        real[i] = creal[i] * cosTable[i] + cimag[i] * sinTable[i];
        imag[i] = -creal[i] * sinTable[i] + cimag[i] * cosTable[i];
    }
}
function transformBluestein ( real , imag ) { if ( real . length !== imag . length ) throw "Mismatched lengths" ; var i , j ; var n = real . length ; var m = 1 ; while ( m < n * 2 + 1 ) m *= 2 ; var cosTable = new Array ( n ) ; var sinTable = new Array ( n ) ; for ( i = 0 ; i < n ; i ++ ) { j = i * i % ( n * 2 ) ; cosTable [ i ] = Math . cos ( Math . PI * j / n ) ; sinTable [ i ] = Math . sin ( Math . PI * j / n ) ; } var areal = new Array ( m ) ; var aimag = new Array ( m ) ; for ( i = 0 ; i < n ; i ++ ) { areal [ i ] = real [ i ] * cosTable [ i ] + imag [ i ] * sinTable [ i ] ; aimag [ i ] = - real [ i ] * sinTable [ i ] + imag [ i ] * cosTable [ i ] ; } for ( i = n ; i < m ; i ++ ) areal [ i ] = aimag [ i ] = 0 ; var breal = new Array ( m ) ; var bimag = new Array ( m ) ; breal [ 0 ] = cosTable [ 0 ] ; bimag [ 0 ] = sinTable [ 0 ] ; for ( i = 1 ; i < n ; i ++ ) { breal [ i ] = breal [ m - i ] = cosTable [ i ] ; bimag [ i ] = bimag [ m - i ] = sinTable [ i ] ; } for ( i = n ; i <= m - n ; i ++ ) breal [ i ] = bimag [ i ] = 0 ; var creal = new Array ( m ) ; var cimag = new Array ( m ) ; convolveComplex ( areal , aimag , breal , bimag , creal , cimag ) ; for ( i = 0 ; i < n ; i ++ ) { real [ i ] = creal [ i ] * cosTable [ i ] + cimag [ i ] * sinTable [ i ] ; imag [ i ] = - creal [ i ] * sinTable [ i ] + cimag [ i ] * cosTable [ i ] ; } }
Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
Computes the discrete Fourier transform ( DFT ) of the given complex vector storing the result back into the vector .
// Find a power-of-2 convolution length m such that m >= n * 2 + 1 // Trignometric tables // This is more accurate than j = i * i // Temporary vectors and preprocessing // Convolution // Postprocessing