mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added probability density function of the normal distribution
This commit is contained in:
parent
ef6871f94b
commit
749668d830
3 changed files with 14 additions and 1 deletions
|
|
@ -52,7 +52,10 @@ Mixed-radix [decimation-in-time](https://en.wikipedia.org/wiki/Cooley%E2%80%93Tu
|
|||
|
||||
### [utils.hh](utils.hh)
|
||||
|
||||
Some everyday helpers, like the [signum function](https://en.wikipedia.org/wiki/Sign_function) or the [lerp function](https://en.wikipedia.org/wiki/Linear_interpolation).
|
||||
Some everyday helpers:
|
||||
* [signum function](https://en.wikipedia.org/wiki/Sign_function)
|
||||
* [lerp function](https://en.wikipedia.org/wiki/Linear_interpolation)
|
||||
* [probability density function](https://en.wikipedia.org/wiki/Probability_density_function) of the [normal distribution](https://en.wikipedia.org/wiki/Normal_distribution)
|
||||
|
||||
### [resampler.hh](resampler.hh)
|
||||
|
||||
|
|
|
|||
2
const.hh
2
const.hh
|
|
@ -17,6 +17,8 @@ struct Const {
|
|||
static constexpr T Pi() { return 3.14159265358979323846; } // 4*a(1)
|
||||
static constexpr T TwoPi() { return 6.28318530717958647693; } // 8*a(1)
|
||||
static constexpr T FourPi() { return 12.56637061435917295385; } // 16*a(1)
|
||||
static constexpr T SqrtPi() { return 1.77245385090551602730; } // sqrt(4*a(1))
|
||||
static constexpr T SqrtTwoPi() { return 2.50662827463100050242; } // sqrt(8*a(1))
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
8
utils.hh
8
utils.hh
|
|
@ -7,6 +7,8 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
#ifndef UTILS_HH
|
||||
#define UTILS_HH
|
||||
|
||||
#include "const.hh"
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE>
|
||||
|
|
@ -21,6 +23,12 @@ AB lerp(X x, AB a, AB b)
|
|||
return (X(1) - x) * a + x * b;
|
||||
}
|
||||
|
||||
template <typename TYPE>
|
||||
TYPE normal_pdf(TYPE x, TYPE m, TYPE s)
|
||||
{
|
||||
return std::exp(-std::pow((x - m) / s, TYPE(2)) / TYPE(2)) / (Const<TYPE>::SqrtTwoPi() * s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue