noiseGate

Dynamic range gate

Description

The noiseGate System 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 noiseGate System object specify the type of dynamic range gating.

To perform dynamic range gating:

  1. Create the noiseGate object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?.

Creation

Description

dRG = noiseGate creates a System object, dRG, that performs dynamic range gating independently across each input channel.

dRG = noiseGate(thresholdValue) sets the Threshold property to thresholdValue.

dRG = noiseGate(___,Name,Value) sets each property Name to the specified Value. Unspecified properties have default values.

Example: dRG = noiseGate('AttackTime',0.01,'SampleRate',16000) creates a System object, dRG, with a 10 ms attack time and a 16 kHz sample rate.

Properties

expand all

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.

Operation threshold in dB, specified as a real scalar.

Operation threshold is the level below which gain is applied to the input signal.

Tunable: Yes

Data Types: single | double

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.

Tunable: Yes

Data Types: single | double

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.

Tunable: Yes

Data Types: single | double

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.

Tunable: Yes

Data Types: single | double

Input sample rate in Hz, specified as a positive scalar.

Tunable: Yes

Data Types: single | double

Usage

Description

example

audioOut = dRG(audioIn) performs dynamic range gating on the input signal, audioIn, and returns the gated signal, audioOut. The type of dynamic range gating is specified by the algorithm and properties of the noiseGate System object, dRG.

[audioOut,gain] = dRG(audioIn) also returns the applied gain, in dB, at each input sample.

Input Arguments

expand all

Audio input to the noise gate, specified as a matrix. The columns of the matrix are treated as independent audio channels.

Data Types: single | double

Output Arguments

expand all

Audio output from the noise gate, returned as a matrix the same size as audioIn.

Data Types: single | double

Gain applied by noise gate, returned as a matrix the same size as audioIn.

Data Types: single | double

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

visualizeVisualize static characteristic of dynamic range controller
createAudioPluginClassCreate audio plugin class that implements functionality of System object
parameterTunerTune object parameters while streaming
configureMIDIConfigure MIDI connections between audio object and MIDI controller
disconnectMIDIDisconnect MIDI controls from audio object
getMIDIConnectionsGet MIDI connections of audio object
cloneCreate duplicate System object
isLockedDetermine if System object is in use
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object
stepRun System object algorithm

The createAudioPluginClass and configureMIDI functions map tunable properties of the noiseGate System object to user-facing parameters:

PropertyRangeMappingUnit
Threshold[–140, 0]lineardB
AttackTime[0, 4]linearseconds
ReleaseTime[0, 4]linearseconds
HoldTime[0, 4]linearseconds

Examples

collapse all

Use dynamic range gating to attenuate background noise from an audio signal.

Set up the dsp.AudioFileReader and 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);

Set up a time scope to visualize the signal before and after dynamic range gating.

scope = timescope( ...
    'SampleRate',fileReader.SampleRate, ...
    'TimeSpanOverrunAction','Scroll', ...
    'TimeSpanSource','property',...
    '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)

Create a dsp.AudioFileReader to read in audio frame-by-frame. Create an audioDeviceWriter to write audio to your sound card. Create a noiseGate to process the audio data.

frameLength = 1024;
fileReader = dsp.AudioFileReader('RockDrums-44p1-stereo-11secs.mp3', ...
    'SamplesPerFrame',frameLength);
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);

dRG = noiseGate('SampleRate',fileReader.SampleRate);

Call parameterTuner to open a UI to tune parameters of the noiseGate while streaming.

parameterTuner(dRG)

In an audio stream loop:

  1. Read in a frame of audio from the file.

  2. Apply dynamic range gating.

  3. Write the frame of audio to your audio device for listening.

While streaming, tune parameters of the dynamic range gate and listen to the effect.

while ~isDone(fileReader)
    audioIn = fileReader();
    audioOut = dRG(audioIn);
    deviceWriter(audioOut);
    drawnow limitrate % required to update parameter
end

As a best practice, release your objects once done.

release(deviceWriter)
release(fileReader)
release(dRG)

Algorithms

expand all

The noiseGate System object processes a signal frame by frame and element by element.

References

[1] 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.

Extended Capabilities

Introduced in R2016a