lfs(linear frequency shift) function on a wav file using R

Viewed 51

I'm trying to use lfs(linear frequency shift) function on a wav file I recorded using R. Here is the code I ran, and features of my wav file.

 library(tuneR) 
 library(MASS) 
 library(seewave) 
 setwd("C:/Users/Minkyung/Desktop/Call made") 

 bull <- readWave("croak_origin_bpf.wav") 

 #STDFT matrix 

 f <- bull@samp.rate ; wl <- 8192; ovlp <- 50; wn <- "rectagle" 
 data <- spectro(bull, wl=wl, ovlp=ovlp, wn=wn, 
 plot=FALSE, norm=FALSE, dB=NULL, complex=TRUE) 

 LF.croak <- lfs(bull, shift=-25, output="Wave") 
 HF.croak <- lfs(bull, shift=+75, output="Wave") 

 writeWave(object=normalize(MF.croak, unit="16"), 
 filename="LF.croak_origin_bpf.wav") 
 writeWave(object=normalize(HF.croak, unit="16"), 
 filename="HF.croak_origin_bpf.wav") 


#> bull
#> Wave Object
#> Number of Samples:      44272
#> Duration (seconds):     1
#> Samplingrate (Hertz):   44100
#> Channels (Mono/Stereo): Mono
#> PCM (integer format):   TRUE
#> Bit (8/16/24/32/64):    16

When I run this code, there's an error for lower shifting function.

LF.croak <- lfs(bull, shift=-25, output="Wave")
> Error in lfs(bull, shift = -25, output = "Wave") :
> 'shift' value cannot be less than the frequency resolution (f/wl)

I realize the frequency resolution cannot be under 0, but in that case is it impossible to use lfs function as a way to lower the frequencies? But in some examples I do find lowering frequencies are possible. Any ideas?

1 Answers

The error message shows that the frequency shift cannot be less than the frequency resolution of the short term Fourier transform. In this case, f is 44100 and wl is 1024 - the default - so the frequency resolution is 43.07 Hz. If you call lfs with a larger wl, such as 2048, this will reduce the frequency resolution to 21.53 so the call using 25 should work.

LF.croak <- lfs(bull, shift=-25, wl=2048, output="Wave") 

I don't have your data so I can't test it.

Related