-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
77 lines (58 loc) · 1.69 KB
/
Copy pathTest.cpp
File metadata and controls
77 lines (58 loc) · 1.69 KB
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
#include <iostream>
#include "CICFilter.h"
#include "FIRFilter.h"
#include <fstream>
#include <iomanip>
int main()
{
std::ifstream file("noisy_signal.txt"); // open file
if(!file){
std::cerr << "Error opening file!\n";
return 1;
}
std::vector<float> signal;
float value;
while(file >> value){
signal.push_back(value);
}
file.close();
using namespace DigitalFilter;
uint8_t stages = 1; // Number of stages in the CIC filter
const uint8_t m = 10; // CIC filter decimation factor
CICDecimateFloat CIC(stages, m);
FIRFilter firFilter(FIRFilterType::BandPass,
FIRFilterWindowType::Kaiser,
128, 100, 10.0f,15.0f, 80.0f);
// for(const auto& impr : firFilter.GetImpulseResponse()){
// std::cout << impr << std::endl;
// }
float input[m];
float output[m];
int i=0;
unsigned char outIndex;
std::vector<float> filtered;
for(auto& value : signal){
input[i] = value;
i++;
if(i % m == 0){
outIndex = CIC.Filter(input, output, i);
for(int j=0; j < outIndex; j++){
filtered.push_back(firFilter.Filter(output[j]));
}
i=0;
}
}
std::ofstream outFile("filtered.txt");
if(outFile.is_open()){
// Optional: set the floating-point precision
outFile << std::fixed << std::setprecision(6); // 6 decimal places
for(const float& val : filtered){
outFile << val << std::endl;
}
outFile.close();
}else{
std::cerr << "Error openting out file\n";
}
std::cout << "Filtered data saved to filtered.txt\n";
return 0;
}