MNE-CPP  0.1.9
A Framework for Electrophysiology
imagcoherence.cpp
Go to the documentation of this file.
1 //=============================================================================================================
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "coherency.h"
43 #include "imagcoherence.h"
44 #include "../network/networknode.h"
45 #include "../network/networkedge.h"
46 #include "../network/network.h"
47 
48 //=============================================================================================================
49 // QT INCLUDES
50 //=============================================================================================================
51 
52 #include <QDebug>
53 #include <QtConcurrent>
54 
55 //=============================================================================================================
56 // EIGEN INCLUDES
57 //=============================================================================================================
58 
59 #include <unsupported/Eigen/FFT>
60 
61 //=============================================================================================================
62 // USED NAMESPACES
63 //=============================================================================================================
64 
65 using namespace CONNECTIVITYLIB;
66 using namespace Eigen;
67 
68 //=============================================================================================================
69 // DEFINE GLOBAL METHODS
70 //=============================================================================================================
71 
72 //=============================================================================================================
73 // DEFINE MEMBER METHODS
74 //=============================================================================================================
75 
77 {
78 }
79 
80 //*******************************************************************************************************
81 
83 {
84  Network finalNetwork("IMAGCOH");
85 
86  if(connectivitySettings.isEmpty()) {
87  qDebug() << "ImagCoherence::calculate - Input data is empty";
88  return finalNetwork;
89  }
90 
91  if(AbstractMetric::m_bStorageModeIsActive == false) {
92  connectivitySettings.clearIntermediateData();
93  }
94 
95  finalNetwork.setSamplingFrequency(connectivitySettings.getSamplingFrequency());
96 
97  // Check if start and bin amount need to be reset to full spectrum
98  int iNfft = connectivitySettings.getFFTSize();
99 
100 // // Check that iNfft >= signal length
101 // if(iNfft > connectivitySettings.at(0).matData.cols()) {
102 // iNfft = connectivitySettings.at(0).matData.cols();
103 // }
104 
105  int iNFreqs = int(floor(iNfft / 2.0)) + 1;
106 
107  if(m_iNumberBinStart == -1 ||
108  m_iNumberBinAmount == -1 ||
109  m_iNumberBinStart > iNFreqs ||
110  m_iNumberBinAmount > iNFreqs ||
111  m_iNumberBinAmount + m_iNumberBinStart > iNFreqs) {
112  qDebug() << "ImagCoherence::calculate - Resetting to full spectrum";
113  AbstractMetric::m_iNumberBinStart = 0;
114  AbstractMetric::m_iNumberBinAmount = iNFreqs;
115  }
116 
117  // Pass information about the FFT length. Use iNFreqs because we only use the half spectrum
118  finalNetwork.setFFTSize(iNFreqs);
119  finalNetwork.setUsedFreqBins(AbstractMetric::m_iNumberBinAmount);
120 
121  //Create nodes
122  int rows = connectivitySettings.at(0).matData.rows();
123  RowVectorXf rowVert = RowVectorXf::Zero(3);
124 
125  for(int i = 0; i < rows; ++i) {
126  rowVert = RowVectorXf::Zero(3);
127 
128  if(connectivitySettings.getNodePositions().rows() != 0 && i < connectivitySettings.getNodePositions().rows()) {
129  rowVert(0) = connectivitySettings.getNodePositions().row(i)(0);
130  rowVert(1) = connectivitySettings.getNodePositions().row(i)(1);
131  rowVert(2) = connectivitySettings.getNodePositions().row(i)(2);
132  }
133 
134  finalNetwork.append(NetworkNode::SPtr(new NetworkNode(i, rowVert)));
135  }
136 
137  //Calculate all-to-all imaginary coherence matrix over epochs
138  Coherency::calculateImag(finalNetwork,
139  connectivitySettings);
140 
141  return finalNetwork;
142 }
CONNECTIVITYLIB::Network
This class holds information about a network, can compute a distance table and provide network metric...
Definition: network.h:88
CONNECTIVITYLIB::Network::append
void append(QSharedPointer< NetworkEdge > newEdge)
CONNECTIVITYLIB::ImagCoherence::ImagCoherence
ImagCoherence()
Definition: imagcoherence.cpp:76
coherency.h
Coherency class declaration.
CONNECTIVITYLIB::Network::setSamplingFrequency
void setSamplingFrequency(float fSFreq)
Definition: network.cpp:492
CONNECTIVITYLIB::ImagCoherence::calculate
static Network calculate(ConnectivitySettings &connectivitySettings)
Definition: imagcoherence.cpp:82
CONNECTIVITYLIB::Coherency::calculateImag
static void calculateImag(Network &finalNetwork, ConnectivitySettings &connectivitySettings)
Definition: coherency.cpp:156
CONNECTIVITYLIB::Network::setUsedFreqBins
void setUsedFreqBins(int iNumberFreqBins)
Definition: network.cpp:506
CONNECTIVITYLIB::Network::setFFTSize
void setFFTSize(int iFFTSize)
Definition: network.cpp:513
CONNECTIVITYLIB::ConnectivitySettings
This class is a container for connectivity settings.
Definition: connectivitysettings.h:91
imagcoherence.h
Imaginary coherence class declaration.
CONNECTIVITYLIB::NetworkNode::SPtr
QSharedPointer< NetworkNode > SPtr
Definition: networknode.h:85
CONNECTIVITYLIB::NetworkNode
This class holds an object to describe the node of a network.
Definition: networknode.h:81