forked from labstreaminglayer/App-BrainAmpSeries
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
88 lines (81 loc) · 2.39 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "mainwindow.h"
#include <QApplication>
#include <string>
#include "Downsampler.h"
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
void testFilter()
{
int nDownsamplingFactor = 2;
int nChunkLen = 10;
std::vector<Downsampler<double>*> downsamplers;
downsamplers.push_back(new Downsampler<double>(nDownsamplingFactor, nChunkLen));
double* pdDataIn = (double*)malloc(sizeof(double) * nChunkLen * nDownsamplingFactor);
double* pdDataOut = (double*)malloc(sizeof(double) * nChunkLen);
std::ifstream ifDataIn;
std::ofstream ofDataOut;
std::string str;
int idx = 0;
ifDataIn.open("C:\\Users\\david.medine\\matlab\\random_noise.txt");
ofDataOut.open("C:\\Users\\david.medine\\matlab\\filtered.txt");
while (std::getline(ifDataIn, str))
{
pdDataIn[idx++] = std::stod(str);
if (idx >= nDownsamplingFactor * nChunkLen)
{
downsamplers[0]->Downsample(pdDataIn);
for (int i = 0; i < nChunkLen; i++)
ofDataOut << downsamplers[0]->m_ptDataOut[i] << "\n";
idx = 0;
}
}
free(pdDataIn);
free(pdDataOut);
delete downsamplers[0];
}
void testDownsampler()
{
int nDownsamplingFactor = 5;
int nChunkLen = 10;
std::vector<Downsampler<double>*> downsamplers;
downsamplers.push_back(new Downsampler<double>(nDownsamplingFactor, nChunkLen));
double* pdDataIn = (double*)malloc(sizeof(double) * nChunkLen * nDownsamplingFactor);
double* pdDataOut = (double*)malloc(sizeof(double) * nChunkLen);
std::ifstream ifDataIn;
std::ofstream ofDataOut;
std::string str;
int idx = 0;
ifDataIn.open("C:\\Users\\david.medine\\matlab\\additive.txt");
ofDataOut.open("C:\\Users\\david.medine\\matlab\\downsampled.txt");
while(std::getline(ifDataIn, str))
{
pdDataIn[idx++] = std::stod(str);
if (idx >= nDownsamplingFactor * nChunkLen)
{
downsamplers[0]->Downsample(pdDataIn);
for (int i = 0; i < nChunkLen; i++)
ofDataOut << downsamplers[0]->m_ptDataOut[i] << "\n";
idx = 0;
}
}
free(pdDataIn);
free(pdDataOut);
delete downsamplers[0];
}
int main(int argc, char* argv[]) {
//testDownsampler();
//testFilter();
//return 0;
// determine the startup config file...
const char* config_file = "BrainAmpSeries.cfg";
for (int k = 1; k < argc; k++)
if (std::string(argv[k]) == "-c" || std::string(argv[k]) == "--config")
config_file = argv[k + 1];
QApplication a(argc, argv);
MainWindow w(nullptr, config_file);
w.show();
return a.exec();
}