killDC: Kill DC

Description Usage Arguments Examples

View source: R/utilities_postprocessing.R

Description

Removes DC offset or similar disbalance in a waveform dynamically, by subtracting a smoothed ~moving average. Simplified compared to a true moving average, but very fast (a few ms per second of 44100 audio).

Usage

1
2
killDC(sound, windowLength = 200, samplingRate = 16000,
  windowLength_points = NULL, plot = FALSE)

Arguments

sound

input vector oscillating about zero

windowLength

the length of smoothing window, ms

samplingRate

the sampling rate, Hz. Only needed if the length of smoothing window is specified in ms rather than points

windowLength_points

the length of smoothing window, points. If specified, overrides both windowLength and samplingRate

plot

if TRUE, plots the original sound, smoothed moving average, and modified sound

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# remove static DC offset
a = rnorm(500) + .3
b = soundgen:::killDC(a, windowLength_points = 500, plot = TRUE)

# remove trend
a = rnorm(500) + seq(0, 1, length.out = 500)
b = soundgen:::killDC(a, windowLength_points = 100, plot = TRUE)

# can also be used as a high-pass filter
a = rnorm(500) + sin(1:500 / 50)
b = soundgen:::killDC(a, windowLength_points = 25, plot = TRUE)

soundgen documentation built on Oct. 4, 2018, 9:04 a.m.