library(ggplot2)
## Warning in register(): Can't find generic `scale_type` in package ggplot2 to
## register S3 method.
#the following is from Jeff Doser’s webiste. I was reading it and playing around with the values.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
x <- seq(0, 2 * pi, .1)
standard <- sin(x)
altered <- 2*sin(3 * (x - 1)) + 4
graphData <- tibble(x, standard, altered)
ggplot(data = graphData, mapping = aes(x = x)) +
geom_point(mapping = aes(y = standard, color = "sin(x)")) +
geom_point(mapping = aes(y = altered, color = "2*sin(3 * (x - 1)) + 4")) +
scale_color_manual("", breaks = c("sin(x)", "2*sin(3 * (x - 1)) + 4"),
values = c("blue", "red")) +
labs(x = "x", y ="")
library(signal)
##
## Attaching package: 'signal'
## The following object is masked from 'package:dplyr':
##
## filter
## The following objects are masked from 'package:stats':
##
## filter, poly
t <- seq(0, 1, len = 100)
sig <- sin(2 * pi * t)
ggplot(mapping = aes(t, sig)) +
geom_line()
noisySig <- sin(2 * pi * t) + 0.25 * rnorm(length(t))
ggplot() +
geom_line(aes(t, noisySig), color = "red")
butterFilter <- butter(3, 0.1)
recoveredSig <- signal::filter(butterFilter, noisySig)
allSignals <- data.frame(t, sig, noisySig, recoveredSig)
ggplot(allSignals, aes(t)) +
geom_line(aes(y = sig, color = "Original")) +
geom_line(aes(y = noisySig, color = "Noisy")) +
geom_line(aes(y = recoveredSig, color = "Recovered")) +
labs(x = "Time", y = "Signal")
t <- 1:500
cleanSignal <- 50 * sin(t * 4 * pi/length(t))
noise <- 50 * 1/12 * sin(t * 4 * pi/length(t) * 12)
originalSignal <- cleanSignal + noise
ggplot() +
geom_line(aes(t, originalSignal))
lowButter <- butter(2, 1/50, type = "low")
low <- signal::filter(lowButter, originalSignal)
highButter <- butter(2, 1/25, type = "high")
high <- signal::filter(highButter, originalSignal)
signals <- data.frame(originalSignal, low, high)
ggplot(signals, aes(t)) +
geom_line(aes(y = originalSignal, color = "Original")) +
geom_line(aes(y = low, color = "Signal")) +
geom_line(aes(y = high, color = "Noise")) +
labs(x = "Time", y = "Signal")