1 Preliminaries

1.1 General setup

Follow the setup instructions given here, i.e. download R and RStudio, create a directory on your computer where you will store files on this course, make a note of the directory path, create an R project that accesses this directory, and install all indicated packages.

For this and subsequent tutorials, access the tidyverse,magrittr, emuR, and wrassp libraries:

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(magrittr)
## 
## Attaching package: 'magrittr'
## 
## The following object is masked from 'package:purrr':
## 
##     set_names
## 
## The following object is masked from 'package:tidyr':
## 
##     extract
library(emuR)
## 
## Attaching package: 'emuR'
## 
## The following object is masked from 'package:base':
## 
##     norm
library(wrassp)
sourceDir = "./testsample"
targetDir = "./emu_databases"

1.2 Download and unzip

a = "https://www.phonetik.uni-muenchen.de/~jmh/"
b = "lehre/Rdf/kiel_butter1.zip"
down_path = paste(a, b, sep="/")
download.file(down_path, 
              file.path(sourceDir, "kiel_butter1.zip"))
# Create directory in sourceDir called 'butter'
dir.create(file.path(sourceDir, "butter"))
# unzip the file into that directory
unzip(file.path(sourceDir, "kiel_butter1.zip"), 
      exdir = file.path(sourceDir, "butter"))

1.3 Convert the collection and create Emu database

path.butter = file.path(sourceDir, "butter")
list.files(path.butter)
convert_TextGridCollection(path.butter, 
                           dbName = "butter",
                           targetDir = targetDir)

Create the Emu database

butter_DB = 
  load_emuDB(file.path(targetDir, "butter_emuDB"))

1.4 Analysis

Identify [s, S] segments

fric.s = query(butter_DB, "Phonetic = s|S")

Calculate ZCR on the fly

fric.zcr = 
  get_trackdata(butter_DB, fric.s, 
                onTheFlyFunctionName = "zcrana")

First plot

fric.zcr %>% 
  ggplot +
  aes(y = T1, x = times_norm, col=labels, group=sl_rowIdx) +
  geom_line()

Normalise length

fric.zcr.norm = normalize_length(fric.zcr, N = 11)

Prepare data for an aggregate plot

fric.zcr.norm.m = 
  fric.zcr.norm %>%
  group_by(times_norm, labels) %>%
  summarise(T1 = mean(T1)) %>% ungroup
## `summarise()` has grouped output by 'times_norm'. You can override using the
## `.groups` argument.

Aggregate normalised time plot

fric.zcr.norm.m %>%
  ggplot +
  aes(y = T1, x = times_norm, col=labels, group=labels) +
  geom_line() +
  ylab("Zero-crossing-rate (Hz)")+
  xlab("Proportional time")