공유자료 HOME > 자료실 > 공유자료
 
[정보기술활용연구] 음향분석, 유사한 음향찾기 R 코드
관리자 16-04-09 16:35 524
   박수.wav (62.5K) [24] DATE : 2016-04-09 16:35:23
install.packages("seewave")
install.packages("tuneR")
library(seewave)
library(tuneR)
sound <- readWave("박수.wav")
timer(sound, f=22050, threshold=5, msooth=c(50,0))  ## f 란 frequency를 뜻함
spec(sound, f=22050, dB="max0", col="blue")
oscillo(sound)
## 음악(소리) 듣기
playlist("MyMusic", sample = TRUE, loop=2)
## 두 임의의 소리와의 유사도 계산하기1
## Cross-correlation between two time wave envelopes
data(orni)
# cross-correlation between two echemes of a cicada song
wave1<-cutw(orni,f=22050,from=0.3,to=0.4,plot=FALSE)
wave2<-cutw(orni,f=22050,from=0.58,to=0.68,plot=FALSE)
corenv(wave1,wave2,f=22050)
## 두 임의의 소리와의 유사도 계산하기2
## Cross-correlation between two frequency spectra
data(tico)
## compare the two first notes spectra
a<-spec(tico,f=22050,wl=512,at=0.2,plot=FALSE)
c<-spec(tico,f=22050,wl=512,at=1.1,plot=FALSE)
op<-par(mfrow=c(2,1), mar=c(4.5,4,3,1))
spec(tico,f=22050,at=0.2,col="blue")
par(new=TRUE)
spec(tico,f=22050,at=1.1,col="green")
legend(x=8,y=0.5,c("Note A", "Note C"),lty=1,col=c("blue","green"),bty="o")
par(mar=c(5,4,2,1))
corspec(a,c, ylim=c(-0.25,0.8),xaxs="i",yaxs="i",las=1)
par(op)
## different correlation methods give different results...
op<-par(mfrow=c(3,1))
corspec(a,c,xaxs="i",las=1, ylim=c(-0.25,0.8))
title("spearmann correlation (by default)")
corspec(a,c,xaxs="i",las=1,ylim=c(0,1),method="pearson")
title("pearson correlation")
corspec(a,c,xaxs="i",las=1,ylim=c(-0.23,0.5),method="kendall")
title("kendall correlation")
par(op)
## inverting x and y does not give exactly similar results
op<-par(mfrow=c(2,1),mar=c(2,4,3,1))
corspec(a,c)
corspec(c,a)
par(op)
## mel scale
require(tuneR)
data(orni)
orni.mel <- melfcc(orni, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE)
orni.mel.mean <- apply(orni.mel$aspectrum, MARGIN=2, FUN=mean)
tico.mel <- melfcc(tico, nbands = 256, dcttype = "t3", fbtype = "htkmel", spec_out=TRUE)
tico.mel.mean <- apply(tico.mel$aspectrum, MARGIN=2, FUN=mean)
corspec(orni.mel.mean, tico.mel.mean, f=22050, mel=TRUE, plot=TRUE)
all <- cbind(tico[1:31000,2], onri[1:31000,2])
matplot(x=tico[1:31000,1], y=all, yaxt="n", xlab="Frequency (kHz)", ylab="Amplitude", xaxs="o", type="l")