Dynamic range gate
object™ performs dynamic range gating independently across each input channel. Dynamic
range gating suppresses signals below a given threshold. It uses specified attack, release,
and hold times to achieve a smooth applied gain curve. Properties of the
object specify the type of dynamic range gating.
To perform dynamic range gating:
Create the noiseGate object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects? (MATLAB).
dRG = noiseGate
dRG = noiseGate(thresholdValue)
dRG = noiseGate(___,Name,Value)
dRG = noiseGate creates a System
dRG, that performs dynamic range gating independently
across each input channel.
dRG = noiseGate( sets the
dRG = noiseGate(___,
sets each property
Name to the specified
Unspecified properties have default values.
dRG = noiseGate('AttackTime',0.01,'SampleRate',16000)creates a System object,
dRG, with a 10 ms attack time and a 16 kHz sample rate.
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).
Threshold— Operation threshold (dB)
–10(default) | real scalar
Operation threshold in dB, specified as a real scalar.
Operation threshold is the level below which gain is applied to the input signal.
AttackTime— Attack time (s)
0.05(default) | real scalar
Attack time in seconds, specified as a real scalar greater than or equal to 0.
Attack time is the time it takes the applied gain to rise from 10% to 90% of its final value when the input goes below the threshold.
ReleaseTime— Release time (s)
0.02(default) | real scalar
Release time in seconds, specified as a real scalar greater than or equal to 0.
Release time is the time it takes the applied gain to drop from 90% to 10% of its final value when the input goes above the threshold.
HoldTime— Hold time (s)
0.05(default) | real finite scalar
Hold time in seconds, specified as a real scalar greater than or equal to 0.
Hold time is the period in which the applied gain is held constant before it starts moving toward its steady-state value. Hold time begins when the input level crosses the operation threshold.
SampleRate— Input sample rate (Hz)
44100(default) | positive scalar
Input sample rate in Hz, specified as a positive scalar.
For versions earlier than R2016b, use the
step function to run the System object™ algorithm. The arguments to
step are the
object you created, followed by the arguments shown in this section.
y = step(obj,x) and
y = obj(x)
perform equivalent operations.
audioOut = dRG(audioIn)
[audioOut,gain] = dRG(audioIn)
audioIn— Audio input to noise gate
Audio input to the noise gate, specified as a matrix. The columns of the matrix are treated as independent audio channels.
audioOut— Audio output from noise gate
Audio output from the noise gate, returned as a matrix the same size as
gain— Gain applied by noise gate (dB)
Gain applied by noise gate, returned as a matrix the same size as
To use an object function, specify the
object as the first input argument. For
example, to release system resources of a System
functions map tunable properties of the
object to user-facing parameters:
Use dynamic range gating to attenuate background noise from an audio signal.
Set up the
audioDeviceWriter System objects™.
frameLength = 1024; fileReader = dsp.AudioFileReader( ... 'Filename','Counting-16-44p1-mono-15secs.wav', ... 'SamplesPerFrame',frameLength); deviceWriter = audioDeviceWriter( ... 'SampleRate',fileReader.SampleRate);
Corrupt the audio signal with Gaussian noise. Play the audio.
while ~isDone(fileReader) x = fileReader(); xCorrupted = x + (1e-2/4)*randn(frameLength,1); deviceWriter(xCorrupted); end release(fileReader)
Set up a dynamic range gate with a threshold of -25 dB, an attack time of 0.01 seconds, a release time of 0.02 seconds, and a hold time of 0 seconds. Use the sample rate of your audio file reader.
gate = noiseGate(-25, ... 'AttackTime',0.01, ... 'ReleaseTime',0.02, ... 'HoldTime',0, ... 'SampleRate',fileReader.SampleRate);
Visualize the static characteristic of the gate.
Set up a time scope to visualize the signal before and after dynamic range gating.
scope = dsp.TimeScope( ... 'SampleRate',fileReader.SampleRate, ... 'TimeSpanOverrunAction','Scroll', ... 'TimeSpan',16, ... 'BufferLength',1.5e6, ... 'YLimits',[-1 1], ... 'ShowGrid',true, ... 'ShowLegend',true, ... 'Title','Corrupted vs. Gated Audio');
Play the processed audio and visualize it on scope.
while ~isDone(fileReader) x = fileReader(); xCorrupted = x + (1e-2/4)*randn(frameLength,1); y = gate(xCorrupted); deviceWriter(y); scope([xCorrupted,y]); end release(fileReader) release(gate) release(deviceWriter) release(scope)
object processes a signal frame by frame and element by element.
The N-point signal, x[n], is converted to magnitude:
xa[n] passes through the gain computer. The gain computer uses the static characteristic properties of the dynamic range gate to determine a brick-wall gain for signal below the threshold:
The computed gain, gc[n], is smoothed using specified attack, release, and hold time properties:
AttackTimeproperty. TR is the release time period, specified by the
ReleaseTimeproperty. Fs is the input sampling rate, specified by the
CR are hold counters for attack and release,
respectively. The limit, TH
, is determined by the
The output of the dynamic range gate is given as
 Giannoulis, Dimitrios, Michael Massberg, and Joshua D. Reiss. "Digital Dynamic Range Compressor Design –– A Tutorial and Analysis." Journal of Audio Engineering Society. Vol. 60, Issue 6, 2012, pp. 399–408.
Usage notes and limitations:
System Objects in MATLAB Code Generation (MATLAB Coder)