libxdf
0.92
A static C++ library for loading XDF files
|
#include <xdf.h>
Classes | |
class | Stream |
Public Types | |
typedef std::string | eventName |
Used as std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> > in eventMap. More... | |
typedef float | eventTimeStamp |
Used as std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> > in eventMap. More... | |
Public Member Functions | |
Xdf () | |
Default constructor with no parameter. More... | |
void | adjustTotalLength () |
Adjust totalLen to avoid possible deviation. More... | |
void | calcTotalLength (int sampleRate) |
Calculate the globle length (in samples). More... | |
void | createLabels () |
Create labels for each channel and store them in labels vector. More... | |
void | detrend () |
Subtract the entire channel by its mean. More... | |
void | freeUpTimeStamps () |
Delete the time stamps vectors when no longer needed to release some memory. More... | |
int | load_xdf (std::string filename) |
The main function of loading an XDF file. More... | |
void | resample (int userSrate) |
Resample all streams and channel to a chosen sample rate. More... | |
int | writeEventsToXDF (std::string file_path) |
writeEventsToXDF More... | |
Public Attributes | |
std::vector< Stream > | streams |
float | version |
uint64_t | totalLen = 0 |
float | minTS = 0 |
float | maxTS = 0 |
size_t | totalCh = 0 |
int | majSR = 0 |
int | maxSR = 0 |
std::vector< int > | streamMap |
std::vector< std::pair< std::pair< eventName, eventTimeStamp >, int > > | eventMap |
std::vector< std::string > | dictionary |
std::vector< uint16_t > | eventType |
std::vector< std::string > | labels |
std::set< double > | sampleRateMap |
std::vector< float > | offsets |
std::string | fileHeader |
int | userAddedStream { 0 } |
std::vector< std::pair< std::string, double > > | userCreatedEvents |
Xdf class is designed to store the data of an entire XDF file. It comes with methods to read XDF files and containers to store the data, as well as some additional methods e.g. resampling etc.
typedef std::string Xdf::eventName |
Used as std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> >
in eventMap.
typedef float Xdf::eventTimeStamp |
Used as std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> >
in eventMap.
Xdf::Xdf | ( | ) |
Default constructor with no parameter.
void Xdf::adjustTotalLength | ( | ) |
Adjust totalLen
to avoid possible deviation.
totalLen
is calculated by multiplying the difference between max time stamp and minimal time stamp by the majSR
(major sample rate). However, this can be inaccurate. In case any channel is longer than totalLen
, this function will make totalLen
match the length of that channel.
void Xdf::calcTotalLength | ( | int | sampleRate | ) |
Calculate the globle length (in samples).
This is calculated by multiplying the rage from the earliest time stamp to the last time stamp across all channels by the parameter sampleRate.
sampleRate | is the sample rate you wish to use to calculate the total length. |
void Xdf::createLabels | ( | ) |
void Xdf::detrend | ( | ) |
Subtract the entire channel by its mean.
Sigviewer displays both the channel signals as well as the zero baseline. Thus when the mean of a channel is too high or too low it would be very hard to see the fluctuation. Subtract the entire channel by its mean will make the signal fluctuate around the zero baseline, and has better visual effect. The mean of each channel times -1
will be stored in member vector offsets
void Xdf::freeUpTimeStamps | ( | ) |
Delete the time stamps vectors when no longer needed to release some memory.
Sigviewer doesn't demand time stamps to display signals except irregular sample rate channels, events, and the first time stamp of each channel (used to decide where does a channel start when putting all streams together). In this case we can delete the time stamps when no longer needed to free up some memory.
int Xdf::load_xdf | ( | std::string | filename | ) |
The main function of loading an XDF file.
filename | is the path to the file being loaded including the file name. |
void Xdf::resample | ( | int | userSrate | ) |
Resample all streams and channel to a chosen sample rate.
userSrate | is recommended to be between integer 1 and the highest sample rate of the current file. |
int Xdf::writeEventsToXDF | ( | std::string | file_path | ) |
writeEventsToXDF
If user added some markups and events in Sigviewer, this function can store those user created events back to the XDF file in a new stream
std::vector<std::string> Xdf::dictionary |
The vector to store unique event types with no repetitions.
std::vector<std::pair<std::pair<eventName, eventTimeStamp>, int> > Xdf::eventMap |
The vector to store all the events across all streams. The format is <<events, timestamps>, streamNum>.
std::vector<uint16_t> Xdf::eventType |
The vector to store events by their index in the dictionary.
std::string Xdf::fileHeader |
Raw XML of the file header.
std::vector<std::string> Xdf::labels |
The vector to store descriptive labels of each channel.
int Xdf::majSR = 0 |
The sample rate that has the most channels across all streams.
int Xdf::maxSR = 0 |
Highest sample rate across all streams.
float Xdf::maxTS = 0 |
The largest time stamp across all streams.
float Xdf::minTS = 0 |
The smallest time stamp across all streams.
std::vector<float> Xdf::offsets |
Offsets of each channel after using subtractMean() function
std::set<double> Xdf::sampleRateMap |
The vector to store all sample rates across all the streams.
std::vector<int> Xdf::streamMap |
A vector indexes which channels belong to which stream. The index is the same as channel number; the actual content is the stream Number
std::vector<Stream> Xdf::streams |
A vector to store all the streams of the current XDF file.
size_t Xdf::totalCh = 0 |
The total number of channel count.
uint64_t Xdf::totalLen = 0 |
The total length is the product of the range between the smallest time stamp and the largest multiplied by the major sample rate.
int Xdf::userAddedStream { 0 } |
For Sigviewer only: if user manually added events in Sigviewer, the events will be stored in a new stream after all current streams. The index will be userAddedStream.
std::vector<std::pair<std::string, double> > Xdf::userCreatedEvents |
User created events in Sigviewer.
float Xdf::version |
The version of XDF file