install.packages("gridExtra")
install.packages("devtools")
devtools::install_github("IPS-LMU/emuR")

path2ae = file.path(mypath, "emuR_demoData", "ae_emuDB")
# load database
ae = load_emuDB(path2ae, verbose = F)
list_ssffTrackDefinitions(ae) #has dft

add_ssffTrackDefinition(ae,"dft",onTheFlyFunctionName = dftSpectrum)

sS.sl = query(ae, "[Phonetic==s|S]")

sS.dft = get_trackdata(ae, sS.sl, "dft", resultType = "tibble",cut=0.5) 

View(sS.dft)

sS.dft.long = convert_wideToLong(sS.dft,calcFreqs = TRUE)

View(sS.dft.long)

ggplot(sS.dft.long)+
  aes(x=freq,y=track_value)+
  geom_line() +
  facet_wrap(~sl_rowIdx+labels)

sS.dft.long.mean = sS.dft.long %>%
  group_by(labels,freq) %>%
  summarise(track_value=mean(track_value))

ggplot(sS.dft.long.mean)+
  aes(x=freq,y=track_value,col=labels)+
  geom_line()

sS.dft.long.mean[sS.dft.long.mean$freq>2000 & sS.dft.long.mean$freq<3000,]

sS.dft.2000to3000 = sS.dft.long %>%
  filter(freq>2000 & freq <3000) %>%
  group_by(labels,sl_rowIdx) %>%
  summarise(track_value=mean(track_value))

ggplot(sS.dft.2000to3000) +
  aes(x=labels,y=track_value)+
  geom_boxplot()


