# NOT RUN {
# Filter white noise
s1 = fade(c(runif(2000, -1, 1)))
bandpass(s1, 16000, upr = 2000, plot = TRUE) # low-pass
bandpass(s1, 16000, lwr = 2000, plot = TRUE) # high-pass
bandpass(s1, 16000, lwr = 1000, upr = 1100, action = 'stop', plot = TRUE) # bandstop
s2 = bandpass(s1, 16000, lwr = 2000, upr = 2100, plot = TRUE) # bandpass
# playme(rep(s2, 5))
spectrogram(s2, 16000) # more accurate than plotting the spectrum with plot = TRUE
# a short vector with some NAs
x = rnorm(150, 10) + 3 * sin((1:50) / 5)
x[sample(1:length(x), 50)] = NA
plot(x, type = 'l')
points(bandpass(x, samplingRate = 100, upr = 10), type = 'l', col = 'blue')
# }
# NOT RUN {
# precise notch filtering is possible, even in low frequencies
whiteNoise = runif(8000, -1, 1)
s3 = bandpass(whiteNoise, 16000, lwr = 30, upr = 40,
plot = TRUE, xlim = c(0, 500))
playme(rep(s3, 5))
spectrogram(s3, 16000, windowLength = 150, yScale = 'log')
# compare the same with STFT
s4 = seewave::ffilter(whiteNoise, f = 16000, from = 30, to = 40)
spectrogram(s4, 16000, windowLength = 150, yScale = 'log')
# (note: works better as wl approaches length(s4))
# high-pass all audio files in a folder
bandpass('~/Downloads/temp', saveAudio = '~/Downloads/temp/hp2000/',
lwr = 2000, savePlots = '~/Downloads/temp/hp2000/')
# }
Run the code above in your browser using DataLab