问题描述
我的真的新的无害化处理,所以也许我的问题将是微不足道的。
我想要做的是提取特定频率范围(比方说150-400赫兹)从一个wav文件,使用R.换句话说,我要创建另一个波形文件(WAVE2)只包含的频率成分,我指定(150〜400赫兹,或者还有什么)。
I'm really new on sound processing, so maybe my question will be trivial.What I want to do is to extract a specific frequency range (let's say 150-400 Hz) from a wav file, using R. In other words, I want to create another wave file (wave2) that contains only the frequency component that I specify (150 to 400 Hz, or what else).
我看了网上的东西,我发现了,这可以用FFT分析来完成,而这里的来的问题。
I read something on the net, and I discovered out that this can be done with a FFT analysis, and here's come the problems.
假设我在这篇code:
Suppose I've this code:
library(sound)
s1 <- Sine(440, 1)
s2 <- Sine(880, 1)
s3 <- s1 + s2
s3.s <- as.vector(s3$sound)
# s3.s is now a vector, with length 44100;
# bitrate is 44100 (by default)
# so total time of s3 is 1sec.
# now I calculate frequencies
N <- length(s3.s) # 44100
k <- c(0:(N-1))
Fs <- 44100 # sampling rate
T <- N / Fs
freq <- k / T
x <- fft(s3.s) / N
plot(freq[1:22050], x[1:22050], type="l") # we need just the first half of FFT computation
我们得到的情节是:
The plot we obtain is:
那么,有两个峰值。如果我们想知道它们对应什么频率,只要找到:
Well, there are two peaks. If we want to know to what frequency they correspond, just find:
order(Mod(x)[1:22050], decreasing=T)[1:10]
[1] 441 881 882 880 883 442 440 879 884 878
前两个值是真正接近的频率,我用来创建我的声音:
First two values are really near to the frequency I've used to create my sound:
real computed
Freq1: 440 | 441
Freq2: 880 | 881
所以,现在问题来了:如何进行,如果我想从我的声音范围中删除的频率,比如(1,500)
?以及如何选择(并保存)只有范围(1,500)
?
我顾不上什么,是我的新的声音(与删除的频率)将接近到简单的事正弦(频率= 880,持续时间= 1)
(我知道,它不能是酷似如此!)。
那可能吗?
So, now comes the problem: how to proceed, if I want to delete from my sound the frequencies in the range, say, (1, 500)
? And how to select (and save) only the range (1, 500)
?What I attend, is that my new sound (with deleted frequencies) will be something near to simple Sine(freq=880, duration=1)
(I know, it cannot be exactly like so!).Is that possible?
我是pretty确保 FFT(DATA,逆= TRUE)
正是我需要的。但我不知道,但和我不知道如何着手。
I'm pretty sure that fft(DATA, inverse = TRUE)
is what I need. But I'm not sure, and however I don't know how to proceed.
推荐答案
也许我忽略了一点,但不要你已经有答案?从您的文章:
Maybe I missed the point, but don't you already have your answer? From your post:
order(Mod(x)[1:22050], decreasing=T)[1:10]
[1] 441 881 882 880 883 442 440 879 884 878
只要收集超过500的所有值:
Simply collect all values above 500:
junk <- order(Mod(x)[1:22050], decreasing=T)[1:10]
(junk1 <- junk[junk > 500])
[1] 881 882 880 883 879 884 878
要生成新的信号简单地重复你做了什么来构建原始信号:
To generate the new signal simply repeat what you did to build the original signal:
junk2 <- Sine(0, 1)
for (i in 1:length(junk1)) {
junk2 <- junk2 + Sine(junk1[i], 1)
}
junk2.s <- as.vector(junk2$sound)
要保持低于500的值:
To keep the values below 500:
(junk3 <- junk[junk <= 500])
[1] 441 442 440
这篇关于如何提取.wav文件特定频率范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!