worked on FIR-Convolution and LocalMaxima detection
This commit is contained in:
45
tests/math/dsp/TestFIRComplex.cpp
Normal file
45
tests/math/dsp/TestFIRComplex.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifdef WITH_TESTS
|
||||
|
||||
#include <fstream>
|
||||
#include "../../Tests.h"
|
||||
#include "../../../math/dsp/FIRComplex.h"
|
||||
#include <random>
|
||||
|
||||
|
||||
TEST(FIRComplex, filter1) {
|
||||
|
||||
const float sRate = 200;
|
||||
const float freq = 10;
|
||||
|
||||
FIRComplex f(sRate);
|
||||
f.lowPass(5, 50); f.dumpKernel("/tmp/k1.m", "k1");
|
||||
f.shiftBy(freq); f.dumpKernel("/tmp/k2.m", "k2");
|
||||
|
||||
std::minstd_rand gen;
|
||||
std::normal_distribution<float> noise(0.0, 0.3);
|
||||
|
||||
std::vector<std::complex<float>> out;
|
||||
|
||||
std::ofstream fileO("/tmp/orig.dat");
|
||||
std::ofstream fileF("/tmp/filtered.dat");
|
||||
|
||||
for (int i = 0; i < 1000; ++i) {
|
||||
const float t = i / sRate;
|
||||
const float n = noise(gen);
|
||||
const float s = std::sin(2*M_PI*freq*t);
|
||||
const float v = s+n;
|
||||
std::vector<float> values;
|
||||
values.push_back(s+n);
|
||||
fileO << v << "\n";
|
||||
std::vector<std::complex<float>> res = f.append(values);
|
||||
out.insert(out.end(), res.begin(), res.end());
|
||||
}
|
||||
|
||||
|
||||
for (const std::complex<float> c : out) {
|
||||
fileF << c.real() << "\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user