-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuneR_strokes_vs_radiohead_vs_bob.R
111 lines (80 loc) · 2.49 KB
/
tuneR_strokes_vs_radiohead_vs_bob.R
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
library(tuneR)
setwd("C:/Users/Elvis/Dropbox/CAS_Statistical_Modelling/Musik/")
Songs<-list.files("Radiohead - In Rainbows (2007) 320kbps/")
i<-1
test=readMP3(paste("Radiohead - In Rainbows (2007) 320kbps/",Songs[i],sep=""))
par(mfrow=c(1,3))
plot(test,main=Songs[i])
par(mfrow=c(1,2))
hist(test@left, main = paste(Songs[i],"left"))
hist(test@right, main = paste(Songs[i],"right"))
library(tuneR)
Songs<-list.files("Radiohead - In Rainbows (2007) 320kbps/")
m1<-matrix(nrow = length(Songs),ncol=102)
for (i in 1:length(Songs))
{
test=readMP3(paste("Radiohead - In Rainbows (2007) 320kbps/",Songs[i],sep=""))
m1[i,]=c(quantile(test@left,probs = seq(0,1,0.02)),quantile(test@right,probs = seq(0,1,0.02)))
print(i)
}
row.names(m1)<-Songs
Songs<-list.files("The_Strokes_Discography/The_Strokes_Is_This_It/")
m2<-matrix(nrow = length(Songs),ncol=102)
for (i in 1:length(Songs))
{
test=readMP3(paste("The_Strokes_Discography/The_Strokes_Is_This_It/",Songs[i],sep=""))
m2[i,]=c(quantile(test@left,probs = seq(0,1,0.02)),quantile(test@right,probs = seq(0,1,0.02)))
print(i)
}
row.names(m2)<-Songs
Songs<-list.files("Bob Marley & The Wailers - Exodus/")
m3<-matrix(nrow = length(Songs),ncol=102)
for (i in 1:length(Songs))
{
test=readMP3(paste("Bob Marley & The Wailers - Exodus/",Songs[i],sep=""))
m3[i,]=c(quantile(test@left,probs = seq(0,1,0.02)),quantile(test@right,probs = seq(0,1,0.02)))
print(i)
}
row.names(m3)<-Songs
data<-rbind(m1,m2,m3)
library(dendextend)
plot(hclust(dist(data),method ="ward.D2"))
dend <- as.dendrogram(hclust(dist(data),method ="ward.D2"))
farbe<-NA
for (i in 1:(dim(data)[2]))
{
if(sum(labels(dend)[i]==row.names(m1))!=0)
{
farbe[i]<-1
}
if(sum(labels(dend)[i]==row.names(m2))!=0)
{
farbe[i]<-2
}
if(sum(labels(dend)[i]==row.names(m3))!=0)
{
farbe[i]<-3
}
}
palette(c("red","blue","black"))
labels_colors(dend) <- farbe
par(mar=c(c(13, 4, 4, 2)))
plot(dend,main="Radiohead vs. Strokes vs. Bob Marley")
png(filename = "dendro_strokes_radiohead_bob.png")
labels_colors(dend) <- farbe
par(mar=c(c(13, 4, 4, 2)))
plot(dend,main="Radiohead vs. Strokes vs. Bob Marley")
dev.off()
#PCA test
png(filename = "pca_T_and_F.png")
par(mfrow=c(1,2))
farbe<-c(rep(1,nrow(m1)),rep(2,nrow(m2)),rep(3,nrow(m3)))
pca<-prcomp(data,scale. = F)
summary(pca)
pca.p<-predict(pca)
plot(pca.p[,1],pca.p[,2],col=farbe,pch=16,main="PCA no norm")
pca<-prcomp(data,scale. = T)
summary(pca)
pca.p<-predict(pca)
plot(pca.p[,1],pca.p[,2],col=farbe,pch=16,main="PCA norm")
dev.off()