-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For instance:
- Loading branch information
Showing
5 changed files
with
414 additions
and
1 deletion.
There are no files selected for viewing
Submodule eMeta
updated
from fb1b10 to 0c99a0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along withº | ||
* this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: pink_noise.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 31/7/2018 | ||
*/ | ||
#ifndef EASYDSP_PINK_NOISE_HPP | ||
#define EASYDSP_PINK_NOISE_HPP | ||
|
||
#include "white_noise_generator.hpp" | ||
|
||
namespace easy { namespace dsp { namespace random { | ||
|
||
template <typename T, typename Engine = std::mt19937> | ||
struct PinkNoiseGenerator { | ||
using result_type = T; | ||
inline PinkNoiseGenerator(result_type min, result_type max) : | ||
generator_(WhiteNoiseGenerator<result_type>(min, max)) { | ||
|
||
} | ||
|
||
inline result_type operator()() { | ||
result_type white = generator_(); | ||
b0 = 0.99886 * b0 + white * 0.0555179; | ||
b1 = 0.99332 * b1 + white * 0.0750759; | ||
b2 = 0.96900 * b2 + white * 0.1538520; | ||
b3 = 0.86650 * b3 + white * 0.3104856; | ||
b4 = 0.55000 * b4 + white * 0.5329522; | ||
b5 = -0.7616 * b5 - white * 0.0168980; | ||
result_type output = (b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362) * 0.11; | ||
b6 = white * 0.115926; | ||
return output; | ||
} | ||
private: | ||
result_type b0{0}; | ||
result_type b1{0}; | ||
result_type b2{0}; | ||
result_type b3{0}; | ||
result_type b4{0}; | ||
result_type b5{0}; | ||
result_type b6{0}; | ||
WhiteNoiseGenerator<T, Engine> generator_; | ||
}; | ||
|
||
}}} | ||
|
||
#endif // EASYDSP_PINK_NOISE_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along withº | ||
* this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: random_generator.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 31/7/2018 | ||
*/ | ||
#ifndef EASYDSP_FISHER_DISTRIBUTION_HPP | ||
#define EASYDSP_FISHER_DISTRIBUTION_HPP | ||
|
||
#include <random> | ||
#include <chrono> | ||
|
||
namespace easy { namespace dsp { namespace random { | ||
|
||
enum class Distribution { | ||
Uniform, | ||
Bernoulli, | ||
Binomial, | ||
Geometric, | ||
Poisson, | ||
Exponential, | ||
Gamma, | ||
Weibull, | ||
ExtremeValue, | ||
Normal, | ||
LogNormal, | ||
ChiSquared, | ||
Cauchy, | ||
Fisher, | ||
Student, | ||
Discrete, | ||
PieceWiseConstant, | ||
PieceWiseLinear | ||
}; | ||
|
||
namespace { | ||
template <typename Distribution, | ||
typename Engine = std::mt19937, | ||
typename result_type = typename Distribution::result_type> | ||
struct RandomGeneratorImpl { | ||
template <typename... Args> | ||
RandomGeneratorImpl(Args... arg) : | ||
generator_(Engine(static_cast<std::size_t>(std::chrono::system_clock::now() | ||
.time_since_epoch() | ||
.count()))), | ||
distribution_(Distribution(std::forward(arg...))) | ||
{} | ||
|
||
inline result_type operator()() { | ||
return static_cast<result_type>(distribution_(generator_)); | ||
} | ||
|
||
private: | ||
Engine generator_; | ||
Distribution distribution_; | ||
}; | ||
|
||
template <Distribution Type, typename T> | ||
struct _RandomGenerator; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Uniform, T> | ||
: public RandomGeneratorImpl<std::uniform_real_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Bernoulli, T> | ||
: public RandomGeneratorImpl<std::bernoulli_distribution, T> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Binomial, T> | ||
: public RandomGeneratorImpl<std::binomial_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Geometric, T> | ||
: public RandomGeneratorImpl<std::geometric_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Poisson, T> | ||
: public RandomGeneratorImpl<std::poisson_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Exponential, T> | ||
: public RandomGeneratorImpl<std::exponential_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Gamma, T> | ||
: public RandomGeneratorImpl<std::gamma_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Weibull, T> | ||
: public RandomGeneratorImpl<std::weibull_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::ExtremeValue, T> | ||
: public RandomGeneratorImpl<std::extreme_value_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Normal, T> | ||
: public RandomGeneratorImpl<std::normal_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::LogNormal, T> | ||
: public RandomGeneratorImpl<std::lognormal_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::ChiSquared, T> | ||
: public RandomGeneratorImpl<std::chi_squared_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Fisher, T> | ||
: public RandomGeneratorImpl<std::fisher_f_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Student, T> | ||
: public RandomGeneratorImpl<std::student_t_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::Discrete, T> | ||
: public RandomGeneratorImpl<std::discrete_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::PieceWiseConstant, T> | ||
: public RandomGeneratorImpl<std::piecewise_constant_distribution<T>> {}; | ||
|
||
template <typename T> | ||
struct _RandomGenerator<Distribution::PieceWiseLinear, T> | ||
: public RandomGeneratorImpl<std::piecewise_linear_distribution<T>> {}; | ||
|
||
} | ||
|
||
template <Distribution dist, typename T> | ||
struct RandomGenerator : public _RandomGenerator<dist, T> {}; | ||
|
||
}}} | ||
|
||
#endif // EASYDSP_FISHER_DISTRIBUTION_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* EasyDSP, A cross-platform Digital Signal Processing library written in modern C++. | ||
* Copyright (C) 2018 Mohammed Boujemaoui Boulaghmoudi | ||
* | ||
* This program is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation, either version 3 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along withº | ||
* this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
* Filename: white_noise.hpp | ||
* Author: Mohammed Boujemaoui | ||
* Date: 31/7/2018 | ||
*/ | ||
#ifndef EASYDSP_WHITE_NOISE_HPP | ||
#define EASYDSP_WHITE_NOISE_HPP | ||
|
||
#include <random> | ||
#include <chrono> | ||
|
||
namespace easy { namespace dsp { namespace random { | ||
|
||
template <typename T, typename Engine = std::mt19937> | ||
struct WhiteNoiseGenerator { | ||
using result_type = T; | ||
inline WhiteNoiseGenerator(result_type min, result_type max) : | ||
generator_(Engine(static_cast<std::size_t>(std::chrono::system_clock::now() | ||
.time_since_epoch() | ||
.count()))), | ||
distribution_(std::uniform_int_distribution<T>(min, max)) { | ||
|
||
} | ||
|
||
inline result_type operator()() { | ||
return static_cast<result_type>(distribution_(generator_)); | ||
} | ||
private: | ||
Engine generator_; | ||
std::uniform_int_distribution<T> distribution_; | ||
}; | ||
|
||
}}} | ||
|
||
|
||
|
||
#endif // EASYDSP_WHITE_NOISE_HPP |
Oops, something went wrong.