I am trying to use R to find the Harmonics within a sound file, I would also like to plot these findings as a Frequency(Hz)(x) Strength(y) graph to show the harmonics found. I've found it hard so far to find a helpful, working example of FFT being used on an audio file in R as most of the tutorials work with a premade cosine or sine wave.
I have found an example on the https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/fft page under community code, but it did not work very well when I attempted to use it on the audio file.
#my addition (I've left the wave file space empty deliberately)
voice <- readWave("",from=0, to=Inf, units=c("seconds"), header=FALSE, toWaveMC=NULL)
#the community code
x <- wavobj@left
fs <- [email protected]
nbits <- wavobj@bit
x <- x[1:(fs*5)]
y <- fft(x)
y.tmp <- Mod(y)
y.tmp <- Mod(y)
y.ampspec <- y.tmp[1:(length(y)/2+1)]
y.ampspec[2:(length(y)/2)] <- y.ampspec[2:(length(y)/2)] * 2
f <- seq(from=0, to=fs/2, length=length(y)/2+1)
plot(f, y.ampspec, type="h", xlab="Frequency (Hz)", ylab="Amplitude Spectrum", xlim=c(0, 350))
Please send some help!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…