Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #<number_id>_<tone>_<rhymetype>_<trialNumber>
  2. setwd("~/Desktop/Falam Recordings/PitchTier")
  3. #this removes thigns frm rg\ightside thingy
  4. rm(list=ls())
  5.  
  6. library(rPraat)
  7. library(reshape2)
  8. library(dplyr)
  9. library(dygraphs)
  10. library(tuneR)
  11. ptFiles <- dir(pattern = "*.PitchTier")
  12. numFiles <- length(ptFiles)
  13. numSamples <- 100
  14.  
  15. f0Contour <- matrix(numeric(numSamples*numFiles), ncol = numSamples)
  16.  
  17.  
  18. for(fIdx in 1:numFiles) {
  19.  
  20. pitchData <- pt.read(ptFiles[fIdx])
  21. numTimeObs <- length(pitchData$t)
  22. timeVecInterp <- seq(pitchData$t[1], pitchData$t[numTimeObs], length = numSamples)
  23. f0Contour[fIdx, ] <- approx(pitchData$t, pitchData$f, timeVecInterp)$y
  24. }
  25.  
  26.  
  27. id <- as.factor(regmatches(ptFiles, regexpr("^\\d*(?=\\_)", ptFiles, perl = TRUE)))
  28. wordType <- as.factor(regmatches(ptFiles, regexpr("[A-Za-z]+(?=_[012].PitchTier$)", ptFiles, perl = TRUE)))
  29. tone <- as.factor(regmatches(ptFiles, regexpr("(?<=\\d\\_)(rising|falling|high|low)", ptFiles, perl = TRUE)))
  30. trialNum <- as.factor(regmatches(ptFiles, regexpr("[0123].PitchTier$", ptFiles, perl = TRUE)))
  31.  
  32.  
  33.  
  34. dfMaster <- data.frame(id, wordType, trialNum, tone, f0Contour)
  35. dfMelt <- melt(dfMaster, id.vars = c("id", "wordType", "trialNum", "tone"))
  36.  
  37. library(mgcv)
  38. dfMelt$time <- as.numeric(dfMelt$variable)
  39. fit <- bam(value ~ tone +
  40. s(time, by = tone, bs = "cr"), data = dfMelt, method = "fREML")
  41.  
  42. library(itsadug)
  43. plot_smooth(fit, view= "time" , plot_all = c("tone") , rug = F)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement