How to extract a specific frequency range from a .wav file?

I'm really really new to sound processing, so maybe my question would be trivial. I want to do in order to extract a certain frequency range (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 (from 150 up to 400 Hz or whatever).

I read something on the net, and I found that this can be done using FFT analysis, and there are problems here.

Suppose I have 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 

We get the following:

enter image description here

Well, there are two peaks. If we want to know at 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 

The first two values ​​are really close to the frequency that I used to create my sound:

  real computed Freq1: 440 | 441 Freq2: 880 | 881 

So now the problem is: how to continue if I want to remove frequencies from my sound in the range of, say, (1, 500) ? And how to select (and save) only the range (1, 500) ? What I visit is that my new sound (with removed frequencies) will be something close to a simple Sine(freq=880, duration=1) (I know it can't be exactly like that!). Is it possible?

I'm sure fft(DATA, inverse = TRUE) is what I need. But I’m not sure, but I don’t know how to act.

+4
source share
3 answers

I may have missed this point, but do you already have no answer? From your message:

 order(Mod(x)[1:22050], decreasing=T)[1:10] [1] 441 881 882 880 883 442 440 879 884 878 

Just collect all the 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 a new signal, simply repeat what you did to create 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) 

To save values ​​below 500:

 (junk3 <- junk[junk <= 500]) [1] 441 442 440 
+2
source

If you do not want to program it, you can use Praat.

Praat is a free scientific program for analyzing speech in phonetics. But you can also use it to edit the spectrum of any sound (delete frequencies, ...), and then export the result as a new sound file.

+3
source

look at the “signal” packet on the tap, one of the filter functions should do

0
source

All Articles