Lab moderna: add p3

Change-Id: I33feba7f04f13e91bfddacfa04a3f5b2e4e1952a
diff --git a/quad12/labmoderna/p3/r/calibracio_na.r b/quad12/labmoderna/p3/r/calibracio_na.r
new file mode 100644
index 0000000..e86eda1
--- /dev/null
+++ b/quad12/labmoderna/p3/r/calibracio_na.r
@@ -0,0 +1,29 @@
+library(tikzDevice)
+
+table <- read.table('dades/calibracio_ra.txt', sep="\t", dec='.', header=TRUE)
+
+# Plot the data
+plotall <- function() {
+  plot(table$ChannelNumber, table$Impulses, type="l", col="#EEEEFF", xlab="Nombre de canal", ylab="Comptes")
+  lines(table$ChannelNumber, table$ImpulsesSmooth, type="l")
+
+  # Add arrows and text labels to the peaks
+  for (j in 1:nrow(peaks)) {
+    i <- peaks[j, 'indexes']
+    label <- peaks[j, 'labels']
+    arrows(table$ChannelNumber[i], table$ImpulsesSmooth[i]+3, table$ChannelNumber[i], table$ImpulsesSmooth[i]+0.1, length = 0.05, code = 1, col = "#514E7E")
+    text(table$ChannelNumber[i], table$ImpulsesSmooth[i]+4.6, paste0("Canal ", table$ChannelNumber[i], "\n", label), col = "#514E7E", cex = 0.75)
+  }
+}
+
+indexes <- c(1601, 2359, 3373) + 1
+labels <- c("\\textsuperscript{226}Ra", "\\textsuperscript{218}Po", "\\textsuperscript{214}Po")
+peaks <- data.frame(indexes, labels)
+
+pdf('output/calibracio_ra.pdf', width = 6, height = 5)
+plotall()
+dev.off()
+
+tikz('output/calibracio_ra.tex', width = 6, height = 5)
+plotall()
+dev.off()