# NOT RUN {
#Create a vector of time that represent times where data are sampled.
Fs = 100; #sampling frequency in Hz
T = 1/Fs; #sampling period
L = 1000; #length of time vector
t = (0:(L-1))*T; #time vector
#First signal
#1. 1 Hz with amplitude of 4
S1 <- 4*sin(2*pi*1*t)
S1.data.frame <- as.data.frame(cbind(t, S1))
colnames(S1.data.frame) <- c("Time", "Signal")
#Second signal
#1. 1 Hz with amplitude of -2
#2. 2 Hz with amplitude of -2
S2 <- (-2)*sin(2*pi*1*t) - 2*sin(2*pi*2*t);
S2.data.frame <- as.data.frame(cbind(t, S2))
colnames(S2.data.frame) <- c("Time", "Signal")
#Third signal
#1. 1 Hz with amplitude of 2
#2. 2 Hz with amplitude of 2
S3 <- 2*sin(2*pi*1*t) + 2*sin(2*pi*2*t);
S3.data.frame <- as.data.frame(cbind(t, S3))
colnames(S3.data.frame) <- c("Time", "Signal")
#Add all signals to a List
list.of.windows <- list(S1.data.frame, S2.data.frame, S3.data.frame)
results <- MakeCompositeXYPlotForAllWindows(list.of.windows, "Signal", 0, 999, 1)
x.values <- results[[1]]
y.values <- results[[2]]
stddev.y.values <- results[[3]]
#plot each xy plot individually
#dev.new()
plot(t, S1, ylim = c(-5, 5), type = "l")
lines(t, S2, col="blue")
lines(t, S3, col="green")
#plot the averaged plot
#The only curve remaining should be the 1Hz with amplitude of 4/3.
#dev.new()
plot(x.values, y.values, type = "l")
#plot averaged plot with error bars
#dev.new()
plot(x.values, y.values, type = "l")
#Add error bars
arrows(x.values, y.values, x.values, y.values + stddev.y.values, length=0.05, angle=90)
arrows(x.values, y.values, x.values, y.values - stddev.y.values, length=0.05, angle=90)
# }
Run the code above in your browser using DataLab