|
| 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 | +/* eslint-disable max-len */ |
| 60 | + |
| 61 | +'use strict'; |
| 62 | + |
| 63 | +// MODULES // |
| 64 | + |
| 65 | +var chRef = require( '@stdlib/fft/base/fftpack/lib/ch_ref.js' ); |
| 66 | +var ccRef = require( '@stdlib/fft/base/fftpack/lib/cc_ref.js' ); |
| 67 | + |
| 68 | + |
| 69 | +// VARIABLES // |
| 70 | + |
| 71 | +var taur = -0.5; |
| 72 | +var taui = -0.866025403784439; |
| 73 | + |
| 74 | + |
| 75 | +// MAIN // |
| 76 | + |
| 77 | +/** |
| 78 | +* Performs a pass of length 3 of the FFT algorithm. |
| 79 | +* |
| 80 | +* @private |
| 81 | +* @param {integer} ido - number of real values for each transform |
| 82 | +* @param {integer} l1 - length of the input sequences |
| 83 | +* @param {Float64Array} cc - input array containing sequences to be transformed |
| 84 | +* @param {Float64Array} ch - output array containing transformed sequences |
| 85 | +* @param {Float64Array} wa1 - first array of twiddle factors |
| 86 | +* @param {Float64Array} wa2 - second array of twiddle factors |
| 87 | +* @returns {void} |
| 88 | +*/ |
| 89 | +function passf3( ido, l1, cc, ch, wa1, wa2 ) { |
| 90 | + var ch_offset; |
| 91 | + var cc_offset; |
| 92 | + var ci2; |
| 93 | + var ci3; |
| 94 | + var di2; |
| 95 | + var di3; |
| 96 | + var cr2; |
| 97 | + var cr3; |
| 98 | + var dr2; |
| 99 | + var dr3; |
| 100 | + var ti2; |
| 101 | + var tr2; |
| 102 | + var i; |
| 103 | + var k; |
| 104 | + |
| 105 | + // Parameter adjustments... |
| 106 | + ch_offset = 1 + ( ido * ( 1 + l1 ) ); |
| 107 | + cc_offset = 1 + ( ido << 2 ); |
| 108 | + |
| 109 | + // Function body: |
| 110 | + if ( ido == 2 ) { |
| 111 | + for ( k = 1; k <= l1; ++k ) { |
| 112 | + tr2 = cc[ ccRef( 1, 2, k, 3, ido ) - cc_offset ] + cc[ ccRef( 1, 3, k, 3, ido ) - cc_offset ]; |
| 113 | + cr2 = cc[ ccRef( 1, 1, k, 3, ido ) - cc_offset ] + ( taur * tr2 ); |
| 114 | + ch[ chRef( 1, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( 1, 1, k, 3, ido ) - cc_offset ] + tr2; |
| 115 | + ti2 = cc[ ccRef( 2, 2, k, 3, ido ) - cc_offset ] + cc[ ccRef( 2, 3, k, 3, ido ) - cc_offset ]; |
| 116 | + ci2 = cc[ ccRef( 2, 1, k, 3, ido ) - cc_offset ] + ( taur * ti2 ); |
| 117 | + ch[ chRef( 2, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( 2, 1, k, 3, ido ) - cc_offset ] + ti2; |
| 118 | + cr3 = taui * ( cc[ ccRef( 1, 2, k, 3, ido ) - cc_offset ] - cc[ ccRef( 1, 3, k, 3, ido ) - cc_offset ] ); |
| 119 | + ci3 = taui * ( cc[ ccRef( 2, 2, k, 3, ido ) - cc_offset ] - cc[ ccRef( 2, 3, k, 3, ido ) - cc_offset ] ); |
| 120 | + ch[ chRef( 1, k, 2, l1, ido ) - ch_offset ] = cr2 - ci3; |
| 121 | + ch[ chRef( 1, k, 3, l1, ido ) - ch_offset ] = cr2 + ci3; |
| 122 | + ch[ chRef( 2, k, 2, l1, ido ) - ch_offset ] = ci2 + cr3; |
| 123 | + ch[ chRef( 2, k, 3, l1, ido ) - ch_offset ] = ci2 - cr3; |
| 124 | + } |
| 125 | + } else { |
| 126 | + for ( k = 1; k <= l1; ++k ) { |
| 127 | + for ( i = 2; i <= ido; i += 2 ) { |
| 128 | + tr2 = cc[ ccRef( i - 1, 2, k, 3, ido ) - cc_offset ] + cc[ ccRef( i - 1, 3, k, 3, ido ) - cc_offset ]; |
| 129 | + cr2 = cc[ ccRef( i - 1, 1, k, 3, ido ) - cc_offset ] + ( taur * tr2 ); |
| 130 | + ch[ chRef( i - 1, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( i - 1, 1, k, 3, ido ) - cc_offset ] + tr2; |
| 131 | + ti2 = cc[ ccRef( i, 2, k, 3, ido ) - cc_offset ] + cc[ ccRef( i, 3, k, 3, ido ) - cc_offset ]; |
| 132 | + ci2 = cc[ ccRef( i, 1, k, 3, ido ) - cc_offset ] + ( taur * ti2 ); |
| 133 | + ch[ chRef( i, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( i, 1, k, 3, ido ) - cc_offset ] + ti2; |
| 134 | + cr3 = taui * ( cc[ ccRef( i - 1, 2, k, 3, ido ) - cc_offset ] - cc[ ccRef( i - 1, 3, k, 3, ido ) - cc_offset ] ); |
| 135 | + ci3 = taui * ( cc[ ccRef( i, 2, k, 3, ido ) - cc_offset ] - cc[ ccRef( i, 3, k, 3, ido ) - cc_offset ] ); |
| 136 | + dr2 = cr2 - ci3; |
| 137 | + dr3 = cr2 + ci3; |
| 138 | + di2 = ci2 + cr3; |
| 139 | + di3 = ci2 - cr3; |
| 140 | + ch[ chRef( i, k, 2, l1, ido) - ch_offset ] = ( wa1[ i - 1 - 1 ] * di2 ) - ( wa1[ i - 1 ] * dr2 ); |
| 141 | + ch[ chRef( i - 1, k, 2, l1, ido) - ch_offset ] = ( wa1[ i - 1 - 1 ] * dr2 ) + ( wa1[ i - 1 ] * di2 ); |
| 142 | + ch[ chRef( i, k, 3, l1, ido) - ch_offset ] = ( wa2[ i - 1 - 1 ] * di3 ) - ( wa2[ i - 1 ] * dr3 ); |
| 143 | + ch[ chRef( i - 1, k, 3, l1, ido) - ch_offset ] = ( wa2[ i - 1 - 1 ] * di3 ) + ( wa2[ i - 1 ] * dr3 ); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | + |
| 150 | +// EXPORTS // |
| 151 | + |
| 152 | +module.exports = passf3; |
0 commit comments