Created
December 18, 2016 23:44
-
-
Save erzk/0d01ca79c7737edb470860176437e0e1 to your computer and use it in GitHub Desktop.
RMarkdown file showing the nirs data analysis
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
--- | |
title: "Loading and plotting nirs data" | |
author: "Eryk Walczak" | |
date: "18 December 2016" | |
output: | |
html_document: default | |
pdf_document: default | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE) | |
``` | |
## Loading | |
Install the necessary packages if not available: | |
```{r} | |
# install.packages("R.matlab") | |
library(R.matlab) | |
``` | |
Load the nirs file | |
```{r} | |
data <- readMat("Simple_Probe.nirs") | |
``` | |
Nirs format description is available [here](http://www.nmr.mgh.harvard.edu/martinos/software/homer/HOMER2_UsersGuide_121129.pdf#4) | |
## Exploring | |
Get the available variable names | |
```{r} | |
names(data) | |
``` | |
Find the dimensions of data: samples and channels | |
```{r} | |
dim(data$d) | |
# number of channels | |
ncol(data$d) | |
``` | |
## Plotting | |
Create a custom plotting function | |
```{r} | |
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 | |
```{r} | |
apply(data$d[, 1:ncol(data$d)], 2, myPlot) | |
``` | |
Session info: | |
```{r} | |
sessionInfo() | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment