Created
February 23, 2018 07:13
-
-
Save agricolamz/950dce81a1fb2db1b4eb8d3b81c9e560 to your computer and use it in GitHub Desktop.
This file visualise multiple simple waves and their summation
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
library(tidyverse) | |
t <- seq(0,0.5, 0.001) | |
`500 Hz` <- sin(1*5*2*pi*t) | |
`1000 Hz` <- sin(2*5*2*pi*t) | |
`1500 Hz` <- sin(3*5*2*pi*t) | |
`2000 Hz` <- sin(4*5*2*pi*t) | |
`2500 Hz` <- sin(5*5*2*pi*t) | |
`500 + 500 Hz` <- sin(1*5*2*pi*t) + sin(1*5*2*pi*t) | |
`1000 + 500 Hz` <- sin(2*5*2*pi*t) + sin(1*5*2*pi*t) | |
`1500 + 500 Hz` <- sin(3*5*2*pi*t) + sin(1*5*2*pi*t) | |
`2000 + 500 Hz` <- sin(4*5*2*pi*t) + sin(1*5*2*pi*t) | |
`2500 + 500 Hz` <- sin(5*5*2*pi*t) + sin(1*5*2*pi*t) | |
df <- data_frame(t = rep(t, 10), | |
Freq = c(`500 Hz`, `1000 Hz`, `1500 Hz`,`2000 Hz`, `2500 Hz`, `500 + 500 Hz`,`1000 + 500 Hz`, `1500 + 500 Hz`,`2000 + 500 Hz`, `2500 + 500 Hz`), | |
freq = rep(c("500 Hz", "1000 Hz", "1500 Hz", "2000 Hz", "2500 Hz", "500 Hz", "1000 Hz", "1500 Hz", "2000 Hz", "2500 Hz"), each = 501), | |
second = rep(c("x", "x + 500 Hz"), each = 501*5)) | |
df %>% | |
mutate(freq = factor(freq, levels = c("500 Hz", "1000 Hz", "1500 Hz", "2000 Hz", "2500 Hz"))) %>% | |
ggplot(aes(t, Freq))+ | |
geom_line(data = data_frame(`500` = `500 Hz`, t), | |
aes(t, `500`), linetype = 2, size = 0.5)+ | |
geom_line()+ | |
facet_grid(second~freq, )+ | |
xlab("t (ms)")+ | |
theme_bw() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment