Daniel Petti | 339f88a | 2015-02-07 22:51:20 -0800 | [diff] [blame] | 1 | #ifndef FRC971_CONTROL_LOOPS_GAUSSIAN_NOISE_H_ |
| 2 | #define FRC971_CONTROL_LOOPS_GAUSSIAN_NOISE_H_ |
| 3 | |
| 4 | #include <unistd.h> |
| 5 | |
| 6 | #include <memory> |
| 7 | #include <random> |
| 8 | |
| 9 | namespace frc971 { |
| 10 | namespace control_loops { |
| 11 | |
| 12 | class GaussianNoise { |
| 13 | public: |
| 14 | // seed: The seed for the random number generator. |
| 15 | // stddev: The standard deviation of the distribution. |
| 16 | GaussianNoise(unsigned int seed, double stddev); |
| 17 | |
| 18 | // Returns a version of the sample with gaussian noise added in. |
| 19 | double AddNoiseToSample(double sample); |
| 20 | |
| 21 | // Sets the standard deviation of the gaussian noise. |
| 22 | inline void set_standard_deviation(double stddev) { |
| 23 | stddev_ = stddev; |
| 24 | } |
| 25 | |
| 26 | private: |
| 27 | double stddev_; |
| 28 | |
| 29 | std::default_random_engine generator_; |
| 30 | std::normal_distribution<double> distribution_; |
| 31 | }; |
| 32 | |
| 33 | } // namespace control_loops |
| 34 | } // namespace frc971 |
| 35 | |
| 36 | #endif // FRC971_CONTROL_LOOPS_GAUSSIAN_NOISE_H_ |