Posted at

Rでfft

More than 3 years have passed since last update.


概要

Rでfftやってみた。


写真


サンプルコード

par(mfrow = c(2, 1))

samplingFreq <- 1200
x <- seq(0, 2 * pi, 1 / samplingFreq)
y <- sin(2 * pi * 440 * x)
plot(x, y, "l")
s <- samplingFreq / 2
h <- c(seq(0, s, length.out = length(y) / 2), seq(-s, 0, length.out = length(y) / 2))
f <- fft(y)
m <- Mod(f)
FFTdata <- cbind(h, m)
plot(FFTdata[1:nrow(FFTdata) / 2, ], t = "l", pch = 20, lwd = 2, cex = 0.8, main = "440hz", xlab = "f(Hz)", ylab = "p")