Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions lib/node_modules/@stdlib/fft/base/fftpack/float32/hc2c/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# hc2c

> Convert a real-valued single-precision floating-point array in [FFTPACK][fftpack] half-complex format to a single-precision complex floating-point array.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var hc2c = require( '@stdlib/fft/base/fftpack/float32/hc2c' );
```

#### hc2c( N, hc, strideHc, offsetHc, out, strideOut, offsetOut )

Converts a real-valued single-precision floating-point array in [FFTPACK][fftpack] half-complex format to a single-precision complex floating-point array.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var floor = require( '@stdlib/math/base/special/floor' );
var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' );
var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' );

var N = 4;
var w = new Float32Array( ( 2*N ) + 34 );

rffti( N, w, 1, 0 );

var r = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] );

rfftf( N, r, 1, 0, w, 1, 0 );
// r => <Float32Array>[ 10.0, -2.0, 2.0, -2.0 ]

var out = new Complex64Array( floor( N/2 ) + 1 );

hc2c( N, r, 1, 0, out, 1, 0 );
// out => <Complex64Array>[ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ]
```

The function accepts the following arguments:

- **N**: length of the original real sequence.
- **hc**: input array in [FFTPACK][fftpack] half-complex format.
- **strideHc**: stride length for `hc`.
- **offsetHc**: starting index for `hc`.
- **out**: output complex array.
- **strideOut**: stride length for `out`.
- **offsetOut**: starting index for `out`.

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

- [FFTPACK][fftpack]'s [`rfftf`][@stdlib/fft/base/fftpack/float32/rfftf] stores the forward DFT of a length `N` real sequence in `N` real values using the following layout:

```text
Even N: [ DC, Re(1), Im(1), Re(2), Im(2), ..., Re(N/2-1), Im(N/2-1), Nyquist ]
Odd N: [ DC, Re(1), Im(1), Re(2), Im(2), ..., Re((N-1)/2), Im((N-1)/2) ]
```

where `DC` is the zero-frequency component and `Nyquist` is the component at frequency `N/2` (even `N` only). Both are always purely real.

- The output is a complex-valued array of length `floor(N/2) + 1`. The `DC` and `Nyquist` components are stored with an explicit zero imaginary part.

- This half-complex format differs from other conventions (e.g., [FFTW][fftw-halfcomplex]). In FFTW's half-complex format, all real components are stored first, followed by imaginary components in reverse order.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var floor = require( '@stdlib/math/base/special/floor' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' );
var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' );
var hc2c = require( '@stdlib/fft/base/fftpack/float32/hc2c' );

var N = 8;
var opts = {
'dtype': 'float32'
};
var r = discreteUniform( N, -10, 10, opts );
var w = new Float32Array( ( 2*N ) + 34 );

console.log( r );

rffti( N, w, 1, 0 );
rfftf( N, r, 1, 0, w, 1, 0 );

console.log( r );

var out = new Complex64Array( floor( N/2 ) + 1 );

hc2c( N, r, 1, 0, out, 1, 0 );

console.log( out );
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[fftpack]: https://www.netlib.org/fftpack/

[fftw-halfcomplex]: https://www.fftw.org/fftw3_doc/The-Halfcomplex_002dformat-DFT.html

[@stdlib/fft/base/fftpack/float32/rfftf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/fft/base/fftpack/float32/rfftf

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Float32Array = require( '@stdlib/array/float32' );
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
var rffti = require( '@stdlib/fft/base/fftpack/float32/rffti' );
var rfftf = require( '@stdlib/fft/base/fftpack/float32/rfftf' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var hc2c = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'float32'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - sequence length
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
var out;
var w;
var r;
var M;

M = floor( N/2 ) + 1;
r = uniform( N, -100.0, 100.0, options );
w = new Float32Array( ( 2*N ) + 34 );
rffti( N, w, 1, 0 );
rfftf( N, r, 1, 0, w, 1, 0 );
out = new Complex64Array( M );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var view;
var v;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = hc2c( N, r, 1, 0, out, 1, 0 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
view = reinterpret( v, 0 );
if ( isnanf( view[ 0 ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var lengths;
var opts;
var iter;
var N;
var f;
var i;

lengths = [
8,
16,
32,
64,
128,
256,
512,
1024
];

iter = 1e6;

for ( i = 0; i < lengths.length; i++ ) {
N = lengths[ i ];
f = createBenchmark( N );
opts = {
'iterations': iter
};
bench( format( '%s:N=%d', pkg, N ), opts, f );
iter = floor( pow( iter, 3.0/4.0 ) );
}
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

{{alias}}( N, hc, strideHc, offsetHc, out, strideOut, offsetOut )
Converts a real-valued single-precision floating-point array in FFTPACK
half-complex format to a single-precision complex floating-point array.

The output complex array must have a length of at least `floor(N/2) + 1`.

Parameters
----------
N: integer
Length of the original real sequence.

hc: Float32Array
Input array in FFTPACK half-complex format.

strideHc: integer
Stride length for `hc`.

offsetHc: integer
Starting index for `hc`.

out: Complex64Array
Output complex array.

strideOut: integer
Stride length for `out`.

offsetOut: integer
Starting index for `out`.

Returns
-------
out: Complex64Array
Output complex array.

Examples
--------
> var N = 4;
> var w = new {{alias:@stdlib/array/float32}}( ( 2*N ) + 34 );
> {{alias:@stdlib/fft/base/fftpack/float32/rffti}}( N, w, 1, 0 )
<Float32Array>
> var r = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> {{alias:@stdlib/fft/base/fftpack/float32/rfftf}}( N, r, 1, 0, w, 1, 0 )
<Float32Array>[ 10.0, -2.0, 2.0, -2.0 ]
> var out = new {{alias:@stdlib/array/complex64}}( ( N/2 ) + 1 );
> {{alias}}( N, r, 1, 0, out, 1, 0 )
<Complex64Array>[ 10.0, 0.0, -2.0, 2.0, -2.0, 0.0 ]

See Also
--------
Loading
Loading