library(tuneR)
# sample rate of the sound in Hz
# must be at least twice the highest frequency
<- 50e3
sample_rate # duration of the sound in seconds
<- 5
duration # lowest and highest frequency in the sound
<- c(1e3, 21e3)
sound_freq_range # number of steps between the lowest and higest frequency
<- 40
sound_freq_steps # time
<- seq(0, duration - 1 / sample_rate, by = 1 / sample_rate)
t # vector of frequencies
<- seq(
sound_freq 1], sound_freq_range[2], length = sound_freq_steps
sound_freq_range[
)# stretch the frequency vector to 1 second
<- rep(sound_freq, each = sample_rate / sound_freq_steps)
sound_freq # amplitude of the sound
<- (2^15 - 1) * sin(2 * pi * sound_freq * t)
u # create Wave object
<- Wave(u, samp.rate = sample_rate, bit = 16)
w # save Wave object to wav file
writeWave(w, "media/test.wav")
Recently René Janssen from Bionet Natuuronderzoek was looking for an automatic bat-detector which could record sounds starting from 4 kHz. That was an incentive to put the Peersonic RPA2 to the test.
Generating a test sound
For this test I needed a file with known frequencies over a given range. It turns out that creating such a test file is relatively easy with R.
Play and record the test sound
Now I have a file test.wav which has sounds ranging from 1kHz up to 21kHz. I played this file using Audacity on a Ubuntu laptop. The laptop speakers failed to play sounds above 15 kHz, so I tried my Philips SHB9850NC headphones. Some testing revealable that I was able to hear sounds up to 22,5 kHz. I’m not sure whether the headphones, my ears or both failed at higher frequencies ;-) So I placed the headphones over the Peersonic RPA2 as show in the photo. Then the Peersonic was set in
auto record
mode with a threshold of -30dB
and a maximum file length of 20
seconds. The volume on the laptop was set about half way. Then I played the test file several times.
Comparison of the original test file and the recording
Let’s first look at the spectrogram of the test file. Again, something which it not that hard with R
<- readWave("media/test.wav")@left
truth library(signal)
<- 1024
window_n <- specgram(
truth_spec x = truth, n = window_n, Fs = sample_rate, overlap = ceiling(0.9 * window_n)
)plot(truth_spec, col = rainbow(10))
Then do the same thing with the file recording.wav as recorded by the Peersonic RPA2. The Peersonic RPA2 records multiple of 5 seconds, hence the silence a the end. Note that the test file did not contain frequencies above 21kHz. The noise around 32kHz is probably due to the fan of my laptop.
<- readWave("media/recording.wav", to = 5 * 384e3)
recording <- 1024
window_n <- specgram(
record_spec x = recording@left, n = window_n, Fs = recording@samp.rate,
overlap = ceiling(0.9 * window_n)
)plot(record_spec, col = rainbow(10))
I’ve zoomed into to the relevant section of the recording: the first 5 seconds and from 0kHz up to 30kHz. The Peersonic RPA2 seems to record sounds as low as 21kHz. The sensitivity of the microphone seems to be a bit lower under 5kHz.
plot(record_spec, col = rainbow(10), xlim = c(0, 5), ylim = c(0, 30e3))
Session info
::session_info() sessioninfo
─ Session info ───────────────────────────────────────────────────────────────
setting value
version R version 4.3.1 (2023-06-16)
os Ubuntu 22.04.3 LTS
system x86_64, linux-gnu
ui X11
language nl_BE:nl
collate nl_BE.UTF-8
ctype nl_BE.UTF-8
tz Europe/Brussels
date 2023-08-30
pandoc 3.1.1 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
─ Packages ───────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0)
digest 0.6.32 2023-06-26 [1] CRAN (R 4.3.1)
evaluate 0.21 2023-05-05 [1] CRAN (R 4.3.0)
fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0)
htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.3.0)
htmlwidgets 1.6.2 2023-03-17 [1] CRAN (R 4.3.0)
jsonlite 1.8.7 2023-06-29 [1] CRAN (R 4.3.1)
knitr 1.43 2023-05-25 [1] CRAN (R 4.3.0)
MASS 7.3-60 2023-05-04 [4] CRAN (R 4.3.1)
rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0)
rmarkdown 2.23 2023-07-01 [1] CRAN (R 4.3.1)
rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.3.0)
sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0)
signal * 0.7-7 2021-05-25 [1] CRAN (R 4.3.1)
tuneR * 1.4.5 2023-08-14 [1] CRAN (R 4.3.1)
xfun 0.39 2023-04-20 [1] CRAN (R 4.3.0)
yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0)
[1] /home/thierry/R/x86_64-pc-linux-gnu-library/4.3
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library
──────────────────────────────────────────────────────────────────────────────