-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaster_code.R
More file actions
106 lines (77 loc) · 2.13 KB
/
master_code.R
File metadata and controls
106 lines (77 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#====================================
#SOUND ANALYSIS OF ORGAN PIPES
#====================================
#Lin Yangchen
#December 2021
#for personal non-commercial use only
rm(list = ls())
#====================================
#user settings
#====================================
#desired sample rate (downsampled if applicable)
downsamprate <- 96000
#where to extract stationary tone from recording
#in seconds
timerange <- c(4, 8)
#cut off power spectra at which harmonic
hcutoff <- 26
#frequency cutoff for stacked spectra
stackfreqcut <- 15000
#frequency cutoff for spectral centroids
centfreqcut <- 20000
#no. of mel-frequency cepstral coefficients
#(including first one which will be discarded)
numcep <- 50
#frequency band (Hz on each side) for flutter detection
flutterband <- c(50,50)
#no. of top notes to exclude from tuning and voicing analysis
keycut <- 47
#where to extract attack transient from recording
#in seconds
attacktime <- c(0.6, 2)
#cut off attack spectrograms at which harmonic
ahcutoff <- 11
#Google Sheet url of pipe data
dataurl <- 'docs.google.com/spreadsheets/d/1K_NoHORpwFQEOORFi61MO-eH3Msx34ED_nw8zD5yqhg#gid=0'
#====================================
#load libraries
#====================================
install.packages(setdiff(c(
'tuneR'
, 'stringr'
, 'lattice'
, 'latticeExtra'
, 'fBasics'
, 'extrafont'
, 'gsheet'
)
, rownames(installed.packages())))
require(tuneR)
require(stringr)
require(lattice)
require(latticeExtra)
require(fBasics)
require(extrafont)
#font_import()
#loadfonts(device = 'pdf')
#fonts()
font <- 'Courier New'
#plot settings
mgp <- c(2,0.5,0)
tck <- 0.01
#====================================
#import morphometric and metallurgical data
#====================================
require(gsheet)
pipedata <- read.csv(text = gsheet2text(dataurl, format = 'csv'))
#====================================
#run analysis on each replicate folder (set) of recordings
#====================================
folders <- list.dirs(recursive = F)
for(folder in folders)
{
file.copy('analysis_code.R', folder, overwrite = T)
setwd(folder)
source('analysis_code.R')
setwd('..')
}