|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# rffti |
| 22 | + |
| 23 | +> Initialize a workspace array for performing a real-valued Fourier transform. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var rffti = require( '@stdlib/fft/base/fftpack/rffti' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### rffti( N, workspace, strideW, offsetW ) |
| 44 | + |
| 45 | +Initializes a workspace array for performing a real-valued Fourier transform. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 49 | + |
| 50 | +var N = 8; |
| 51 | +var workspace = new Float64Array( ( 2*N ) + 34 ); |
| 52 | + |
| 53 | +rffti( N, workspace, 1, 0 ); |
| 54 | + |
| 55 | +var twiddleFactors = workspace.slice( N, 2*N ); |
| 56 | +// returns <Float64Array>[ 0, ~0.707, ~0.707, 0, 0, 0, 0, 0 ] |
| 57 | + |
| 58 | +var factors = workspace.slice( 2*N, ( 2*N ) + 4 ); |
| 59 | +// returns <Float64Array>[ 8, 2, 2, 4 ] |
| 60 | +``` |
| 61 | + |
| 62 | +The function accepts the following arguments: |
| 63 | + |
| 64 | +- **N**: length of the sequence to transform. |
| 65 | +- **workspace**: workspace array. |
| 66 | +- **strideW**: stride length for `workspace`. |
| 67 | +- **offsetW**: starting index for `workspace`. |
| 68 | + |
| 69 | +</section> |
| 70 | + |
| 71 | +<!-- /.usage --> |
| 72 | + |
| 73 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 74 | + |
| 75 | +<section class="notes"> |
| 76 | + |
| 77 | +## Notes |
| 78 | + |
| 79 | +- The workspace array is divided into three sections: |
| 80 | + |
| 81 | + ```text |
| 82 | + size = N N 2+ceil(log2(N)/2) |
| 83 | + ↓ ↓ ↓ |
| 84 | + | scratch / workspace | twiddle factors | radix factor table | |
| 85 | + ↑ ↑ ↑ |
| 86 | + i = 0 ... N ... 2N ... |
| 87 | + ``` |
| 88 | +
|
| 89 | + - **scratch/workspace**: used as a scratch space when performing transforms. This section is not updated during initialization. |
| 90 | + - **twiddle factors**: a table of reusable complex-exponential constants stored as cosine/sine pairs. |
| 91 | + - **radix factor table**: a table containing the sequence length `N`, the number of factors into which `N` was decomposed, and the individual integer radix factors. |
| 92 | +
|
| 93 | +- In general, a workspace array should have `2N + 34` indexed elements (as `log2(N)/2 ≤ 32` for all `2^64`). During initialization, only the sections for storing twiddle factors and the factorization of `N` are updated. |
| 94 | +
|
| 95 | +- The radix factor table is comprised as follows: |
| 96 | +
|
| 97 | + ```text |
| 98 | + | sequence_length | number_of_factors | integer_factors | |
| 99 | + ``` |
| 100 | +
|
| 101 | +- If `N` equals `1`, the function returns early without modifying the workspace, as a single data point is its own Fourier transform. |
| 102 | +
|
| 103 | +</section> |
| 104 | +
|
| 105 | +<!-- /.notes --> |
| 106 | +
|
| 107 | +<section class="examples"> |
| 108 | +
|
| 109 | +## Examples |
| 110 | +
|
| 111 | +<!-- eslint no-undef: "error" --> |
| 112 | +
|
| 113 | +```javascript |
| 114 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 115 | +var rffti = require( '@stdlib/fft/base/fftpack/rffti' ); |
| 116 | +
|
| 117 | +var workspace; |
| 118 | +var N; |
| 119 | +var nf; |
| 120 | +var i; |
| 121 | +var j; |
| 122 | +
|
| 123 | +N = 8; |
| 124 | +workspace = new Float64Array( ( 2*N ) + 34 ); |
| 125 | +
|
| 126 | +rffti( N, workspace, 1, 0 ); |
| 127 | +
|
| 128 | +console.log( 'Sequence length: %d', N ); |
| 129 | +console.log( 'Twiddle factors:' ); |
| 130 | +for ( i = N; i < 2*N; i++ ) { |
| 131 | + console.log( ' workspace[%d] = %d', i, workspace[ i ] ); |
| 132 | +} |
| 133 | +
|
| 134 | +console.log( 'Factorization:' ); |
| 135 | +nf = workspace[ ( 2*N ) + 1 ]; |
| 136 | +console.log( ' number of factors: %d', nf ); |
| 137 | +for ( j = 0; j < nf; j++ ) { |
| 138 | + console.log( ' factor[%d]: %d', j, workspace[ ( 2*N ) + 2 + j ] ); |
| 139 | +} |
| 140 | +``` |
| 141 | + |
| 142 | +</section> |
| 143 | + |
| 144 | +<!-- /.examples --> |
| 145 | + |
| 146 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 147 | + |
| 148 | +<section class="references"> |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.references --> |
| 153 | + |
| 154 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 155 | + |
| 156 | +<section class="related"> |
| 157 | + |
| 158 | +</section> |
| 159 | + |
| 160 | +<!-- /.related --> |
| 161 | + |
| 162 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 163 | + |
| 164 | +<section class="links"> |
| 165 | + |
| 166 | +</section> |
| 167 | + |
| 168 | +<!-- /.links --> |
0 commit comments