48 #include <QStringList>
49 #include <QRegularExpression>
55 using namespace RTPROCESSINGLIB;
56 using namespace Eigen;
71 if(!path.contains(
".txt"))
75 if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
76 qDebug()<<
"Error opening filter txt file for reading";
81 QTextStream in(&file);
82 QVector<double> coefficientsTemp;
86 QString line = in.readLine();
88 QStringList fields = line.split(QRegularExpression(
"\\s+"));
91 if(fields.at(fields.size()-1) ==
"")
94 if(line.contains(
"#"))
97 if(line.contains(
"sFreq") && fields.size()==2)
98 filter.setSamplingFrequency(fields.at(1).toDouble());
101 if(line.contains(
"name")) {
103 for(
int i=1; i<fields.size(); i++)
104 sFilterName.append(fields.at(i));
105 filter.setName(sFilterName);
109 if(line.contains(
"order") && fields.size()==2)
110 filter.setFilterOrder(fields.at(1).toInt());
113 if(line.contains(
"type") && fields.size()==2)
117 if(line.contains(
"LPFreq") && fields.size()==2)
118 filter.setLowpassFreq(fields.at(1).toDouble());
121 if(line.contains(
"HPFreq") && fields.size()==2)
122 filter.setHighpassFreq(fields.at(1).toDouble());
125 if(line.contains(
"CenterFreq") && fields.size()==2)
126 filter.setCenterFrequency(fields.at(1).toDouble());
129 if(line.contains(
"DesignMethod") && fields.size()==2)
133 coefficientsTemp.push_back(fields.join(
"").toDouble());
136 if(filter.getFilterOrder() != coefficientsTemp.size()) {
137 filter.setFilterOrder(coefficientsTemp.size());
140 RowVectorXd vecCoeff = RowVectorXd::Zero(coefficientsTemp.size());
141 for(
int i=0; i < vecCoeff.cols(); i++) {
142 vecCoeff(i) = coefficientsTemp.at(i);
144 filter.setCoefficients(vecCoeff);
159 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
160 qDebug()<<
"Error opening filter txt file for writing";
165 QTextStream out(&file);
167 out <<
"#sFreq " << filter.getSamplingFrequency() <<
"\n";
168 out <<
"#name " << filter.getName() <<
"\n";
169 out <<
"#type " << filter.getFilterType().
getName() <<
"\n";
170 out <<
"#order " << filter.getFilterOrder() <<
"\n";
171 out <<
"#HPFreq " << filter.getHighpassFreq() <<
"\n";
172 out <<
"#LPFreq " << filter.getLowpassFreq() <<
"\n";
173 out <<
"#CenterFreq " << filter.getCenterFrequency() <<
"\n";
174 out <<
"#DesignMethod " << filter.getDesignMethod().
getName() <<
"\n";
176 for(
int i = 0 ; i<filter.getCoefficients().cols() ;i++)
177 out << filter.getCoefficients()(i) <<
"\n";
184 qDebug()<<
"Error Filter File path is empty";