60 using namespace INVERSELIB;
61 using namespace Eigen;
74 if(checkEmpty(hpiModelParameters)) {
78 const bool bParametersChanged = m_modelParameters != hpiModelParameters;
79 const bool bDimensionsChanged = m_iCurrentModelCols != matData.cols();
81 if(bDimensionsChanged || bParametersChanged) {
82 m_iCurrentModelCols = matData.cols();
83 m_modelParameters = hpiModelParameters;
84 selectModelAndCompute();
87 return m_matInverseSignalModel * matData.transpose();
92 bool SignalModel::checkDataDimensions(
const int iCols)
94 bool bHasChanged =
false;
95 if(iCols != m_iCurrentModelCols) {
96 m_iCurrentModelCols = iCols;
106 bool bHasChanged =
false;
107 if((m_modelParameters.iSampleFreq() != hpiModelParameters.iSampleFreq()) ||
108 (m_modelParameters.iLineFreq() != hpiModelParameters.iLineFreq()) ||
109 (m_modelParameters.iNHpiCoils() != hpiModelParameters.iNHpiCoils()) ||
110 (m_modelParameters.vecHpiFreqs() != hpiModelParameters.
vecHpiFreqs()) ||
111 (m_modelParameters.bBasic() != hpiModelParameters.bBasic())) {
113 m_modelParameters = hpiModelParameters;
123 std::cout <<
"SignalModel::checkEmpty - no Hpi frequencies set" << std::endl;
125 }
else if(hpiModelParameters.iSampleFreq() == 0) {
126 std::cout <<
"SignalModel::checkEmpty - no sampling frequencies set" << std::endl;
134 void SignalModel::selectModelAndCompute()
136 if(m_modelParameters.bBasic()) {
137 computeInverseBasicModel();
139 computeInverseAdvancedModel();
145 void SignalModel::computeInverseBasicModel()
147 const int iNumCoils = m_modelParameters.iNHpiCoils();
149 const VectorXd vecTime = VectorXd::LinSpaced(m_iCurrentModelCols, 0, m_iCurrentModelCols-1) *1.0/m_modelParameters.iSampleFreq();
152 matSimsig.conservativeResize(m_iCurrentModelCols,iNumCoils*2);
154 for(
int i = 0; i < iNumCoils; ++i) {
155 matSimsig.col(i) = sin(2*M_PI*m_modelParameters.vecHpiFreqs()[i]*vecTime.array());
156 matSimsig.col(i+iNumCoils) = cos(2*M_PI*m_modelParameters.vecHpiFreqs()[i]*vecTime.array());
163 void SignalModel::computeInverseAdvancedModel()
165 const int iNumCoils = m_modelParameters.iNHpiCoils();
166 const int iSampleFreq = m_modelParameters.iSampleFreq();
168 MatrixXd matSimsigInvTemp;
170 const VectorXd vecTime = VectorXd::LinSpaced(m_iCurrentModelCols, 0, m_iCurrentModelCols-1) *1.0/iSampleFreq;
173 matSimsig.conservativeResize(m_iCurrentModelCols,iNumCoils*4+2);
174 for(
int i = 0; i < iNumCoils; ++i) {
175 matSimsig.col(i) = sin(2*M_PI*m_modelParameters.vecHpiFreqs()[i]*vecTime.array());
176 matSimsig.col(i+iNumCoils) = cos(2*M_PI*m_modelParameters.vecHpiFreqs()[i]*vecTime.array());
177 matSimsig.col(i+2*iNumCoils) = sin(2*M_PI*m_modelParameters.iLineFreq()*(i+1)*vecTime.array());
178 matSimsig.col(i+3*iNumCoils) = cos(2*M_PI*m_modelParameters.iLineFreq()*(i+1)*vecTime.array());
180 matSimsig.col(iNumCoils*4) = RowVectorXd::LinSpaced(m_iCurrentModelCols, -0.5, 0.5);
181 matSimsig.col(iNumCoils*4+1).fill(1);
183 m_matInverseSignalModel = matSimsigInvTemp.block(0,0,iNumCoils*2,m_iCurrentModelCols);