-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from project8/develop
Develop
- Loading branch information
Showing
60 changed files
with
2,465 additions
and
4,379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* LMCFIRHandlerCore.cc | ||
* | ||
* Created on: May 11, 2018 | ||
* Author: P. T. Surukuchi | ||
*/ | ||
|
||
#include "LMCConst.hh" | ||
#include "LMCFIRHandler.hh" | ||
|
||
#include "logger.hh" | ||
|
||
namespace locust | ||
{ | ||
LOGGER( lmclog, "FIRHandlerCore" ); | ||
|
||
FIRHandlerCore::FIRHandlerCore(): | ||
fNFIRBins(-99), | ||
fFIRResolution(1e-12), | ||
fNFIRSkips(1) | ||
{ | ||
} | ||
|
||
FIRHandlerCore::~FIRHandlerCore() | ||
{ | ||
} | ||
|
||
bool FIRHandlerCore::Configure(const scarab::param_node& aParam) | ||
{ | ||
return true; | ||
} | ||
|
||
bool FIRHandlerCore::ends_with(const std::string &str, const std::string &suffix) | ||
{ | ||
//copied from https://stackoverflow.com/a/20446239 | ||
return str.size() >= suffix.size() && | ||
str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; | ||
} | ||
|
||
bool FIRHandlerCore::ReadFIRFile() | ||
{ | ||
fNFIRBins=0; | ||
if(!ends_with(fFIRFilename,".txt")) | ||
{ | ||
LERROR(lmclog,"The FIR file should end in .txt"); | ||
return false; | ||
} | ||
double firIndex; | ||
double filterMagnitude; | ||
FILE *firFile; | ||
firFile=fopen(fFIRFilename.c_str(),"r"); | ||
//logic copied from /LMCPatchSignalGenerator.cc | ||
int count=0; | ||
while (!feof(firFile)){ | ||
fscanf(firFile,"%lf %lf",&firIndex,&filterMagnitude); | ||
if (count%fNFIRSkips==0) | ||
{ | ||
fFIRFilter.push_back(filterMagnitude); | ||
++fNFIRBins; | ||
} | ||
++count; | ||
} | ||
fclose(firFile); | ||
return true; | ||
} | ||
|
||
double FIRHandlerCore::ConvolveWithFIRFilter(std::deque<double> delayedVoltageBuffer) | ||
{ | ||
double convolution=0.0; | ||
if(fNFIRBins<=0){ | ||
LERROR(lmclog,"Number of bins in the filter should be positive"); | ||
} | ||
for(int i=0;i<fNFIRBins;++i) | ||
{ | ||
convolution+=fFIRFilter[i]*delayedVoltageBuffer[i]; | ||
} | ||
return convolution; | ||
} | ||
|
||
FIRTransmitterHandler::FIRTransmitterHandler():FIRHandlerCore() | ||
{ | ||
} | ||
|
||
FIRTransmitterHandler::~FIRTransmitterHandler() | ||
{ | ||
} | ||
|
||
bool FIRTransmitterHandler::Configure(const scarab::param_node& aParam) | ||
{ | ||
if( aParam.has( "fir-transmitter-filename" ) ) | ||
{ | ||
fFIRFilename=aParam["fir-transmitter-filename"]().as_string(); | ||
} | ||
if( aParam.has( "fir-transmitter-dt" ) ) | ||
{ | ||
fFIRResolution=aParam["fir-transmitter-dt"]().as_double(); | ||
} | ||
if( aParam.has( "fir-transmitter-nskips" ) ) | ||
{ | ||
fNFIRSkips=aParam["fir-transmitter-nskips"]().as_int(); | ||
} | ||
return true; | ||
} | ||
|
||
FIRReceiverHandler::FIRReceiverHandler():FIRHandlerCore() | ||
{ | ||
} | ||
|
||
FIRReceiverHandler::~FIRReceiverHandler() | ||
{ | ||
} | ||
|
||
bool FIRReceiverHandler::Configure(const scarab::param_node& aParam) | ||
{ | ||
if( aParam.has( "fir-receiver-filename" ) ) | ||
{ | ||
fFIRFilename=aParam["fir-receiver-filename"]().as_string(); | ||
} | ||
if( aParam.has( "fir-receiver-dt" ) ) | ||
{ | ||
fFIRResolution=aParam["fir-receiver-dt"]().as_double(); | ||
} | ||
if( aParam.has( "fir-receiver-nskips" ) ) | ||
{ | ||
fNFIRSkips=aParam["fir-receiver-nskips"]().as_int(); | ||
} | ||
return true; | ||
} | ||
|
||
} /* namespace locust */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#ifndef LMCFIRHANDLERCORE_HH_ | ||
#define LMCFIRHANDLERCORE_HH_ | ||
|
||
#include "LMCException.hh" | ||
#include "param.hh" | ||
|
||
namespace locust | ||
{ | ||
/*! | ||
@class FIRHandlerCore | ||
@author P. T. Surukuchi | ||
@brief Handles opening of the FIR files, saving them into objects to be used for convolution | ||
@details | ||
Available configuration options: | ||
- "fir-transmitter(receiver)-filename": string -- The location of the file containing impulse response | ||
- "fir-transmitter(receiver)-dt": double (1e-12) -- The size of filter sample width (seconds) | ||
- "fir-transmitter(receiver)-nskips": int (1) -- Number of skips to be peformed in reading from the FIR file, this will deteremine the number of FIR bins | ||
*/ | ||
|
||
class FIRHandlerCore | ||
{ | ||
public: | ||
FIRHandlerCore(); | ||
virtual ~FIRHandlerCore(); | ||
|
||
// Member functions | ||
virtual bool Configure( const scarab::param_node& aNode); | ||
bool ReadFIRFile(); | ||
double ConvolveWithFIRFilter(std::deque<double>);// Convolve input signal (voltage or field) with FIR | ||
int GetFilterSize() const;//Number of entries in the filter | ||
double GetFilterResolution() const;//Get the resolution of the filter | ||
|
||
protected: | ||
|
||
// Member variables | ||
std::string fFIRFilename; | ||
std::vector<double> fFIRFilter; | ||
int fNFIRBins; | ||
double fFIRResolution; | ||
int fNFIRSkips; | ||
// bool fIsTransmitter;//Ad-hoc definition of FIR filter type if true transmitter other-wise receiver | ||
|
||
//Member functions | ||
//Check weather the given input string ends with another string | ||
//PTS: Should be moved into a core class | ||
bool ends_with(const std::string &, const std::string &); | ||
}; | ||
|
||
inline int FIRHandlerCore::GetFilterSize() const | ||
{ | ||
return fNFIRBins; | ||
} | ||
|
||
inline double FIRHandlerCore::GetFilterResolution() const | ||
{ | ||
return fFIRResolution; | ||
} | ||
|
||
/*! | ||
@class FIRTransmitterHandler | ||
@author P. T. Surukuchi | ||
@brief Handles transmitter FIR, saving them into objects to be used for convolution | ||
@details | ||
Available configuration options: | ||
- "fir-transmitter-filename": string -- The location of the file containing impulse response function | ||
- "fir-transmitter-dt": double (1e-12) -- The size of filter sample width (seconds) | ||
- "fir-transmitter-nskips": int (1) -- Number of skips to be peformed in reading from the FIR file, this will deteremine the number of FIR bins | ||
*/ | ||
|
||
class FIRTransmitterHandler: public FIRHandlerCore | ||
{ | ||
public: | ||
FIRTransmitterHandler(); | ||
virtual ~FIRTransmitterHandler(); | ||
|
||
// Member functions | ||
bool Configure( const scarab::param_node& aNode); | ||
}; | ||
|
||
/*! | ||
@class FIRReceiverHandler | ||
@author P. T. Surukuchi | ||
@brief Handles receiver FIR, saving them into objects to be used for convolution | ||
@details | ||
Available configuration options: | ||
- "fir-transmitter-filename": string -- The location of the file containing impulse response function | ||
- "fir-transmitter-dt": double (1e-12) -- The size of filter sample width (seconds) | ||
- "fir-transmitter-nskips": int (1) -- Number of skips to be peformed in reading from the FIR file, this will deteremine the number of FIR bins | ||
*/ | ||
|
||
class FIRReceiverHandler: public FIRHandlerCore | ||
{ | ||
public: | ||
FIRReceiverHandler(); | ||
virtual ~FIRReceiverHandler(); | ||
|
||
// Member functions | ||
bool Configure( const scarab::param_node& aNode); | ||
}; | ||
|
||
} /*namespace locust*/ | ||
|
||
#endif/*LMCFIRHANDLERCORE_HH_ */ |
Oops, something went wrong.