|
| 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 | +# cosqi |
| 22 | + |
| 23 | +> Initialize a workspace array for performing a quarter-wave cosine 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 cosqi = require( '@stdlib/fft/base/fftpack/cosqi' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### cosqi( N, workspace, strideW, offsetW ) |
| 44 | + |
| 45 | +Initializes a workspace array for performing a quarter-wave cosine transform. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 49 | + |
| 50 | +var N = 8; |
| 51 | +var workspace = new Float64Array( ( 3*N ) + 34 ); |
| 52 | + |
| 53 | +var out = cosqi( N, workspace, 1, 0 ); |
| 54 | +// returns <Float64Array> |
| 55 | + |
| 56 | +var bool = ( out === workspace ); |
| 57 | +// returns true |
| 58 | + |
| 59 | +var cosineTable = workspace.slice( 0, N ); |
| 60 | +// returns <Float64Array>[ ~0.98, ~0.92, ~0.83, ~0.7, ~0.56, ~0.38, ~0.2, ~0.0 ] |
| 61 | + |
| 62 | +var twiddleFactors = workspace.slice( 2*N, 3*N ); |
| 63 | +// returns <Float64Array>[ 0, ~0.707, ~0.707, 0, 0, 0, 0, 0 ] |
| 64 | + |
| 65 | +var factors = workspace.slice( 3*N, ( 3*N ) + 4 ); |
| 66 | +// returns <Float64Array>[ 8, 2, 2, 4 ] |
| 67 | +``` |
| 68 | + |
| 69 | +The function accepts the following arguments: |
| 70 | + |
| 71 | +- **N**: length of the sequence to transform. |
| 72 | +- **workspace**: workspace array. |
| 73 | +- **strideW**: stride length for `workspace`. |
| 74 | +- **offsetW**: starting index for `workspace`. |
| 75 | + |
| 76 | +</section> |
| 77 | + |
| 78 | +<!-- /.usage --> |
| 79 | + |
| 80 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 81 | + |
| 82 | +<section class="notes"> |
| 83 | + |
| 84 | +## Notes |
| 85 | + |
| 86 | +- The workspace array is divided into four sections: |
| 87 | + |
| 88 | + ```text |
| 89 | + size = N N N 2+ceil(log2(N)/2) |
| 90 | + ↓ ↓ ↓ ↓ |
| 91 | + | cosine table | scratch / workspace | twiddle factors | radix factor table | |
| 92 | + ↑ ↑ ↑ ↑ |
| 93 | + i = 0 ... N ... 2N ... 3N ... |
| 94 | + ``` |
| 95 | +
|
| 96 | + - **cosine table**: a table of precomputed cosine coefficients used by quarter-wave cosine transforms. |
| 97 | + - **scratch/workspace**: used as a scratch space when performing transforms. This section is not updated during initialization. |
| 98 | + - **twiddle factors**: a table of reusable complex-exponential constants stored as cosine/sine pairs. |
| 99 | + - **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. |
| 100 | +
|
| 101 | +- In general, a workspace array should have `3N + 34` indexed elements (as `log2(N)/2 ≤ 32` for all `2^64`). During initialization, only the sections for storing the cosine coefficients, twiddle factors, and the factorization of `N` are updated. |
| 102 | +
|
| 103 | +- The radix factor table is comprised as follows: |
| 104 | +
|
| 105 | + ```text |
| 106 | + | sequence_length | number_of_factors | integer_factors | |
| 107 | + ``` |
| 108 | +
|
| 109 | +</section> |
| 110 | +
|
| 111 | +<!-- /.notes --> |
| 112 | +
|
| 113 | +<section class="examples"> |
| 114 | +
|
| 115 | +## Examples |
| 116 | +
|
| 117 | +<!-- eslint no-undef: "error" --> |
| 118 | +
|
| 119 | +```javascript |
| 120 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 121 | +var zeroTo = require( '@stdlib/array/zero-to' ); |
| 122 | +var logEach = require( '@stdlib/console/log-each' ); |
| 123 | +var cosqi = require( '@stdlib/fft/base/fftpack/cosqi' ); |
| 124 | +
|
| 125 | +var N = 8; |
| 126 | +var workspace = new Float64Array( ( 3*N ) + 34 ); |
| 127 | +
|
| 128 | +cosqi( N, workspace, 1, 0 ); |
| 129 | +console.log( 'Sequence length: %d', N ); |
| 130 | +
|
| 131 | +console.log( 'Cosine table:' ); |
| 132 | +var idx = zeroTo( N, 'generic' ); |
| 133 | +logEach( ' workspace[ %d ] = %0.4f', idx, workspace.slice( 0, N ) ); |
| 134 | +
|
| 135 | +console.log( 'Twiddle factors:' ); |
| 136 | +idx = zeroTo( N, 'generic' ); |
| 137 | +logEach( ' workspace[ %d ] = %0.4f', idx, workspace.slice( 2*N, 3*N ) ); |
| 138 | +
|
| 139 | +console.log( 'Factorization:' ); |
| 140 | +var nf = workspace[ (3*N)+1 ]; |
| 141 | +
|
| 142 | +console.log( ' number of factors: %d', nf ); |
| 143 | +idx = zeroTo( nf, 'generic' ); |
| 144 | +logEach( ' factor[ %d ]: %d', idx, workspace.slice( (3*N)+2, (3*N)+2+nf ) ); |
| 145 | +``` |
| 146 | + |
| 147 | +</section> |
| 148 | + |
| 149 | +<!-- /.examples --> |
| 150 | + |
| 151 | +<!-- 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. --> |
| 152 | + |
| 153 | +<section class="references"> |
| 154 | + |
| 155 | +</section> |
| 156 | + |
| 157 | +<!-- /.references --> |
| 158 | + |
| 159 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 160 | + |
| 161 | +<section class="related"> |
| 162 | + |
| 163 | +</section> |
| 164 | + |
| 165 | +<!-- /.related --> |
| 166 | + |
| 167 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 168 | + |
| 169 | +<section class="links"> |
| 170 | + |
| 171 | +</section> |
| 172 | + |
| 173 | +<!-- /.links --> |
0 commit comments