library("R.matlab") library("signal") library("tuneR") library("ggplot2") source("defines.R") source("frequency_response_functions.R") # setWavPlayer("audacious") # Linux (needs audacious) speech <- R.matlab::readMat("speech.mat") x <- as.numeric(speech[["x"]]) h1 <- as.numeric(speech[["h1"]]) h2 <- as.numeric(speech[["h2"]]) y1 = as.numeric(filter(h1,1,x)) y2 = as.numeric(filter(h2,1,x)) n <- 1:length(x) ggplot() + geom_line(aes(x=n, y=x, color="x"), size = 1) + geom_line(aes(x=n, y=y1, color="y1"), size = 1) + geom_line(aes(x=n, y=y2, color="y2"), size = 1) + scale_colour_manual(values = c("x" = "blue", "y1" = "red", "y2" = "black")) + labs(title = "Sound Signals", color="Sounds") + plot_style ws = seq(-pi, pi, by=0.01) H1 <- frequencyResponseExp(h1, ws) H2 <- frequencyResponseExp(h2, ws) nh1 <- 1:length(h1) ggplot() + geom_segment(aes(x=nh1,y=h1,xend=nh1,yend=h1-h1)) + geom_point(aes(x=nh1,y=h1),size=3) + labs(title = "h1", x="", y="") + plot_style nh2 <- 1:length(h2) ggplot() + geom_segment(aes(x=nh2,y=h2,xend=nh1,yend=h2-h2)) + geom_point(aes(x=nh2,y=h2),size=3) + labs(title = "h2", x="", y="") + plot_style ggplot() + geom_line(aes(x=ws, y=H1, color="H1"), size = 1) + geom_line(aes(x=ws, y=H2, color="H2"), size = 1) + scale_colour_manual(values = c("H1" = "blue", "H2" = "red")) + labs(title = "Frequency Responses", x="", y="", color="Frequency Responses") + plot_style play(Wave(x, samp.rate = 8000)) play(Wave(y1, samp.rate = 8000)) play(Wave(y2, samp.rate = 8000)) play(Wave(y1+y2, samp.rate = 8000))