#include <stddef.h>
#include <math.h>
#include <limits.h>
#include <float.h>
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
|
#define | BRAHE_E 2.71828182845904523536028747135 |
| e (natural logarithm base
|
|
#define | BRAHE_LOG2_E 1.44269504088896340735992468100 |
| log_2 (e)
|
|
#define | BRAHE_LOG10_E 0.43429448190325182765112891892 |
| log_10 (e)
|
|
#define | BRAHE_SQRT_2 1.41421356237309504880168872421 |
| sqrt(2)
|
|
#define | BRAHE_SQRT_HALF 0.70710678118654752440084436210 |
| sqrt(1/2)
|
|
#define | BRAHE_SQRT_3 1.73205080756887729352744634151 |
| sqrt(3)
|
|
#define | BRAHE_PI 3.14159265358979323846264338328 |
| pi (180 deg)
|
|
#define | BRAHE_TAU 6.28318530717958647692528676656 |
| tau (2 * pi)
|
|
#define | BRAHE_PI_DIV_2 1.57079632679489661923132169164 |
| pi/2 (90 deg)
|
|
#define | BRAHE_PI_DIV_3 1.04719755119659774615421446109 |
| pi/3 (60 deg)
|
|
#define | BRAHE_PI_DIV_4 0.78539816339744830961566084582 |
| pi/4 (45 deg)
|
|
#define | BRAHE_PI_DIV_6 0.52359877559829887307710723055 |
| pi/6 (30 deg)
|
|
#define | BRAHE_PI_DIV_9 0.34906585039886591538473815370 |
| pi/9 (20 deg)
|
|
#define | BRAHE_PI_DIV_12 0.26179938779914943653855361527 |
| pi / 12 (15 deg)
|
|
#define | BRAHE_PI_DIV_18 0.17453292519943295769236907685 |
| pi / 18 (10 deg)
|
|
#define | BRAHE_PI_DIV_36 0.08726646259971647884618453842 |
| pi / 36 (5 deg)
|
|
#define | BRAHE_DEG_PER_RAD 57.2957795130823208767981548141 |
| degrees per radian
|
|
#define | BRAHE_RAD_PER_DEG 0.01745329251994329576923690768 |
| radians per degree
|
|
#define | BRAHE_SQRT_PI 1.77245385090551602729816748334 |
| sqrt(pi)
|
|
#define | BRAHE_TWO_DIV_SQRT_PI 1.12837916709551257389615890312 |
| 2/sqrt(pi)
|
|
#define | BRAHE_ONE_DIV_PI 0.31830988618379067153776752675 |
| 1/pi
|
|
#define | BRAHE_TWO_DIV_PI 0.63661977236758134307553505349 |
| 2/pi
|
|
#define | BRAHE_LN_10 2.30258509299404568401799145468 |
| ln(10)
|
|
#define | BRAHE_LN_2 0.69314718055994530941723212146 |
| ln(2)
|
|
#define | BRAHE_LOG_2 0.30102999566398119521373889472 |
| log(2)
|
|
#define | BRAHE_LN_PI 1.14472988584940017414342735135 |
| ln(pi)
|
|
#define | BRAHE_EULER 0.57721566490153286060651209008 |
| Euler constant.
|
|
|
double | brahe_round_nearest (const double x) |
| Round to nearest value.
|
|
double | brahe_sigdig (const double x, const uint16_t n) |
| Set number of significant digits in a floating-point value.
|
|
uint64_t | brahe_lcm (const uint64_t x, const uint64_t y) |
| Lowest common multiple.
|
|
uint64_t | brahe_gcf (uint64_t x, uint64_t y) |
| Greatest common factor (denominator)
|
|
double | brahe_log2base (const double x, const double base) |
| Logarithm to a specified base.
|
|
int | brahe_sizepow2 (const int n) |
| Smallest power of 2 that includes a given value.
|
|
char * | brahe_pretty_int (int64_t n, brahe_pretty_format fmt) |
| Turn a 64-bit integer into a pretty string.
|
|
brahe_statistics | brahe_get_statistics (double *data, size_t n) |
| statistics for array of double
|
|
double * | brahe_moving_average (const double *data, const int n, const int distance) |
| Moving average.
|
|
double * | brahe_simple_fft (const double *data, const int n) |
| Simple real-to-real fft (arbitrary length)
|
|
double * | brahe_simple_fft2 (const double *data, const int n) |
| Simple real-to-real fft (power of 2 length)
|
|
double * | brahe_make_sinusoid (const brahe_wave_factor_t *factors, const size_t factor_n, const size_t array_n) |
| Sine wave based artificial signal generator.
|
|
void | brahe_add_noise (double *a, const size_t n, double noise) |
| Apply noise to a signal.
|
|
double | brahe_asinh (const double x) |
| Hyperbolic arcsine.
|
|
double | brahe_acosh (const double x) |
| Hyperbolic arccosine.
|
|
double | brahe_atanh (const double x) |
| Hyperbolic arctangent.
|
|
◆ BRAHE_DEG_PER_RAD
#define BRAHE_DEG_PER_RAD 57.2957795130823208767981548141 |
◆ BRAHE_E
#define BRAHE_E 2.71828182845904523536028747135 |
◆ BRAHE_EULER
#define BRAHE_EULER 0.57721566490153286060651209008 |
◆ BRAHE_LN_10
#define BRAHE_LN_10 2.30258509299404568401799145468 |
◆ BRAHE_LN_2
#define BRAHE_LN_2 0.69314718055994530941723212146 |
◆ BRAHE_LN_PI
#define BRAHE_LN_PI 1.14472988584940017414342735135 |
◆ BRAHE_LOG10_E
#define BRAHE_LOG10_E 0.43429448190325182765112891892 |
◆ BRAHE_LOG2_E
#define BRAHE_LOG2_E 1.44269504088896340735992468100 |
◆ BRAHE_LOG_2
#define BRAHE_LOG_2 0.30102999566398119521373889472 |
◆ BRAHE_ONE_DIV_PI
#define BRAHE_ONE_DIV_PI 0.31830988618379067153776752675 |
◆ BRAHE_PI
#define BRAHE_PI 3.14159265358979323846264338328 |
◆ BRAHE_PI_DIV_12
#define BRAHE_PI_DIV_12 0.26179938779914943653855361527 |
◆ BRAHE_PI_DIV_18
#define BRAHE_PI_DIV_18 0.17453292519943295769236907685 |
◆ BRAHE_PI_DIV_2
#define BRAHE_PI_DIV_2 1.57079632679489661923132169164 |
◆ BRAHE_PI_DIV_3
#define BRAHE_PI_DIV_3 1.04719755119659774615421446109 |
◆ BRAHE_PI_DIV_36
#define BRAHE_PI_DIV_36 0.08726646259971647884618453842 |
◆ BRAHE_PI_DIV_4
#define BRAHE_PI_DIV_4 0.78539816339744830961566084582 |
◆ BRAHE_PI_DIV_6
#define BRAHE_PI_DIV_6 0.52359877559829887307710723055 |
◆ BRAHE_PI_DIV_9
#define BRAHE_PI_DIV_9 0.34906585039886591538473815370 |
◆ BRAHE_RAD_PER_DEG
#define BRAHE_RAD_PER_DEG 0.01745329251994329576923690768 |
◆ BRAHE_SQRT_2
#define BRAHE_SQRT_2 1.41421356237309504880168872421 |
◆ BRAHE_SQRT_3
#define BRAHE_SQRT_3 1.73205080756887729352744634151 |
◆ BRAHE_SQRT_HALF
#define BRAHE_SQRT_HALF 0.70710678118654752440084436210 |
◆ BRAHE_SQRT_PI
#define BRAHE_SQRT_PI 1.77245385090551602729816748334 |
◆ BRAHE_TAU
#define BRAHE_TAU 6.28318530717958647692528676656 |
◆ BRAHE_TWO_DIV_PI
#define BRAHE_TWO_DIV_PI 0.63661977236758134307553505349 |
◆ BRAHE_TWO_DIV_SQRT_PI
#define BRAHE_TWO_DIV_SQRT_PI 1.12837916709551257389615890312 |
◆ brahe_pretty_format
◆ brahe_statistics
◆ brahe_pretty_format_t
Enumerator |
---|
BRAHE_PRETTY_TEXT | english text (nine thousand, two hundred eleven)
|
BRAHE_PRETTY_COMMA | comma delimited, (1,234,567,890)
|
◆ brahe_acosh()
double brahe_acosh |
( |
const double |
x | ) |
|
Calculates cosh-1.
- Parameters
-
- Returns
- inverse hyperbolic cosine of x
◆ brahe_add_noise()
void brahe_add_noise |
( |
double * |
a, |
|
|
const size_t |
n, |
|
|
double |
noise |
|
) |
| |
Adds a percentage of noise to a signal. If "noise" is set to 0.1 (for example) each value will be adjust to between 90% and 110% of its original value. This function changes the existing values in the array.
- Parameters
-
a | array containing signal data |
n | number of samples in signal |
noise | percentage of noise |
◆ brahe_asinh()
double brahe_asinh |
( |
const double |
x | ) |
|
Calculates sinh-1.
- Parameters
-
- Returns
- inverse hyperbolic sine of x
◆ brahe_atanh()
double brahe_atanh |
( |
const double |
x | ) |
|
Calculates tanh-1.
- Parameters
-
- Returns
- inverse hyperbolic tangent of x
◆ brahe_gcf()
uint64_t brahe_gcf |
( |
uint64_t |
x, |
|
|
uint64_t |
y |
|
) |
| |
Calculates the greatest common factor for two values.
- Parameters
-
x | first value |
y | second value |
- Returns
- The greatest common factor for x and y
◆ brahe_get_statistics()
Calculate several common statistics for an array of doubles.
- Parameters
-
data | array of double values |
n | number of elements in data |
- Returns
- statistics for data
◆ brahe_lcm()
uint64_t brahe_lcm |
( |
const uint64_t |
x, |
|
|
const uint64_t |
y |
|
) |
| |
Calculates the lowest common multiple for two values.
- Parameters
-
x | first value |
y | second value |
- Returns
- The lowest common multiple for x and y
◆ brahe_log2base()
double brahe_log2base |
( |
const double |
x, |
|
|
const double |
base |
|
) |
| |
Calculates the base-n logarithm for a given value. If a range error occurs, the return value equals NaN.
- Parameters
-
x | value for which logarithm is required |
base | lagarithm base |
- Returns
- logarithm of x to base base; NAN on range error
◆ brahe_make_sinusoid()
double * brahe_make_sinusoid |
( |
const brahe_wave_factor_t * |
factors, |
|
|
const size_t |
factor_n, |
|
|
const size_t |
array_n |
|
) |
| |
Generates an array of doubles by combining sine waves. The primary purpose is to produce an artificial signal with known properties, for testing signal analysis applications. The caller is responsible for freeing the memory used by the array returned by this function.
- Parameters
-
factors | defines properties of the sine waves to be combined |
factor_n | number of elements in factors |
array_n | number of elements in the output array |
- Returns
- an allocated array containg values generated from the given factors
◆ brahe_moving_average()
double * brahe_moving_average |
( |
const double * |
data, |
|
|
const int |
n, |
|
|
const int |
distance |
|
) |
| |
Computes the moving average for an array. The returned buffer must be freed by the calling code.
- Parameters
-
data | array of double values to be averaged |
n | number of elements in data |
distance | number elements to average before and after an element in data |
- Returns
- an allocated n-length array containing the moving average of corresponding elements in data
◆ brahe_pretty_int()
Returns a nicely formatted strong for a given 64-bit integer.
- Parameters
-
n | number to be formatted |
fmt | specifies format, as text or comma-delimited |
- Returns
- an allocated string containing the generated text
◆ brahe_round_nearest()
double brahe_round_nearest |
( |
const double |
x | ) |
|
Rounds a value to nearest integer, rounding to even for exact fractions of 0.5.
◆ brahe_sigdig()
double brahe_sigdig |
( |
const double |
x, |
|
|
const uint16_t |
n |
|
) |
| |
Returns the given value rounded for the number of specified decimal digits of precision.
- Parameters
-
x | - Original value to be rounded |
n | - Number of significant digits |
- Returns
- The value x rounded to n digits of precision
◆ brahe_simple_fft()
double * brahe_simple_fft |
( |
const double * |
data, |
|
|
const int |
n |
|
) |
| |
A simple real-to-real FFT for arbitrary-length data. This is not intended to replace dedicated libraries such as FFTW. The caller is responsible for freeing the memory used by the array returned by this function. /param data input array /param n length of data /return an allocated array containing the real FFT of data
◆ brahe_simple_fft2()
double * brahe_simple_fft2 |
( |
const double * |
data, |
|
|
const int |
n |
|
) |
| |
A simple real-to-real FFT for power of 2-length data. This is not intended to replace dedicated libraries such as FFTW. The caller is responsible for freeing the memory used by the array returned by this function. /param data input array /param n length of data /return an allocated array containing the real FFT of data
◆ brahe_sizepow2()
int brahe_sizepow2 |
( |
const int |
n | ) |
|
Returns the smallest power of 2 that includes n in its range
- Parameters
-
n | number that must be less than the result |
- Returns
- the lowest power of 2 that is greater than n, or