Added filtered uniform noise demo in main.cpp.
This commit is contained in:
parent
4f078b2a0f
commit
a532068fbc
1 changed files with 33 additions and 1 deletions
34
main.cpp
34
main.cpp
|
|
@ -1,3 +1,4 @@
|
|||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue