last-svn-commit-17-g706148b Add white gaussian noise function.

* mln/fun/all.hh: Include a new file. * mln/fun/n2v/all.hh, * mln/fun/n2v/white_gaussian.hh: New. --- milena/ChangeLog | 9 +++ milena/mln/fun/all.hh | 2 + milena/mln/fun/{stat => n2v}/all.hh | 17 ++--- .../fun/{v2w2v/cos.hh => n2v/white_gaussian.hh} | 75 +++++++++++-------- 4 files changed, 62 insertions(+), 41 deletions(-) copy milena/mln/fun/{stat => n2v}/all.hh (79%) copy milena/mln/fun/{v2w2v/cos.hh => n2v/white_gaussian.hh} (61%) diff --git a/milena/ChangeLog b/milena/ChangeLog index 9a870bf..fae42e1 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,12 @@ +2010-02-24 Guillaume Lazzara <z@lrde.epita.fr> + + Add white gaussian noise function. + + * mln/fun/all.hh: Include a new file. + + * mln/fun/n2v/all.hh, + * mln/fun/n2v/white_gaussian.hh: New. + 2010-02-16 Guillaume Lazzara <z@lrde.epita.fr> Cleanup to_qimage convertion routines. diff --git a/milena/mln/fun/all.hh b/milena/mln/fun/all.hh index b353f38..b4f3ebb 100644 --- a/milena/mln/fun/all.hh +++ b/milena/mln/fun/all.hh @@ -57,6 +57,8 @@ namespace mln // Sub-directories. +# include <mln/fun/n2v/all.hh> + # include <mln/fun/i2v/all.hh> //<<lrde # include <mln/fun/meta/all.hh> diff --git a/milena/mln/fun/stat/all.hh b/milena/mln/fun/n2v/all.hh similarity index 79% copy from milena/mln/fun/stat/all.hh copy to milena/mln/fun/n2v/all.hh index d207047..0e0e55c 100644 --- a/milena/mln/fun/stat/all.hh +++ b/milena/mln/fun/n2v/all.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,12 +23,12 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_STAT_ALL_HH -# define MLN_FUN_STAT_ALL_HH +#ifndef MLN_FUN_N2V_ALL_HH +# define MLN_FUN_N2V_ALL_HH /// \file /// -/// File that includes all statistical functions. +/// File that includes all functions from nil to value. namespace mln @@ -37,16 +37,15 @@ namespace mln namespace fun { - /// \brief Namespace of statistical functions. + /// \brief Namespace of functions from nil to value. /// /// \ingroup modfun - namespace stat {} + namespace n2v {} } } -# include <mln/fun/stat/mahalanobis.hh> +# include <mln/fun/n2v/white_gaussian.hh> - -#endif // ! MLN_FUN_STAT_ALL_HH +#endif // ! MLN_FUN_N2V_ALL_HH diff --git a/milena/mln/fun/v2w2v/cos.hh b/milena/mln/fun/n2v/white_gaussian.hh similarity index 61% copy from milena/mln/fun/v2w2v/cos.hh copy to milena/mln/fun/n2v/white_gaussian.hh index 7616e05..53afbf6 100644 --- a/milena/mln/fun/v2w2v/cos.hh +++ b/milena/mln/fun/n2v/white_gaussian.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,21 +23,18 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_FUN_V2W2V_COS_HH -# define MLN_FUN_V2W2V_COS_HH +#ifndef MLN_FUN_N2V_WHITE_GAUSSIAN_HH +# define MLN_FUN_N2V_WHITE_GAUSSIAN_HH -/*! \file - * - * \brief Cos functor. - * - * \see mln/math/. - */ +/// \file +/// +/// White Gaussian noise. + +# include <cstdlib> +# include <ctime> # include <mln/core/concept/function.hh> -# include <mln/trait/value_.hh> -# include <mln/math/cos.hh> -# include <mln/math/acos.hh> namespace mln @@ -46,48 +43,62 @@ namespace mln namespace fun { - namespace v2w2v + namespace n2v { - /*! \brief Cosinus bijective functor. - * - * \c V is the type of input values and the result type. - * - * \see mln::math::cos. + /*! \brief Generate a White Gaussian Noise. + + + Reference: + http://www.dspguru.com/dsp/howtos/how-to-generate-white-gaussian-noise */ template <typename V> - struct cos : public Function_v2v< cos<V> > + struct white_gaussian : Function_n2v< white_gaussian<V> > { typedef V result; - V operator()(const V& v) const; - V f_1 (const V& v) const; + + white_gaussian(double sigma_); + V operator()() const; + + double sigma; }; + # ifndef MLN_INCLUDE_ONLY + template <typename V> - inline - V - cos<V>::operator()(const V& v) const + white_gaussian<V>::white_gaussian(double sigma_) + : sigma(sigma_) { - return mln::math::cos (v); + srand(time(0)); } + template <typename V> - inline - V - cos<V>::f_1(const V& v) const + V white_gaussian<V>::operator()() const { - return mln::math::acos (v); - } + double X = 0; + for (int i = 1; i < 50; ++i) + { + double U = rand() / (float)RAND_MAX; + X = X + U; + } + + X = X - 25.f; /* set mean to 0 */ + X = X * sqrt(12 / 50.f); /* adjust variance to 1 */ + + return sigma * X; + }; + # endif // ! MLN_INCLUDE_ONLY - } // end of namespace mln::fun::v2w2v + } // end of namespace mln::fun::n2v } // end of namespace mln::fun } // end of namespace mln -#endif // ! MLN_FUN_V2W2V_COS_HH +#endif // ! MLN_FUN_N2V_WHITE_GAUSSIAN_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara