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