|  | 
|  | 1 | +/** | 
|  | 2 | +* @license Apache-2.0 | 
|  | 3 | +* | 
|  | 4 | +* Copyright (c) 2025 The Stdlib Authors. | 
|  | 5 | +* | 
|  | 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 7 | +* you may not use this file except in compliance with the License. | 
|  | 8 | +* You may obtain a copy of the License at | 
|  | 9 | +* | 
|  | 10 | +*    http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 11 | +* | 
|  | 12 | +* Unless required by applicable law or agreed to in writing, software | 
|  | 13 | +* distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 15 | +* See the License for the specific language governing permissions and | 
|  | 16 | +* limitations under the License. | 
|  | 17 | +* | 
|  | 18 | +* | 
|  | 19 | +* ## Notice | 
|  | 20 | +* | 
|  | 21 | +* The original C code and copyright notice are from the [PFFFT library]{@link https://github.com/marton78/pffft/blob/master/fftpack.c}. The implementation follows the original, but has been modified for JavaScript. | 
|  | 22 | +* | 
|  | 23 | +* ```text | 
|  | 24 | +* Copyright (c) 2004 the University Corporation for Atmospheric | 
|  | 25 | +* Research ("UCAR"). All rights reserved. Developed by NCAR's | 
|  | 26 | +* Computational and Information Systems Laboratory, UCAR, | 
|  | 27 | +* www.cisl.ucar.edu. | 
|  | 28 | +* | 
|  | 29 | +* Redistribution and use of the Software in source and binary forms, | 
|  | 30 | +* with or without modification, is permitted provided that the | 
|  | 31 | +* following conditions are met: | 
|  | 32 | +* | 
|  | 33 | +*     - Neither the names of NCAR's Computational and Information Systems | 
|  | 34 | +*       Laboratory, the University Corporation for Atmospheric Research, | 
|  | 35 | +*       nor the names of its sponsors or contributors may be used to | 
|  | 36 | +*       endorse or promote products derived from this Software without | 
|  | 37 | +*       specific prior written permission. | 
|  | 38 | +* | 
|  | 39 | +*     - Redistributions of source code must retain the above copyright | 
|  | 40 | +*       notices, this list of conditions, and the disclaimer below. | 
|  | 41 | +* | 
|  | 42 | +*     - Redistributions in binary form must reproduce the above copyright | 
|  | 43 | +*       notice, this list of conditions, and the disclaimer below in the | 
|  | 44 | +*       documentation and/or other materials provided with the | 
|  | 45 | +*       distribution. | 
|  | 46 | +* | 
|  | 47 | +* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 
|  | 48 | +* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF | 
|  | 49 | +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 
|  | 50 | +* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT | 
|  | 51 | +* HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL, | 
|  | 52 | +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN | 
|  | 53 | +* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | 
|  | 54 | +* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE | 
|  | 55 | +* SOFTWARE. | 
|  | 56 | +* ``` | 
|  | 57 | +*/ | 
|  | 58 | + | 
|  | 59 | +/* eslint-disable max-len */ | 
|  | 60 | + | 
|  | 61 | +'use strict'; | 
|  | 62 | + | 
|  | 63 | +// MODULES // | 
|  | 64 | + | 
|  | 65 | +var passfb5 = require( './passfb5.js' ); | 
|  | 66 | +var passfb = require( './passfb.js' ); | 
|  | 67 | +var passf4 = require( './passf4.js' ); | 
|  | 68 | +var passf2 = require( './passf2.js' ); | 
|  | 69 | +var passf3 = require( './passf3.js' ); | 
|  | 70 | + | 
|  | 71 | + | 
|  | 72 | +// MAIN // | 
|  | 73 | + | 
|  | 74 | +/** | 
|  | 75 | +* Performs the complex forward Fast Fourier Transform. | 
|  | 76 | +* | 
|  | 77 | +* @private | 
|  | 78 | +* @param {number} n - length of the sequence to transform | 
|  | 79 | +* @param {Float64Array} c - input array containing sequence to be transformed | 
|  | 80 | +* @param {Float64Array} ch - working array for intermediate results | 
|  | 81 | +* @param {Float64Array} wa - array of twiddle factors | 
|  | 82 | +* @param {Int32Array} ifac - array containing factorization information | 
|  | 83 | +* @returns {void} | 
|  | 84 | +*/ | 
|  | 85 | +function cfftf1( n, c, ch, wa, ifac ) { | 
|  | 86 | +	var idl1; | 
|  | 87 | +	var idot; | 
|  | 88 | +	var nac; | 
|  | 89 | +	var ido; | 
|  | 90 | +	var ix4; | 
|  | 91 | +	var ix3; | 
|  | 92 | +	var ix2; | 
|  | 93 | +	var nf; | 
|  | 94 | +	var na; | 
|  | 95 | +	var l2; | 
|  | 96 | +	var l1; | 
|  | 97 | +	var iw; | 
|  | 98 | +	var ip; | 
|  | 99 | +	var k1; | 
|  | 100 | +	var i; | 
|  | 101 | + | 
|  | 102 | +	// Function Body: | 
|  | 103 | +	nf = ifac[ 1 ]; | 
|  | 104 | +	na = 0; | 
|  | 105 | +	l1 = 1; | 
|  | 106 | +	iw = 0; | 
|  | 107 | +	for ( k1 = 1; k1 <= nf; k1++ ) { | 
|  | 108 | +		ip = ifac[ k1 + 1 ]; | 
|  | 109 | +		l2 = ip * l1; | 
|  | 110 | +		ido = n / l2; | 
|  | 111 | +		idot = ido + ido; | 
|  | 112 | +		idl1 = idot * l1; | 
|  | 113 | +		switch ( ip ) { | 
|  | 114 | +		case 4: | 
|  | 115 | +			ix2 = iw + idot; | 
|  | 116 | +			ix3 = ix2 + idot; | 
|  | 117 | +			passf4( idot, l1, ( na ) ? ch : c, ( na ) ? c : ch, wa[ iw ], wa[ ix2 ], wa[ ix3 ] ); | 
|  | 118 | +			na = 1 - na; | 
|  | 119 | +			break; | 
|  | 120 | +		case 2: | 
|  | 121 | +			passf2( idot, l1, ( na ) ? ch : c, ( na ) ? c : ch, wa[ iw ] ); | 
|  | 122 | +			na = 1 - na; | 
|  | 123 | +			break; | 
|  | 124 | +		case 3: | 
|  | 125 | +			ix2 = iw + idot; | 
|  | 126 | +			passf3( idot, l1, ( na ) ? ch : c, ( na ) ? c : ch, wa[ iw ], wa[ ix2 ] ); | 
|  | 127 | +			na = 1 - na; | 
|  | 128 | +			break; | 
|  | 129 | +		case 5: | 
|  | 130 | +			ix2 = iw + idot; | 
|  | 131 | +			ix3 = ix2 + idot; | 
|  | 132 | +			ix4 = ix3 + idot; | 
|  | 133 | +			passfb5( idot, l1, ( na ) ? ch : c, ( na ) ? c : ch, wa[ iw ], wa[ ix2 ], wa[ ix3 ], wa[ ix4 ], -1 ); | 
|  | 134 | +			na = 1 - na; | 
|  | 135 | +			break; | 
|  | 136 | +		default: | 
|  | 137 | +			if ( na === 0 ) { | 
|  | 138 | +				passfb( nac, idot, ip, l1, idl1, c, c, c, ch, ch, wa[ iw ], -1 ); | 
|  | 139 | +			} else { | 
|  | 140 | +				passfb( nac, idot, ip, l1, idl1, ch, ch, ch, c, c, wa[ iw ], -1 ); | 
|  | 141 | +			} | 
|  | 142 | +			if ( nac !== 0 ) { | 
|  | 143 | +				na = 1 - na; | 
|  | 144 | +			} | 
|  | 145 | +			break; | 
|  | 146 | +		} | 
|  | 147 | +		l1 = l2; | 
|  | 148 | +		iw += ( ip - 1 ) * idot; | 
|  | 149 | +	} | 
|  | 150 | +	if ( na === 0 ) { | 
|  | 151 | +		return; | 
|  | 152 | +	} | 
|  | 153 | +	for ( i = 0; i < ( 2 * n ); i++ ) { | 
|  | 154 | +		c[ i ] = ch[ i ]; | 
|  | 155 | +	} | 
|  | 156 | +} | 
|  | 157 | + | 
|  | 158 | + | 
|  | 159 | +// EXPORTS // | 
|  | 160 | + | 
|  | 161 | +module.exports = cfftf1; | 
0 commit comments