Commit 1c61d196 authored by Adrien Dorsaz's avatar Adrien Dorsaz

Add possibility to filter two bands with only one filter

Please think about revert this commit and find a better solution to have same result : it duplicates a lot of code and it doesn't add anything.

Maybe we could create a method "addFilterBand(int lowBand, int highBand, int norder)" and use a QList of bands to filter.
parent c3e4ab6e
......@@ -69,6 +69,7 @@ void Sbs2EmocapPacket::update(char *data)
values[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues2ndBand[Sbs2Common::getChannelNames()->at(m)] = level;
}
}
......@@ -71,6 +71,7 @@ void Sbs2Emocap28Packet::update(char *data)
values[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues2ndBand[Sbs2Common::getChannelNames()->at(m)] = level;
}
}
......@@ -120,6 +121,7 @@ void Sbs2Emocap28Packet::update(char *data1, char *data2)
values[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues2ndBand[Sbs2Common::getChannelNames()->at(m)] = level;
}
for (int m=14; m<28; ++m)
......@@ -138,6 +140,7 @@ void Sbs2Emocap28Packet::update(char *data1, char *data2)
}
values[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues2ndBand[Sbs2Common::getChannelNames()->at(m)] = level;
}
//qDebug() << counter1 << counter2 << values["O2"] << values["O2_2"];
......
......@@ -70,6 +70,7 @@ void Sbs2EmotivPacket::update(char *data)
values[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues[Sbs2Common::getChannelNames()->at(m)] = level;
filteredValues2ndBand[Sbs2Common::getChannelNames()->at(m)] = level;
}
}
......
......@@ -12,6 +12,7 @@ Sbs2Packet::Sbs2Packet(QObject *parent) :
{
values[Sbs2Common::getChannelNames()->at(m)] = 0;
filteredValues[Sbs2Common::getChannelNames()->at(m)] = 0;
filteredValues2ndBand[Sbs2Common::getChannelNames()->at(m)] = 0;
}
}
......
......@@ -66,6 +66,7 @@ public:
QString cqName;
QMap<QString, double> values;
QMap<QString, double> filteredValues;
QMap<QString, double> filteredValues2ndBand;
int battery;
char* rawData;
......
......@@ -12,6 +12,9 @@ Sbs2DataHandler::Sbs2DataHandler(QObject *parent) :
sbs2Filter = 0;
toFilterValues = 0;
filterResultValues = 0;
filterOn2nd = 0;
filterOrder2nd = 0;
filterResultValues2nd = 0;
//recording
recording = 0;
......@@ -90,6 +93,34 @@ void Sbs2DataHandler::filter()
}
void Sbs2DataHandler::filter2bands()
{
if (!filterOn || !filterOn2nd){
qDebug() << "2 bands filter not ready";
return;
}
//qDebug()<<"sbs2DH : initiate filter 2bands...";
for (int row=0; row<Sbs2Common::channelsNo(); ++row)
{
for (int column = filterOrder; column > 0; --column){
(*toFilterValues)[row][column] = (*toFilterValues)[row][column-1];
}
//qDebug() << "Get channel name : " << Sbs2Common::getChannelNames()->at(row);
(*toFilterValues)[row][0] = thisPacket->values[Sbs2Common::getChannelNames()->at(row)];
}
//qDebug()<<"sbs2DH : filter 2bands...";
sbs2Filter->doFilter2(toFilterValues,filterResultValues, filterResultValues2nd);
//qDebug()<<"sbs2DH : save filtered values 2bands";
for (int row = 0; row<Sbs2Common::channelsNo(); ++row){
thisPacket->filteredValues[Sbs2Common::getChannelNames()->at(row)] = (*filterResultValues)[row][0];
thisPacket->filteredValues2ndBand[Sbs2Common::getChannelNames()->at(row)] = (*filterResultValues2nd)[row][0];
}
//qDebug()<<"sbs2DH: End of filter start 2bands";
}
void Sbs2DataHandler::spectrogramChannel()
{
if (!spectrogramChannelOn)
......@@ -197,6 +228,7 @@ void Sbs2DataHandler::sourceReconstructionPower()
void Sbs2DataHandler::turnFilterOff()
{
filterOn = 0;
filterOn2nd = 0;
if (!(toFilterValues == 0))
{
delete toFilterValues;
......@@ -207,6 +239,11 @@ void Sbs2DataHandler::turnFilterOff()
delete filterResultValues;
filterResultValues = 0;
}
if (!(filterResultValues2nd == 0))
{
delete filterResultValues2nd;
filterResultValues2nd = 0;
}
if (!(sbs2Filter == 0))
{
delete sbs2Filter;
......@@ -243,6 +280,51 @@ void Sbs2DataHandler::turnFilterOn(int fbandLow_, int fbandHigh_, int filterOrde
filterOn = 1;
}
void Sbs2DataHandler::turnFilterOn2bands(int fbandLow_, int fbandHigh_, int filterOrder_,
int fbandLow2_, int fbandHigh2_, int filterOrder2_)
{
fbandLow = fbandLow_;
fbandHigh = fbandHigh_;
filterOrder = filterOrder_;
fbandLow2nd = fbandLow2_;
fbandHigh2nd = fbandHigh2_;
filterOrder2nd = filterOrder2_;
if (!(toFilterValues == 0))
{
delete toFilterValues;
toFilterValues = 0;
}
if (!(filterResultValues == 0))
{
delete filterResultValues;
filterResultValues = 0;
}
if (!(filterResultValues2nd == 0))
{
delete filterResultValues2nd;
filterResultValues2nd = 0;
}
qDebug() << "sbs2DH : create filter 2bands";
sbs2Filter = Sbs2Filter::New2(fbandLow,fbandHigh,filterOrder,
fbandLow2nd, fbandHigh2nd, filterOrder2nd, this);
qDebug() << "sbs2DH : create matrices 2bands";
toFilterValues = new DTU::DtuArray2D<double> (Sbs2Common::channelsNo(),filterOrder+1);
filterResultValues = new DTU::DtuArray2D<double> (Sbs2Common::channelsNo(),1);
filterResultValues2nd = new DTU::DtuArray2D<double> (Sbs2Common::channelsNo(),1);
qDebug() << "sbs2DH : reset ? 2bands";
reset();
qDebug() << "sbs2DH : update filter 2bands";
sbs2Filter->updateFilter2nd(filterOrder,fbandLow,fbandHigh,
filterOrder2nd, fbandLow2nd, fbandHigh2nd);
filterOn = 1;
filterOn2nd = 1;
}
void Sbs2DataHandler::record()
{
if (recording)
......@@ -585,6 +667,10 @@ void Sbs2DataHandler::reset()
{
(*filterResultValues) = 0;
}
if (!(filterResultValues2nd ==0))
{
(*filterResultValues2nd) = 0;
}
if (!(toSpectrogramValues ==0))
{
(*toSpectrogramValues) = 0;
......
......@@ -45,6 +45,7 @@ public:
//filtering
virtual void filter();
virtual void filter2bands();
//recording
virtual void record();
......@@ -76,11 +77,19 @@ protected:
int filterOrder;
int fbandLow;
int fbandHigh;
// 2nd band filtering
int filterOn2nd;
int filterOrder2nd;
int fbandLow2nd;
int fbandHigh2nd;
//objects
Sbs2Filter* sbs2Filter;
//data matrices
DTU::DtuArray2D<double>* toFilterValues;
DTU::DtuArray2D<double>* filterResultValues;
DTU::DtuArray2D<double>* filterResultValues2nd;
//recording
int recording;
......@@ -147,6 +156,10 @@ public slots:
void turnFilterOn(int fbandLow_, int fbandHigh_, int filterOrder_);
void turnFilterOff();
//filtering
void turnFilterOn2bands(int fbandLow_, int fbandHigh_, int filterOrder_,
int fbandLow2_, int fbandHigh2_, int filterOrder2_);
//recording
void startRecording(QString user, QString description);
void stopRecording();
......
......@@ -10,6 +10,16 @@ Sbs2Filter* Sbs2Filter::New(int fbandLow_, int fbandHigh_, int order_, QObject *
return m_pInstance;
}
Sbs2Filter* Sbs2Filter::New2(int fbandLow_, int fbandHigh_, int order_,
int fbandLow2_, int fbandHigh2_, int order2_, QObject *parent)
{
if (!m_pInstance){
m_pInstance = new Sbs2Filter(fbandLow_,fbandHigh_,order_,
fbandLow2_, fbandHigh2_, order2_ ,parent);
}
return m_pInstance;
}
Sbs2Filter::Sbs2Filter(int fbandLow_, int fbandHigh_, int order_, QObject *parent): QObject(parent),fbandLow(fbandLow_), fbandHigh(fbandHigh_), order(order_)
{
......@@ -17,6 +27,21 @@ Sbs2Filter::Sbs2Filter(int fbandLow_, int fbandHigh_, int order_, QObject *paren
loadFilter();
}
Sbs2Filter::Sbs2Filter(int fbandLow_, int fbandHigh_, int order_,
int fbandLow2_, int fbandHigh2_, int order2_, QObject *parent)
{
fbandLow=fbandLow_;
fbandHigh=fbandHigh_;
order=order_;
fbandLow2nd=fbandLow2_;
fbandHigh2nd=fbandHigh2_;
order2nd=order2_;
hcoef2 = 0;
hcoef2_2nd = 0;
loadFilter();
loadFilter2nd();
}
void Sbs2Filter::loadFilter()
{
......@@ -63,6 +88,50 @@ void Sbs2Filter::loadFilter()
}
void Sbs2Filter::loadFilter2nd()
{
if (!(hcoef2_2nd == 0))
{
delete hcoef2_2nd;
hcoef2_2nd = 0;
}
hcoef2_2nd = new DTU::DtuArray2D<double>(1,order2nd+1);
QString filename;
filename.append(Sbs2Common::getRootAppPath());
filename.append("filtercoef_fband");
filename.append(QString::number(fbandLow2nd));
filename.append("-");
filename.append(QString::number(fbandHigh2nd));
filename.append("_norder");
filename.append(QString::number(order2nd));
filename.append(".txt");
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
qDebug() << "sbs2-filter : ERROR: unable to find file : "<<filename;
return;
}
int i=0;
while (!file.atEnd())
{
QByteArray line = file.readLine();
QString str = line.data();
QStringList list1 = str.split("\t");
for (int j = 0; j < list1.size(); j++)
{
(*hcoef2_2nd)[0][j] = list1.at(j).toDouble();
}
i++;
}
}
void Sbs2Filter::updateFilter(int order_, int fbandLow_, int fbandHigh_)
{
order=order_;
......@@ -71,6 +140,19 @@ void Sbs2Filter::updateFilter(int order_, int fbandLow_, int fbandHigh_)
loadFilter();
}
void Sbs2Filter::updateFilter2nd(int order_, int fbandLow_, int fbandHigh_,
int order2_, int fbandLow2_, int fbandHigh2_)
{
order=order_;
fbandHigh=fbandHigh_;
fbandLow=fbandLow_;
order2nd=order2_;
fbandHigh2nd=fbandHigh2_;
fbandLow2nd=fbandLow2_;
loadFilter();
loadFilter2nd();
}
void Sbs2Filter::doFilter(DTU::DtuArray2D<double>* values, DTU::DtuArray2D<double>* returnValues)
{
......@@ -93,6 +175,30 @@ void Sbs2Filter::doFilter(DTU::DtuArray2D<double>* values, DTU::DtuArray2D<doubl
}
}
void Sbs2Filter::doFilter2(DTU::DtuArray2D<double>* values, DTU::DtuArray2D<double>* returnValues, DTU::DtuArray2D<double>* returnValues2nd)
{
if (!(values->dim1() == returnValues->dim1())) //14 for emotiv
return;
if (!(values->dim2() == (order +1))) //columns of the values
return;
double yn, yn2nd;
for (int j=0; j<values->dim1(); j++)
{
yn = 0.0;
yn2nd = 0.0;
for (int k=0; k<values->dim2(); k++)
{
yn += (*hcoef2)[0][k] * ((*values)[j][k]);
yn2nd += (*hcoef2_2nd)[0][k] * ((*values)[j][k]);
}
(*returnValues)[j][0] = yn;
(*returnValues2nd)[j][0] = yn2nd;
}
}
Sbs2Filter::~Sbs2Filter()
{
......@@ -101,6 +207,10 @@ Sbs2Filter::~Sbs2Filter()
delete hcoef2;
hcoef2 = 0;
}
if (!(hcoef2_2nd == 0)){
delete hcoef2_2nd;
hcoef2_2nd = 0;
}
m_pInstance = 0;
}
......@@ -42,9 +42,17 @@ class Sbs2Filter : public QObject
public:
static Sbs2Filter* New(int fbandLow_, int fbandHigh_, int order_, QObject *parent = 0);
static Sbs2Filter* New2(int fbandLow_, int fbandHigh_, int order_,
int fbandLow2_, int fbandHigh2_, int order2_, QObject *parent = 0);
void loadFilter();
void loadFilter2nd();
void updateFilter(int order_, int fbandLow_, int fbandHigh_);
void updateFilter2nd(int order_, int fbandLow_, int fbandHigh_,
int order2_, int fbandLow2_, int fbandHigh2_);
void doFilter(DTU::DtuArray2D<double>* values, DTU::DtuArray2D<double>* returnValues);
void doFilter2(DTU::DtuArray2D<double>* values, DTU::DtuArray2D<double>* returnValues, DTU::DtuArray2D<double>* returnValues2nd);
~Sbs2Filter();
private:
......@@ -54,8 +62,16 @@ private:
int fbandLow;
int fbandHigh;
int order;
DTU::DtuArray2D<double>* hcoef2_2nd;
int fbandLow2nd;
int fbandHigh2nd;
int order2nd;
static Sbs2Filter* m_pInstance;
Sbs2Filter(int fbandLow_, int fbandHigh_, int order_, QObject *parent = 0);
Sbs2Filter(int fbandLow_, int fbandHigh_, int order_,
int fbandLow2_, int fbandHigh2_, int order2_, QObject *parent = 0);
signals:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment