|
| 1 | +/** |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2024 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 | +'use strict'; |
| 60 | + |
| 61 | +// MODULES // |
| 62 | + |
| 63 | +var chRef = require( '@stdlib/fft/base/fftpack/lib/ch_ref.js' ); |
| 64 | +var ccRef = require( '@stdlib/fft/base/fftpack/lib/cc_ref.js' ); |
| 65 | + |
| 66 | + |
| 67 | +// MAIN // |
| 68 | + |
| 69 | +/** |
| 70 | +* Performs a pass of length 5 of the FFT algorithm with a sign factor. |
| 71 | +* |
| 72 | +* @private |
| 73 | +* @param {integer} ido - Number of real values for each transform |
| 74 | +* @param {integer} l1 - Length of the input sequences |
| 75 | +* @param {Float64Array} cc - Input array containing sequences to be transformed |
| 76 | +* @param {Float64Array} ch - Output array containing transformed sequences |
| 77 | +* @param {Float64Array} wa1 - First array of twiddle factors |
| 78 | +* @param {Float64Array} wa2 - Second array of twiddle factors |
| 79 | +* @param {Float64Array} wa3 - Third array of twiddle factors |
| 80 | +* @param {Float64Array} wa4 - Fourth array of twiddle factors |
| 81 | +* @param {number} fsign - Sign factor for the FFT computation |
| 82 | +* @returns {void} |
| 83 | +*/ |
| 84 | +function passfb5( ido, l1, cc, ch, wa1, wa2, wa3, wa4, fsign ) { |
| 85 | + var ch_offset; |
| 86 | + var cc_offset; |
| 87 | + var ci2; |
| 88 | + var ci3; |
| 89 | + var ci4; |
| 90 | + var ci5; |
| 91 | + var di2; |
| 92 | + var di3; |
| 93 | + var di4; |
| 94 | + var di5; |
| 95 | + var cr2; |
| 96 | + var cr3; |
| 97 | + var cr4; |
| 98 | + var cr5; |
| 99 | + var ti2; |
| 100 | + var ti3; |
| 101 | + var ti4; |
| 102 | + var ti5; |
| 103 | + var dr2; |
| 104 | + var dr3; |
| 105 | + var dr4; |
| 106 | + var dr5; |
| 107 | + var tr2; |
| 108 | + var tr3; |
| 109 | + var tr4; |
| 110 | + var tr5; |
| 111 | + var i; |
| 112 | + var k; |
| 113 | + |
| 114 | + // Parameter adjustments... |
| 115 | + ch_offset = 1 + ( ido * ( 1 + l1 ) ); |
| 116 | + cc_offset = 1 + ( ido * 5 ); |
| 117 | + |
| 118 | + // Function body: |
| 119 | + if ( ido === 2 ) { |
| 120 | + for ( k = 1; k <= l1; ++k ) { |
| 121 | + ti1 = cc[ ccRef( 2, 1, k, 4, ido ) - cc_offset ] - cc[ ccRef( 2, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 122 | + ti2 = cc[ ccRef( 2, 1, k, 4, ido ) - cc_offset ] + cc[ ccRef( 2, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 123 | + tr4 = cc[ ccRef( 2, 4, k, 4, ido ) - cc_offset ] - cc[ ccRef( 2, 2, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 124 | + ti3 = cc[ ccRef( 2, 2, k, 4, ido ) - cc_offset ] + cc[ ccRef( 2, 4, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 125 | + tr1 = cc[ ccRef( 1, 1, k, 4, ido ) - cc_offset ] - cc[ ccRef( 1, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 126 | + tr2 = cc[ ccRef( 1, 1, k, 4, ido ) - cc_offset ] + cc[ ccRef( 1, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 127 | + ti4 = cc[ ccRef( 1, 2, k, 4, ido ) - cc_offset ] - cc[ ccRef( 1, 4, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 128 | + tr3 = cc[ ccRef( 1, 2, k, 4, ido ) - cc_offset ] + cc[ ccRef( 1, 4, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 129 | + ch[ chRef( 1, k, 1, l1, ido ) - ch_offset ] = tr2 + tr3; |
| 130 | + ch[ chRef( 1, k, 3, l1, ido ) - ch_offset ] = tr2 - tr3; |
| 131 | + ch[ chRef( 2, k, 1, l1, ido ) - ch_offset ] = ti2 + ti3; |
| 132 | + ch[ chRef( 2, k, 3, l1, ido ) - ch_offset ] = ti2 - ti3; |
| 133 | + ch[ chRef( 1, k, 2, l1, ido ) - ch_offset ] = tr1 + tr4; |
| 134 | + ch[ chRef( 1, k, 4, l1, ido ) - ch_offset ] = tr1 - tr4; |
| 135 | + ch[ chRef( 2, k, 2, l1, ido ) - ch_offset ] = ti1 + ti4; |
| 136 | + ch[ chRef( 2, k, 4, l1, ido ) - ch_offset ] = ti1 - ti4; |
| 137 | + } |
| 138 | + } else { |
| 139 | + for ( k = 1; k <= l1; ++k ) { |
| 140 | + for ( i = 2; i <= ido; i += 2 ) { |
| 141 | + ti1 = cc[ ccRef( i, 1, k, 4, ido ) - cc_offset ] - cc[ ccRef( i, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 142 | + ti2 = cc[ ccRef( i, 1, k, 4, ido ) - cc_offset ] + cc[ ccRef( i, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 143 | + ti3 = cc[ ccRef( i, 2, k, 4, ido ) - cc_offset ] + cc[ ccRef( i, 4, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 144 | + tr4 = cc[ ccRef( i, 4, k, 4, ido ) - cc_offset ] - cc[ ccRef( i, 2, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 145 | + tr1 = cc[ ccRef( i - 1, 1, k, 4, ido ) - cc_offset ] - cc[ ccRef( i - 1, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 146 | + tr2 = cc[ ccRef( i - 1, 1, k, 4, ido ) - cc_offset ] + cc[ ccRef( i - 1, 3, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 147 | + ti4 = cc[ ccRef( i - 1, 2, k, 4, ido ) - cc_offset ] - cc[ ccRef( i - 1, 4, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 148 | + tr3 = cc[ ccRef( i - 1, 2, k, 4, ido ) - cc_offset ] + cc[ ccRef( i - 1, 4, k, 4, ido ) - cc_offset ]; // eslint-disable-line max-len |
| 149 | + ch[ chRef( i - 1, k, 1, l1, ido ) - ch_offset ] = tr2 + tr3; |
| 150 | + cr3 = tr2 - tr3; |
| 151 | + ch[ chRef( i, k, 1, l1, ido ) - ch_offset ] = ti2 + ti3; |
| 152 | + ci3 = ti2 - ti3; |
| 153 | + cr2 = tr1 + tr4; |
| 154 | + cr4 = tr1 - tr4; |
| 155 | + ci2 = ti1 + ti4; |
| 156 | + ci4 = ti1 - ti4; |
| 157 | + ch[ chRef( i - 1, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 1 - 1 ] * cr2 ) - ( wa1[ i - 1 ] * ci2 ); |
| 158 | + ch[ chRef( i, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 1 - 1 ] * ci2 ) + ( wa1[ i - 1 ] * cr2 ); |
| 159 | + ch[ chRef( i - 1, k, 3, l1, ido ) - ch_offset ] = ( wa2[ i - 1 - 1 ] * cr3 ) - ( wa2[ i - 1 ] * ci3 ); |
| 160 | + ch[ chRef( i, k, 3, l1, ido ) - ch_offset ] = ( wa2[ i - 1 - 1 ] * ci3 ) + ( wa2[ i - 1 ] * cr3 ); |
| 161 | + ch[ chRef( i - 1, k, 4, l1, ido ) - ch_offset ] = ( wa3[ i - 1 - 1 ] * cr4 ) - ( wa3[ i - 1 ] * ci4 ); |
| 162 | + ch[ chRef( i, k, 4, l1, ido ) - ch_offset ] = ( wa3[ i - 1 - 1 ] * ci4 ) + ( wa3[ i - 1 ] * cr4 ); |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | +} |
| 167 | + |
| 168 | + |
| 169 | +// EXPORTS // |
| 170 | + |
| 171 | +module.exports = passfb5; |
0 commit comments