From a532068fbce001094061d0dd00b03dc995641a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me?= Date: Sun, 17 Nov 2019 17:52:42 +0100 Subject: [PATCH] Added filtered uniform noise demo in main.cpp. --- main.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 4ca436c..3f56158 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include #include #include "utils.hpp" @@ -13,7 +14,8 @@ int main() { cout.precision(16); - { + if(0) + {// step response of simple 1st order filter double tend = 10., dt = 0.1, t, y = 0.; @@ -27,5 +29,35 @@ int main() } } + // if(0) + {// Generate some uniform noise and filter it to see if the filter class works as expected + uint32_t state[5] = {123456, 654897, 812656, 87913951, 0}; + + double tend = 10., + dt = 0.025, + omega = 2*M_PI*10, + Q = 20., + t, y = 0., y2; + FlyByWire::Filter2 filt1 = FlyByWire::Filter2::Bandpass(omega, Q, dt); + + std::ofstream out("data_out.m", std::ios_base::out | std::ios_base::trunc); + + if(!out.is_open()) + { + std::cerr << "Could not open the file in writing mode.\n"; + return 1; + } + + out << "a = ["; + for(int i = 0 ; i <= (tend/dt) ; i++) + { + t = i*dt; + y = RAND_XORWOW_A_B(state, -1., 1.); + y2 = filt1.Filter(y); + out << t << " " << y << " " << y2 << "\n"; + } + out << "];\nplot(a(:,1), a(:,2), a(:,1), a(:,3), 'linewidth', 2.), grid on, legend('original', 'filtered')"; + } + return 0; }