Skip to content

Instantly share code, notes, and snippets.

@erzk
Created December 18, 2016 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erzk/339d081c65ce4da4254c0bdbef760b20 to your computer and use it in GitHub Desktop.
Save erzk/339d081c65ce4da4254c0bdbef760b20 to your computer and use it in GitHub Desktop.
This script shows how to load and plot fnirs data (.nirs format)
# install the package if not available with:
# install.packages("R.matlab")
library(R.matlab)
# load the nirs file
data <- readMat("Simple_Probe.nirs")
# get the available names
names(data)
# format description:
# http://www.nmr.mgh.harvard.edu/martinos/software/homer/HOMER2_UsersGuide_121129.pdf#4
# find the dimensions of data: samples and channels
dim(data$d)
# number of channels
ncol(data$d)
# create a custom plotting function
myPlot <- function(y){
plot(data$t, y,
type = "l",
xlab = "Time", ylab = "Intensity",
ylim = c(range(data$d)),
main = paste("Channel ", toString(y)))
# add the lines when triggers occur
lines(data$t, data$s*1500, # multiply the trigger value to make it visible
type = "l", xlab = "Time", col = "red")
}
# apply the plotting function to all channels
apply(data$d[, 1:ncol(data$d)], 2, myPlot)
sessionInfo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment