Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ea138a88 authored by Alison Cellard's avatar Alison Cellard
Browse files

Clean up Hilbert transform code

Fix bug in S-PLV algorithm
parent 736980a4
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,6 @@ boolean CAlgorithmHilbertTransform::process(void)
m_vecXcdSignalBuffer(samples).real(l_pInputMatrix->getBuffer()[samples + channel * (l_ui32SamplesPerChannel)]);
m_vecXcdSignalBuffer(samples).imag(0.0);
}
// std::cout <<"channel "<<channel<<" = "<<m_vecXcdSignalBuffer.transpose()<<std::endl;
//Fast Fourier Transform of input signal
fft.fwd(m_vecXcdSignalFourier, m_vecXcdSignalBuffer);
......@@ -133,14 +132,10 @@ boolean CAlgorithmHilbertTransform::process(void)
//Inverse Fast Fourier transform
fft.inv(m_vecXcdSignalBuffer, m_vecXcdSignalFourier); // m_vecXcdSignalBuffer is now the analytical signal of the initial input signal
//std::cout <<"channel "<<channel<<" = "<<m_vecXcdSignalBuffer.transpose()<<std::endl;
//Compute envelope and phase and pass it to the corresponding output
for(uint32 samples=0; samples<l_ui32SamplesPerChannel;samples++)
{
//std::cout<<"channel "<<channel<<" = "<<arg(m_vecXcdSignalBuffer(samples))<<std::endl;
l_pOutputHilbertMatrix->getBuffer()[samples + channel*l_ui32SamplesPerChannel] = m_vecXcdSignalBuffer(samples).imag();
l_pOutputEnvelopeMatrix->getBuffer()[samples + channel*l_ui32SamplesPerChannel] = abs(m_vecXcdSignalBuffer(samples));
l_pOutputPhaseMatrix->getBuffer()[samples + channel*l_ui32SamplesPerChannel] = arg(m_vecXcdSignalBuffer(samples));
......
......@@ -165,7 +165,7 @@ boolean CAlgorithmSingleTrialPhaseLockingValue::process(void)
//Compute S-PLV for each pairs
for(uint32 channel = 0; channel < l_ui32PairsCount*2; channel = channel+1)
for(uint32 channel = 0; channel < l_ui32PairsCount; channel = channel+1)
{
l_vecXdChannelToCompare1 = VectorXd::Zero(l_ui32SamplesPerChannel1);
l_vecXdChannelToCompare2 = VectorXd::Zero(l_ui32SamplesPerChannel2);
......
......@@ -249,182 +249,42 @@ boolean CBoxAlgorithmConnectivityMeasure::process(void)
else
{
// The ranges are valid so selects all the channels in those range
this->getLogManager() << LogLevel_Trace << "For range [" << l_sChannel[chan] << "] :\n";
for(uint32 k=l_ui32RangeStartIndex; k<=l_ui32RangeEndIndex; k++)
{
for(uint32 j=l_ui32RangeStartIndex2; j<=l_ui32RangeEndIndex2; j++)
{
m_vChannelTable.push_back(k);
m_vChannelTable.push_back(j);
this->getLogManager() << LogLevel_Info << " Selected channels [" << k+1 << ","<< j+1 <<"]\n";
//std::cout<< "Selected channel [" << k+1 << ","<< j+1 << "]\n"<<std::endl;
}
}
}
/* // Checks if the channel designation of each side of the "-" is a range
if(OpenViBEToolkit::Tools::String::split(l_sChannel[chan], OpenViBEToolkit::Tools::String::TSplitCallback < std::vector < CString > >(l_sSubChannel), OV_Value_RangeStringSeparator)==2)
{
m_bRange1 = true;
}
if(OpenViBEToolkit::Tools::String::split(l_sChannel[chan+1], OpenViBEToolkit::Tools::String::TSplitCallback < std::vector < CString > >(l_sSubChannel2), OV_Value_RangeStringSeparator)==2)
{
m_bRange2 = true;
}
//4 cases:
//Case 1 : There is 2 ranges
if(m_bRange1 && m_bRange2) //Check if there is 2 ranges
{
// Finds the first & second part of both range (only index based)
uint32 l_ui32RangeStartIndex=::_find_channel_(*ip_pMatrix1, l_sSubChannel[0], OVP_TypeId_MatchMethod_Index);
uint32 l_ui32RangeEndIndex=::_find_channel_(*ip_pMatrix1, l_sSubChannel[1], OVP_TypeId_MatchMethod_Index);
uint32 l_ui32RangeStartIndex2 =::_find_channel_(*ip_pMatrix1, l_sSubChannel2[0], OVP_TypeId_MatchMethod_Index);
uint32 l_ui32RangeEndIndex2=::_find_channel_(*ip_pMatrix1, l_sSubChannel2[1], OVP_TypeId_MatchMethod_Index);
// When first or second part is not found but associated token is empty, don't consider this as an error
if(l_ui32RangeStartIndex==uint32(-1) && l_sSubChannel[0]==CString("")) l_ui32RangeStartIndex=0;
if(l_ui32RangeEndIndex ==uint32(-1) && l_sSubChannel[1]==CString("")) l_ui32RangeEndIndex=ip_pMatrix1->getDimensionSize(0)-1;
if(l_ui32RangeStartIndex2==uint32(-1) && l_sSubChannel2[0]==CString("")) l_ui32RangeStartIndex2=0;
if(l_ui32RangeEndIndex2 ==uint32(-1) && l_sSubChannel2[1]==CString("")) l_ui32RangeEndIndex2=ip_pMatrix1->getDimensionSize(0)-1;
/* uint32 l_bFound=false;
uint32 l_ui32Index=uint32(-1);
// After these corrections, if either first or second token were not found, or if start index is greater than start index, consider this an error and invalid range
if(l_ui32RangeStartIndex==uint32(-1) || l_ui32RangeEndIndex ==uint32(-1) || l_ui32RangeStartIndex>l_ui32RangeEndIndex)
{
this->getLogManager() << LogLevel_Warning << "Invalid channel range [" << l_sChannel[chan] << "] - splitted as [" << l_sSubChannel[0] << "][" << l_sSubChannel[1] << "]\n";
}
else if(l_ui32RangeStartIndex2==uint32(-1) || l_ui32RangeEndIndex2 ==uint32(-1) || l_ui32RangeStartIndex2>l_ui32RangeEndIndex2)
{
this->getLogManager() << LogLevel_Warning << "Invalid channel range [" << l_sChannel[chan+1] << "] - splitted as [" << l_sSubChannel2[0] << "][" << l_sSubChannel2[1] << "]\n";
}
else
// Looks for all the channels with this name
while((l_ui32Index=::_find_channel_(*m_pInputMatrix, l_sToken[j], l_ui64MatchMethodIdentifier, l_ui32Index+1))!=uint32(-1))
{
// The ranges are valid so selects all the channels in those range
this->getLogManager() << LogLevel_Trace << "For range [" << l_sChannel[chan] << "] :\n";
for(uint32 k=l_ui32RangeStartIndex; k<=l_ui32RangeEndIndex; k++)
{
for(uint32 j=l_ui32RangeStartIndex2; j<=l_ui32RangeEndIndex2; j++)
{
m_vChannelTable.push_back(k);
m_vChannelTable.push_back(j);
this->getLogManager() << LogLevel_Trace << " Selected channels [" << k+1 << ","<< j+1 <<"]\n";
std::cout<< "Selected channel [" << k+1 << ","<< j+1 << "]\n"<<std::endl;
}
}
l_bFound=true;
m_vLookup.push_back(l_ui32Index);
this->getLogManager() << LogLevel_Trace << "Selected channel [" << l_ui32Index+1 << "]\n";
}
}
//Case 2 : One channel and a range
if(!m_bRange1 && m_bRange2)
{
//First, identify the channel to compare to the range
uint32 l_ui32Index=uint32(-1);
// Looks for the channel with this name
l_ui32Index=::_find_channel_(*ip_pMatrix1, l_sChannel[chan], l_ui64MatchMethodIdentifier, l_ui32Index+1);
// Finds the first & second part of the range (only index based)
uint32 l_ui32RangeStartIndex=::_find_channel_(*ip_pMatrix1, l_sSubChannel[0], OVP_TypeId_MatchMethod_Index);
uint32 l_ui32RangeEndIndex=::_find_channel_(*ip_pMatrix1, l_sSubChannel[1], OVP_TypeId_MatchMethod_Index);
// When first or second part is not found but associated token is empty, don't consider this as an error
if(l_ui32RangeStartIndex==uint32(-1) && l_sSubChannel[0]==CString("")) l_ui32RangeStartIndex=0;
if(l_ui32RangeEndIndex ==uint32(-1) && l_sSubChannel[1]==CString("")) l_ui32RangeEndIndex=ip_pMatrix1->getDimensionSize(0)-1;
// After these corrections, if either first or second token were not found, or if start index is greater than start index, consider this an error and invalid range
if(l_ui32RangeStartIndex==uint32(-1) || l_ui32RangeEndIndex ==uint32(-1) || l_ui32RangeStartIndex>l_ui32RangeEndIndex)
{
this->getLogManager() << LogLevel_Warning << "Invalid channel range [" << l_sChannel[chan+1] << "] - splitted as [" << l_sSubChannel[0] << "][" << l_sSubChannel[1] << "]\n";
}
else
// When no channel was found, consider it a missing channel
if(!l_bFound)
{
// The range is valid so selects all the channels in this range
this->getLogManager() << LogLevel_Trace << "For range [" << l_sChannel[chan+1] << "] :\n";
for(uint32 k=l_ui32RangeStartIndex; k<=l_ui32RangeEndIndex; k++)
{
m_vChannelTable.push_back(l_ui32Index);
m_vChannelTable.push_back(k);
this->getLogManager() << LogLevel_Trace << " Selected channel [" << k+1 << "]\n";
std::cout<< "Selected channel [" << k+1 << "]\n"<<std::endl;
}
}
}
this->getLogManager() << LogLevel_Warning << "Invalid channel [" << l_sToken[j] << "]\n";
m_vLookup.push_back(uint32(-1));
// Case 3 : A range and one channel
if(m_bRange1 && !m_bRange2)
{
//First, identify the channel to compare to the range
uint32 l_ui32Index=uint32(-1);
// Looks for the channel with this name
l_ui32Index=::_find_channel_(*ip_pMatrix1, l_sChannel[chan+1], l_ui64MatchMethodIdentifier, l_ui32Index+1);
// Finds the first & second part of the range (only index based)
std::cout<<"size ="<<l_sSubChannel.size()<<std::endl;
uint32 l_ui32RangeStartIndex=::_find_channel_(*ip_pMatrix1, l_sSubChannel[0], OVP_TypeId_MatchMethod_Index);
uint32 l_ui32RangeEndIndex=::_find_channel_(*ip_pMatrix1, l_sSubChannel[1], OVP_TypeId_MatchMethod_Index);
}*/
// When first or second part is not found but associated token is empty, don't consider this as an error
if(l_ui32RangeStartIndex==uint32(-1) && l_sSubChannel[0]==CString("")) l_ui32RangeStartIndex=0;
if(l_ui32RangeEndIndex ==uint32(-1) && l_sSubChannel[1]==CString("")) l_ui32RangeEndIndex=ip_pMatrix1->getDimensionSize(0)-1;
// After these corrections, if either first or second token were not found, or if start index is greater than start index, consider this an error and invalid range
if(l_ui32RangeStartIndex==uint32(-1) || l_ui32RangeEndIndex ==uint32(-1) || l_ui32RangeStartIndex>l_ui32RangeEndIndex)
{
this->getLogManager() << LogLevel_Warning << "Invalid channel range [" << l_sChannel[chan+2] << "] - splitted as [" << l_sSubChannel[0] << "][" << l_sSubChannel[1] << "]\n";
}
else
this->getLogManager() << LogLevel_Trace << "For range [" << l_sChannel[chan] << "] :\n";
for(uint32 k=l_ui32RangeStartIndex; k<=l_ui32RangeEndIndex; k++)
{
// The range is valid so selects all the channels in this range
this->getLogManager() << LogLevel_Trace << "For range [" << l_sChannel[chan+2] << "] :\n";
for(uint32 k=l_ui32RangeStartIndex; k<=l_ui32RangeEndIndex; k++)
for(uint32 j=l_ui32RangeStartIndex2; j<=l_ui32RangeEndIndex2; j++)
{
m_vChannelTable.push_back(k);
m_vChannelTable.push_back(l_ui32Index);
this->getLogManager() << LogLevel_Trace << " Selected channel [" << k+1 << "]\n";
std::cout<< "Selected channel [" << k+1 << "]\n"<<std::endl;
}
}
}
//Case 4 : 2 channels
else
{
uint32 l_bFound=false;
uint32 l_ui32Index=uint32(-1);
uint32 l_ui32Index2=uint32(-1);
// Looks for all the channels with this name
// while((l_ui32Index=::_find_channel_(*ip_pMatrix1, l_sChannel[chan], l_ui64MatchMethodIdentifier, l_ui32Index+1))!=uint32(-1))
if((l_ui32Index=::_find_channel_(*ip_pMatrix1, l_sChannel[chan], l_ui64MatchMethodIdentifier, l_ui32Index+1))!=uint32(-1))
{
l_bFound=true;
m_vChannelTable.push_back(l_ui32Index);
this->getLogManager() << LogLevel_Trace << "Selected channel [" << l_ui32Index+1 << "]\n";
std::cout<< "Selected channel [" << l_ui32Index+1 << "]\n"<<std::endl;
}
m_vChannelTable.push_back(j);
// while((l_ui32Index2=::_find_channel_(*ip_pMatrix1, l_sChannel[chan+1], l_ui64MatchMethodIdentifier, l_ui32Index+1))!=uint32(-1))
if((l_ui32Index2=::_find_channel_(*ip_pMatrix1, l_sChannel[chan+1], l_ui64MatchMethodIdentifier, l_ui32Index2+1))!=uint32(-1))
{
l_bFound=true;
m_vChannelTable.push_back(l_ui32Index2);
this->getLogManager() << LogLevel_Trace << "Selected channel [" << l_ui32Index2+1 << "]\n";
std::cout<< "Selected channel [" << l_ui32Index2+1 << "]\n"<<std::endl;
}
this->getLogManager() << LogLevel_Info << " Selected channels [" << k+1 << ","<< j+1 <<"]\n";
//std::cout<< "Selected channel [" << k+1 << ","<< j+1 << "]\n"<<std::endl;
}
// When no channel was found, consider it a missing channel
if(!l_bFound)
{
this->getLogManager() << LogLevel_Warning << "Invalid channel [" << l_sPairs[pair] << "]\n";
m_vChannelTable.push_back(uint32(-1));
}
}
*/ }
}
}
// Parsing chain to identify channel name or index
......@@ -437,9 +297,6 @@ boolean CBoxAlgorithmConnectivityMeasure::process(void)
//cout<<"channel table"<<ip_pChannelTable->getBuffer()[cpt]<<endl;
}
// Start the initialization process
m_pConnectivityMethod->process(OVTK_Algorithm_Connectivity_InputTriggerId_Initialize);
// Make sure the algo initialization was successful
if(!m_pConnectivityMethod->process(OVTK_Algorithm_Connectivity_InputTriggerId_Initialize))
{
......@@ -447,8 +304,6 @@ boolean CBoxAlgorithmConnectivityMeasure::process(void)
return false;
}
// Pass the header to the next boxes, by encoding a header on the output 0:
m_oAlgo1_SignalEncoder.encodeHeader(0);
......
......@@ -21,7 +21,7 @@
namespace OpenViBEToolkit
{
class CConnectivityAlgorithm : public OpenViBEToolkit::TAlgorithm < OpenViBE::Plugins::IAlgorithm >
class OV_API CConnectivityAlgorithm : public OpenViBEToolkit::TAlgorithm < OpenViBE::Plugins::IAlgorithm >
{
public:
......@@ -43,7 +43,7 @@ namespace OpenViBEToolkit
OpenViBE::Kernel::TParameterHandler <OpenViBE::IMatrix*> op_pMatrix;
};
class CConnectivityAlgorithmDesc : public OpenViBE::Plugins::IAlgorithmDesc
class OV_API CConnectivityAlgorithmDesc : public OpenViBE::Plugins::IAlgorithmDesc
{
public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment