Skip to content
About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

hc2c

NPM version Build Status Coverage Status

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

Installation

npm install @stdlib/fft-base-fftpack-float32-hc2c

Alternatively,

  • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
  • If you are using Deno, visit the deno branch (see README for usage intructions).
  • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (see README).

The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.

To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.

Usage

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 half-complex format to a single-precision complex floating-point array.

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

Notes

  • FFTPACK's rfftf stores the forward DFT of a length N real sequence in N real values using the following layout:

    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). In FFTW's half-complex format, all real components are stored first, followed by imaginary components in reverse order.

Examples

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 );

Notice

This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.

For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2026. The Stdlib Authors.

About

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

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages