Skip to content

Commit 80a4f21

Browse files
committed
feat: add passf2, passf3
1 parent 3eac426 commit 80a4f21

File tree

3 files changed

+279
-8
lines changed

3 files changed

+279
-8
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
// MAIN //
70+
71+
/**
72+
* Performs a pass of length 2 of the FFT algorithm.
73+
*
74+
* @private
75+
* @param {integer} ido - number of real values for each transform
76+
* @param {integer} l1 - length of the input sequences
77+
* @param {Float64Array} cc - input array containing sequences to be transformed
78+
* @param {Float64Array} ch - output array containing transformed sequences
79+
* @param {Float64Array} wa1 - array of twiddle factors
80+
* @returns {void}
81+
*/
82+
function passf2( ido, l1, cc, ch, wa1 ) {
83+
var ch_offset;
84+
var cc_offset;
85+
var ti2;
86+
var tr2;
87+
var i;
88+
var k;
89+
90+
// Parameter adjustments...
91+
ch_offset = 1 + ( ido * ( 1 + l1 ) );
92+
cc_offset = 1 + ( ido * 3 );
93+
94+
// Function body:
95+
if ( ido == 2 ) {
96+
for ( k = 1; k <= l1; ++k ) {
97+
ch[ chRef( 1, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( 1, 1, k, 2, ido ) - cc_offset ] + cc[ ccRef( 1, 2, k, 2, ido ) - cc_offset ];
98+
ch[ chRef( 1, k, 2, l1, ido ) - ch_offset ] = cc[ ccRef( 1, 1, k, 2, ido ) - cc_offset ] - cc[ ccRef( 1, 2, k, 2, ido ) - cc_offset ];
99+
ch[ chRef( 2, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( 2, 1, k, 2, ido ) - cc_offset ] + cc[ ccRef( 2, 2, k, 2, ido ) - cc_offset ];
100+
ch[ chRef( 2, k, 2, l1, ido ) - ch_offset ] = cc[ ccRef( 2, 1, k, 2, ido ) - cc_offset ] - cc[ ccRef( 2, 2, k, 2, ido ) - cc_offset ];
101+
}
102+
} else {
103+
for ( k = 1; k <= l1; ++k ) {
104+
for ( i = 2; i <= ido; i += 2 ) {
105+
ch[ chRef( i - 1, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( i - 1, 1, k, 2, ido ) - cc_offset ] + cc[ ccRef( i - 1, 2, k, 2, ido ) - cc_offset ];
106+
tr2 = cc[ ccRef( i - 1, 1, k, 2, ido ) - cc_offset ] - cc[ ccRef( i - 1, 2, k, 2, ido ) - cc_offset ];
107+
ch[ chRef( i, k, 1, l1, ido ) - ch_offset ] = cc[ ccRef( i, 1, k, 2, ido ) - cc_offset ] + cc[ ccRef( i, 2, k, 2, ido ) - cc_offset ];
108+
ti2 = cc[ ccRef( i, 1, k, 2, ido ) - cc_offset ] - cc[ ccRef( i, 2, k, 2, ido ) - cc_offset ];
109+
ch[ chRef( i, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 1 - 1 ] * ti2 ) - ( wa1[ i - 1 ] * tr2 );
110+
ch[ chRef( i - 1, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 1 - 1 ] * tr2 ) - ( wa1[ i - 1 ] * ti2 );
111+
}
112+
}
113+
}
114+
}
115+
116+
117+
// EXPORTS //
118+
119+
module.exports = passf2;
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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;

lib/node_modules/@stdlib/fft/base/fftpack/lib/passfb5.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ function passfb5( ido, l1, cc, ch, wa1, wa2, wa3, wa4, fsign ) {
187187
dr2 = cr2 - ci5;
188188
di5 = ci2 - cr5;
189189
di2 = ci2 + cr5;
190-
ch[ chRef( i - 1, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 2 ] * dr2 ) - ( fsign * wa1[ i - 1 ] * di2 );
191-
ch[ chRef( i, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 2 ] * di2 ) + ( fsign * wa1[ i - 1 ] * dr2 );
192-
ch[ chRef( i - 1, k, 3, l1, ido ) - ch_offset ] = ( wa2[ i - 2 ] * dr3 ) - ( fsign * wa2[ i - 1 ] * di3 );
193-
ch[ chRef( i, k, 3, l1, ido ) - ch_offset ] = ( wa2[ i - 2 ] * di3 ) + ( fsign * wa2[ i - 1 ] * dr3 );
194-
ch[ chRef( i - 1, k, 4, l1, ido ) - ch_offset ] = ( wa3[ i - 2 ] * dr4 ) - ( fsign * wa3[ i - 1 ] * di4 );
195-
ch[ chRef( i, k, 4, l1, ido ) - ch_offset ] = ( wa3[ i - 2 ] * di4 ) + ( fsign * wa3[ i - 1 ] * dr4 );
196-
ch[ chRef( i - 1, k, 5, l1, ido ) - ch_offset ] = ( wa4[ i - 2 ] * dr5 ) - ( fsign * wa4[ i - 1 ] * di5 );
197-
ch[ chRef( i, k, 5, l1, ido ) - ch_offset ] = ( wa4[ i - 2 ] * di5 ) + ( fsign * wa4[ i - 1 ] * dr5 );
190+
ch[ chRef( i - 1, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 1 - 1 ] * dr2 ) - ( fsign * wa1[ i - 1 ] * di2 );
191+
ch[ chRef( i, k, 2, l1, ido ) - ch_offset ] = ( wa1[ i - 1 - 1 ] * di2 ) + ( fsign * wa1[ i - 1 ] * dr2 );
192+
ch[ chRef( i - 1, k, 3, l1, ido ) - ch_offset ] = ( wa2[ i - 1 - 1 ] * dr3 ) - ( fsign * wa2[ i - 1 ] * di3 );
193+
ch[ chRef( i, k, 3, l1, ido ) - ch_offset ] = ( wa2[ i - 1 - 1 ] * di3 ) + ( fsign * wa2[ i - 1 ] * dr3 );
194+
ch[ chRef( i - 1, k, 4, l1, ido ) - ch_offset ] = ( wa3[ i - 1 - 1 ] * dr4 ) - ( fsign * wa3[ i - 1 ] * di4 );
195+
ch[ chRef( i, k, 4, l1, ido ) - ch_offset ] = ( wa3[ i - 1 - 1 ] * di4 ) + ( fsign * wa3[ i - 1 ] * dr4 );
196+
ch[ chRef( i - 1, k, 5, l1, ido ) - ch_offset ] = ( wa4[ i - 1 - 1 ] * dr5 ) - ( fsign * wa4[ i - 1 ] * di5 );
197+
ch[ chRef( i, k, 5, l1, ido ) - ch_offset ] = ( wa4[ i - 1 - 1 ] * di5 ) + ( fsign * wa4[ i - 1 ] * dr5 );
198198
}
199199
}
200200
}

0 commit comments

Comments
 (0)