Skip to content

Commit

Permalink
Changes to resolution and compute structure
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbmotta committed May 11, 2021
1 parent e58927c commit 0e08945
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,16 @@ void TimeFrequency::computeTimeFreqency()
// tfplot4->show();


auto tfData = RTPROCESSINGLIB::TimeFrequencyData::computeTimeFrequency(*m_pFiffRawModel->getFiffIO()->m_qlistRaw.first().data(),
auto tfData = RTPROCESSINGLIB::TimeFrequencyData::computeEpochListTimeFrequency(*m_pFiffRawModel->getFiffIO()->m_qlistRaw.first().data(),
m_pFiffRawModel->getEventModel()->getEventMatrix(9999),
-0.100f,
0.300f);

auto averagedData = RTPROCESSINGLIB::TimeFrequencyData::averageEpochListTimeFrequency(tfData);

m_pTFModel->setFiffInfo(m_pFiffRawModel->getFiffIO()->m_qlistRaw.first().data()->info);
m_pTFModel->setSpectr(tfData);

m_pTFModel->setSpectr(averagedData);

// auto spectr = RTPROCESSINGLIB::TimeFrequencyData::computeTimeFrequency(*m_pAvgModel->getEvokedSet());

Expand Down
12 changes: 0 additions & 12 deletions libraries/disp/viewers/helpers/timefrequencymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,9 @@ QVariant TimeFrequencyModel::data(const QModelIndex &index,
}
case Qt::DisplayRole:{
QVariant variant;
// Eigen::MatrixXcd returnMat = m_vSpectr.front();
// Eigen::MatrixXd realmat = returnMat.cwiseAbs2();

// variant.setValue(realmat);

// return variant;


// Eigen::MatrixXd mat = Eigen::MatrixXd::Zero(m_vSpectr[0].rows(), m_vSpectr[0].cols());
// auto matr = m_vSpectr[0].real();
Eigen::MatrixXcd matrix = Eigen::MatrixXcd::Zero(m_vSpectr[0].rows(), m_vSpectr[0].cols());

// for (auto& channel : m_vSpectr){
// matrix += channel;
// }
int a = 0;
if(m_listSelection.size() > 0){
for (int iChIndex : m_listSelection){
Expand Down
103 changes: 75 additions & 28 deletions libraries/rtprocessing/timefrequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ using namespace RTPROCESSINGLIB;
// DEFINE STATIC RTPROCESSINGLIB METHODS
//=============================================================================================================

std::vector<Eigen::MatrixXd> TimeFrequencyData::computeTimeFrequency(const FIFFLIB::FiffEvokedSet& evokedSet)
std::vector<Eigen::MatrixXd> TimeFrequencyData::computeEpochListTimeFrequency(const FIFFLIB::FiffEvokedSet& evokedSet)
{
qDebug() << "[RTPROCESSINGLIB::computeTimeFreqency]";

Expand Down Expand Up @@ -113,57 +113,104 @@ std::vector<Eigen::MatrixXcd> TimeFrequencyData::computeComplexTimeFrequency(con

//=============================================================================================================

std::vector<Eigen::MatrixXcd> TimeFrequencyData::computeTimeFrequency(const FIFFLIB::FiffRawData &raw,
const Eigen::MatrixXi &matEvents,
float fTMinS,
float fTMaxS)
std::vector<std::vector<Eigen::MatrixXcd>> TimeFrequencyData::computeEpochListTimeFrequency(const FIFFLIB::FiffRawData &raw,
const Eigen::MatrixXi &matEvents,
float fTMinS,
float fTMaxS)
{

QMap<QString,double> mapReject;
mapReject.insert("eog", 300e-06);
int iType = 1;

MNELIB::MNEEpochDataList lstEpochDataList = MNELIB::MNEEpochDataList::readEpochs(raw,
std::vector<std::vector<Eigen::MatrixXcd> > epochTimeFrequencyList; //list of epochs x channels x tf

MNELIB::MNEEpochDataList epochDataList = MNELIB::MNEEpochDataList::readEpochs(raw,
matEvents,
fTMinS,
fTMaxS,
iType,
mapReject);

std::vector<Eigen::MatrixXcd> data;
for(QSharedPointer<MNELIB::MNEEpochData>& epoch : epochDataList){
epochTimeFrequencyList.emplace_back(computeEpochTimeFrequency(epoch,
raw.info.sfreq));
}

return epochTimeFrequencyList;
}

if(!lstEpochDataList.isEmpty()){
//=============================================================================================================

Eigen::VectorXd col = lstEpochDataList.front()->epoch.row(0).transpose();
Eigen::MatrixXcd spctr = UTILSLIB::Spectrogram::makeComplexSpectrogram(col, raw.info.sfreq * 0.2);

int iCols = spctr.cols();
int iRows = spctr.rows();
std::vector<Eigen::MatrixXcd> TimeFrequencyData::computeEpochTimeFrequency(const QSharedPointer<MNELIB::MNEEpochData>& epoch,
float sampleFrequency)
{
int numChannels(epoch->epoch.rows());

qDebug() << "Rows:" << iRows << " | Cols:" << iCols;
std::vector<Eigen::MatrixXcd> channelTimeFrequencyList;

for(int i = 0; i < lstEpochDataList.front()->epoch.rows(); i++){
Eigen::MatrixXcd matrix = Eigen::MatrixXcd::Zero(iRows, iCols);
data.push_back(matrix);
for(int channeli = 0; channeli < numChannels; channeli++){
channelTimeFrequencyList.emplace_back(UTILSLIB::Spectrogram::makeComplexSpectrogram(epoch->epoch.row(channeli).transpose(), 200));
}

//Do subsequent epochs
for (auto& epoch : lstEpochDataList){
for(int i = 0; i < epoch->epoch.rows(); i++){
Eigen::VectorXd dataCol = epoch->epoch.row(i).transpose();
Eigen::MatrixXcd Spectrum = UTILSLIB::Spectrogram::makeComplexSpectrogram(dataCol, raw.info.sfreq * 0.2);
data[i] += Spectrum;
}
}
return channelTimeFrequencyList;
}



//=============================================================================================================

Eigen::MatrixXcd TimeFrequencyData::averageEpochTimeFrequency(const std::vector<Eigen::MatrixXcd>& epochTimeFrequency)
{
if (epochTimeFrequency.empty()){
return Eigen::MatrixXcd();
}

Eigen::MatrixXcd averageTimeFrequency(epochTimeFrequency.front().rows(), epochTimeFrequency.front().cols());

for (auto tfData : data) {
tfData /= lstEpochDataList.size();
for(auto channelTimeFreq : epochTimeFrequency){
averageTimeFrequency += channelTimeFreq;
}

return averageTimeFrequency / epochTimeFrequency.size();
}

//=============================================================================================================

std::vector<Eigen::MatrixXcd> TimeFrequencyData::averageEpochListTimeFrequency(const std::vector<std::vector<Eigen::MatrixXcd> >& epochListTimeFrequency)
{
int numFreqs(epochListTimeFrequency.front().front().rows());
int numSamples(epochListTimeFrequency.front().front().cols());

int numEpochs(epochListTimeFrequency.size());

if (numSamples ==0 || numFreqs == 0 || numEpochs == 0){
return std::vector<Eigen::MatrixXcd>();
}

int numChannelsInEpoch(epochListTimeFrequency.front().size());

for (int epochindex(1) ; epochindex < epochListTimeFrequency.size(); epochindex++){
if (static_cast<int>(epochListTimeFrequency[epochindex].size()) != numChannelsInEpoch){
qDebug() << "Channel number does not match across epoch" << epochindex;
return std::vector<Eigen::MatrixXcd>();
}
}

qDebug() << "Vector size:" << data.size();
std::vector<Eigen::MatrixXcd> averagedEpochListTimeFrequency;
Eigen::MatrixXcd auxMatrix;

for (int iChannel = 0; iChannel < numChannelsInEpoch; iChannel++){
auxMatrix = Eigen::MatrixXcd::Zero(numFreqs, numSamples);
for (auto epoch : epochListTimeFrequency){
auxMatrix += epoch[iChannel];
}
auxMatrix /= numEpochs;
averagedEpochListTimeFrequency.push_back(auxMatrix);
}

return data;
return averagedEpochListTimeFrequency;
}

//=============================================================================================================
Expand Down
17 changes: 15 additions & 2 deletions libraries/rtprocessing/timefrequency.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ namespace FIFFLIB {
class FiffEvokedSet;
}

namespace MNELIB {
class MNEEpochData;
}

//=============================================================================================================
// DEFINE NAMESPACE RTPROCESSINGLIB
//=============================================================================================================
Expand All @@ -77,15 +81,24 @@ class RTPROCESINGSHARED_EXPORT TimeFrequencyData

TimeFrequencyData(Eigen::MatrixXcd mat);

static std::vector<Eigen::MatrixXd> computeTimeFrequency(const FIFFLIB::FiffEvokedSet& evokedSet);
static std::vector<Eigen::MatrixXd> computeEpochListTimeFrequency(const FIFFLIB::FiffEvokedSet& evokedSet);

static std::vector<Eigen::MatrixXcd> computeComplexTimeFrequency(const FIFFLIB::FiffEvokedSet& evokedSet);

static std::vector<Eigen::MatrixXcd> computeTimeFrequency(const FIFFLIB::FiffRawData& raw,
static std::vector<std::vector<Eigen::MatrixXcd> > computeEpochListTimeFrequency(const FIFFLIB::FiffRawData& raw,
const Eigen::MatrixXi& matEvents,
float fTMinS,
float fTMaxS);

static std::vector<Eigen::MatrixXcd> computeEpochTimeFrequency(const QSharedPointer<MNELIB::MNEEpochData>& epoch,
float sampleFrequency);

static Eigen::MatrixXcd averageEpochTimeFrequency(const std::vector<Eigen::MatrixXcd>& epochTimeFrequency);

static std::vector<Eigen::MatrixXcd> averageEpochListTimeFrequency(const std::vector<std::vector<Eigen::MatrixXcd> >& epochListTimeFrequency);



Eigen::MatrixXcd getData();

TimeFrequencyData& operator=(const Eigen::MatrixXcd& mat)
Expand Down
2 changes: 1 addition & 1 deletion libraries/utils/spectrogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ MatrixXcd Spectrogram::makeComplexSpectrogram(VectorXd signal, qint32 windowSize

signal.array() -= signal.mean();
QList<SpectogramInputData> lData;
int iThreadSize = QThread::idealThreadCount()*2;
int iThreadSize = QThread::idealThreadCount();
int iStepsSize = signal.rows()/iThreadSize;
int iResidual = signal.rows()%iThreadSize;

Expand Down

0 comments on commit 0e08945

Please sign in to comment.