Skip to content

Commit

Permalink
ensure sf is calculated in a packet with enough data
Browse files Browse the repository at this point in the history
  • Loading branch information
jhmigueles committed Jan 27, 2025
1 parent fa28ed9 commit 9ecaeba
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions R/readParmayMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ readParmayMatrix = function(bin_file, return = c("all", "sf", "dynrange")[1],
# Process timestamps and calculate sampling frequency
start_timestamps = apply(start_timestamp_raw, 1, function(x) readBin(x, "integer", size = 4, endian = "little"))
end_timestamps = apply(end_timestamp_raw, 1, function(x) readBin(x, "integer", size = 4, endian = "little"))
sf_acc_observed = acc_count / (end_timestamps - start_timestamps)
sf_acc_p1 = sf_acc_observed[1]
packets_dur_s = end_timestamps - start_timestamps
sf_acc_observed = acc_count / packets_dur_s
sf_acc_p1 = sf_acc_observed[which(packets_dur_s >= 60)[1]]
expected_sf = c(12.5, 25, 50, 100)
sf = expected_sf[which.min(abs(expected_sf - sf_acc_p1[1]))]
if (return == "sf") return(sf)
Expand Down

0 comments on commit 9ecaeba

Please sign in to comment.