Skip to content

Commit

Permalink
Update sample rate computation
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed Dec 13, 2022
1 parent 3bc9b4e commit 0756f09
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Source/FileSource/NWBFileSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,30 @@ void NWBFileSource::fillRecordInfo()
attr = data.openAttribute("conversion");
attr.read(PredType::NATIVE_FLOAT, &bitVolts);

//Compute sample rate from first few timestamps
data = dataSource.openDataSet("timestamps");

dSpace = data.getSpace();
dSpace.getSimpleExtentDims(dims);
info.sampleRate = -1.0f;

HeapBlock<double> tsArray(dims[0]);
data.read(tsArray.getData(), PredType::NATIVE_DOUBLE);
if (data.attrExists("interval"))
{
attr = data.openAttribute("interval");
double interval;
attr.read(PredType::NATIVE_DOUBLE, &interval);
double sampleRate = 1.0f / interval;

info.sampleRate = 2 / (tsArray[2] - tsArray[0]);
info.sampleRate = sampleRate;
}
else
{
dSpace = data.getSpace();
dSpace.getSimpleExtentDims(dims);

HeapBlock<double> tsArray(dims[0]);
data.read(tsArray.getData(), PredType::NATIVE_DOUBLE);

if (tsArray[2] > 0 && tsArray[0] > 0)
info.sampleRate = 2 / (tsArray[2] - tsArray[0]);
}

//Get the first sample number to align events
data = dataSource.openDataSet("sync");
Expand Down

0 comments on commit 0756f09

Please sign in to comment.