Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

crossoverFilter System object

Audio crossover filter

Description

The crossoverFilter System object™ implements an audio crossover filter, which is used to split an audio signal into two or more frequency bands. Crossover filters are multiband filters whose overall magnitude frequency response is flat.

To implement an audio crossover filter:

  1. Create the crossoverFilter 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? (MATLAB).

Creation

Syntax

crossFilt = crossoverFilter
crossFilt = crossoverFilter(nCrossovers)
crossFilt = crossoverFilter(nCrossovers,xFrequencies)
crossFilt = crossoverFilter(nCrossovers,xFrequencies,xSlopes)
crossFilt = crossoverFilter(nCrossovers,xFrequencies,xSlopes,Fs)
crossFilt = crossoverFilter(___,Name,Value)

Description

crossFilt = crossoverFilter creates a System object, crossFilt, that implements an audio crossover filter.

crossFilt = crossoverFilter(nCrossovers) sets the NumCrossovers property to nCrossovers.

crossFilt = crossoverFilter(nCrossovers,xFrequencies) sets the CrossoverFrequencies property to xFrequencies.

crossFilt = crossoverFilter(nCrossovers,xFrequencies,xSlopes) sets the CrossoverSlopes property to xSlopes.

crossFilt = crossoverFilter(nCrossovers,xFrequencies,xSlopes,Fs) sets the SampleRate property to Fs.

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

Example: crossFilt = crossoverFilter(2,'CrossoverFrequencies',[100,800],'CrossoverSlopes',[6,48]) creates a System object, crossFilt, with two crossovers located at 100 Hz and 800 Hz, and crossover slopes of 6 dB/octave and 48 dB/octave, respectively.

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 (MATLAB).

Number of magnitude response band crossings, specified as a scalar integer in the range 1 to 4.

The number of bands output when implementing crossover filtering is one more than the NumCrossovers value.

Number of magnitude response band crossingsNumber of bands output
1two-band
2three-band
3four-band
4five-band

Tunable: No

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Crossover frequencies in Hz, specified as a scalar or vector of real values of length NumCrossovers.

Crossover frequencies are the intersections of magnitude response bands of the individual two-band crossover filters used in the multiband crossover filter.

Tunable: Yes

Data Types: single | double

Crossover slopes in dB/octave, specified as a scalar or vector of real values in the range [6:6:48]. If a specified crossover slope is not inside the range, the slope is rounded to the nearest allowed value.

  • If CrossoverSlopes is a scalar, all two-band component crossover slopes take that value.

  • If CrossoverSlopes is a vector of length NumCrossovers, the respective two-band component crossover slopes take those values.

Crossover slopes are the slopes of individual bands at the associated crossover frequency, as specified in the two-band component crossover.

Tunable: Yes

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

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

Tunable: Yes

Data Types: single | double

Usage

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.

For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Syntax

[band1,...,bandN] = crossFilt(audioIn)

Description

example

[band1,...,bandN] = crossFilt(audioIn) applies a crossover filter on the input, audioIn, and returns the filtered output bands, [band1,...,bandN], where N = NumCrossovers + 1.

Input Arguments

expand all

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

Data Types: single | double

Output Arguments

expand all

Audio bands output from the crossover filter, returned as a set of N bands. The NumCrossovers property determines the number of return arguments: N = NumCrossovers + 1. The size of each output argument is 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)
visualizeVisualize magnitude response of crossover filter
costEstimate implementation cost of audio System objects
createAudioPluginClassCreate audio plugin class that implements functionality of System object
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 locked
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 crossoverFilter System object to user-facing parameters:

PropertyRangeMappingUnit
CrossoverFrequencies[20, 20000]linearHz
CrossoverSlopes[6, 48]lineardB/octave

Examples

expand all

Use the crossoverFilter System object™ to split Gaussian noise into three separate frequency bands.

Create a 5 second noise signal that assumes a 12,000 Hz sample rate.

noise = randn(12000*5,1);

Create a crossoverFilter System object with 2 crossovers (3 bands), crossover frequencies at 4 kHz and 8 kHz, a slope of 48 dB/octave, and a sample rate of 24 kHz.

crossFilt = crossoverFilter(...
    'NumCrossovers',2,...
    'CrossoverFrequencies',[4000,8000],...
    'CrossoverSlopes',48,...
    'SampleRate',24000);

Visualize the magnitude response of your crossover filter object.

visualize(crossFilt)

Call your crossover filter like a function with the noise signal as the argument.

[y1,y2,y3] = crossFilt(noise);

Visualize the results using a spectrogram.

figure('Position',[100,100,800,700]);
subplot(4,1,1)
    spectrogram(noise,120,100,6000,24000,'yaxis')
        title('Noise')
subplot(4,1,2)
    spectrogram(y1,120,100,6000,24000,'yaxis')
        title('y1')
subplot(4,1,3)
    spectrogram(y2,120,100,6000,24000,'yaxis')
        title('y2')
subplot(4,1,4)
    spectrogram(y3,120,100,6000,24000,'yaxis')
        title('y3')

Use the crossoverFilter System object™ to split an audio signal into three frequency bands.

Create the dsp.AudioFileReader and audioDeviceWriter System objects. Use the sample rate of the reader as the sample rate of the writer. Call setup to reduce the computation load of initialization in an audio stream loop.

samplesPerFrame = 256;

fileReader = dsp.AudioFileReader( ...
    'RockGuitar-16-44p1-stereo-72secs.wav', ...
    'SamplesPerFrame',samplesPerFrame);
deviceWriter = audioDeviceWriter( ...
    'SampleRate',fileReader.SampleRate);

setup(fileReader)
setup(deviceWriter,ones(samplesPerFrame,2))

Create a crossoverFilter System object with 2 crossovers (3 bands), crossover frequencies at 500 Hz and 1 kHz, and a slope of 18 dB/octave. Use the sample rate of the reader as the sample rate of the crossover filter.

crossFilt = crossoverFilter( ...
    'NumCrossovers',2, ...
    'CrossoverFrequencies',[500,1000], ...
    'CrossoverSlopes',18, ...
    'SampleRate',fileReader.SampleRate);

setup(crossFilt,ones(samplesPerFrame,2))

Visualize the bands of the crossover filter.

visualize(crossFilt)

Get the cost of the crossover filter.

cost(crossFilt)
ans = 

  struct with fields:

                  NumCoefficients: 48
                        NumStates: 18
    MultiplicationsPerInputSample: 48
          AdditionsPerInputSample: 37

Create a spectrum analyzer to visualize the effect of the crossover filter.

scope = dsp.SpectrumAnalyzer( ...
    'SampleRate',fileReader.SampleRate, ...
    'PlotAsTwoSidedSpectrum',false, ...
    'FrequencyScale','Log', ...
    'FrequencyResolutionMethod','WindowLength', ...
    'WindowLength',samplesPerFrame, ...
    'Title', ...
    'Crossover Bands and Reconstructed Signal', ...
    'ShowLegend',true, ...
    'ChannelNames',{'Original Signal','Band 1', ...
    'Band 2','Band 3','Sum'});

Play 10 seconds of the audio signal. Visualize the spectrum of the original audio, the crossover bands, and the reconstructed signal (sum of bands).

setup(scope,ones(samplesPerFrame,5))
count = 0;
while count < (fileReader.SampleRate/samplesPerFrame)*10
    originalSignal = fileReader();
    [band1,band2,band3] = crossFilt(originalSignal);
    sumOfBands = band1 + band2 + band3;
    scope([originalSignal(:,1), ...
           band1(:,1), ...
           band2(:,1), ...
           band3(:,1), ...
           sumOfBands(:,1)])
    deviceWriter(sumOfBands);
    count = count+1;
end

release(fileReader)
release(crossFilt)
release(scope)
release(deviceWriter)

De-essing is the process of diminishing sibilant sounds in an audio signal. Sibilance refers to the s, z, and sh sounds in speech, which can be disproportionately emphasized during recording. es sounds fall under the category of unvoiced speech with all consonants and have a higher frequency than voiced speech. In this example, you apply split-band de-essing to a speech signal by separating the signal into high and low frequencies, applying an expander to diminish the sibilant frequencies, and then remixing the channels.

Create a dsp.AudioFileReader System object™ and an audioDeviceWriter System object to read from a sound file and write to an audio device. Listen to the unprocessed signal. Then release the file reader and device writer.

fileReader = dsp.AudioFileReader( ...
    fullfile(matlabroot,'examples','audio','Sibilance.wav'));
deviceWriter = audioDeviceWriter;

while ~isDone(fileReader)
    audioIn = fileReader();
    deviceWriter(audioIn);
end

release(deviceWriter)
release(fileReader)

Create an expander System object to de-ess the audio signal. Set the sample rate of the expander to the sample rate of the audio file. Create a two-band crossover filter with a crossover of 3000 Hz. Sibilance is usually found in this range. Set the crossover slope to 12. Plot the frequency response of the crossover filter to confirm your design visually.

dRExpander = expander( ...
    'Threshold',-50, ...
    'AttackTime', 0.05, ...
    'ReleaseTime',0.05, ...
    'HoldTime',0.005, ...
    'SampleRate',fileReader.SampleRate);

crossFilt = crossoverFilter( ...
    'NumCrossovers',1, ...
    'CrossoverFrequencies',3000, ...
    'CrossoverSlopes',12);
visualize(crossFilt)

Create a dsp.TimeScope System object to visualize the original and processed audio signals.

scope = dsp.TimeScope( ...
    'SampleRate',fileReader.SampleRate, ...
    'TimeSpanOverrunAction','Scroll', ...
    'TimeSpan',4, ...
    'BufferLength',44100*8, ...
    'YLimits',[-1 1], ...
    'ShowGrid',true, ...
    'ShowLegend',true, ...
    'ChannelNames',{'Original','Processed'});

In an audio stream loop:

  1. Read in a frame of the audio file.

  2. Split the audio signal into two bands.

  3. Apply dynamic range expansion to the upper band.

  4. Remix the channels.

  5. Write the processed audio signal to your audio device for listening.

  6. Visualize the processed and unprocessed signals on a time scope.

As a best practice, release your objects once done.

while ~isDone(fileReader)
    audioIn = fileReader();

    [band1,band2] = crossFilt(audioIn);

    band2processed = dRExpander(band2);

    procAudio  = band1 + band2processed;

    deviceWriter(procAudio);

    scope([audioIn procAudio]);
end

release(deviceWriter)
release(fileReader)
release(scope)
release(crossFilt)
release(dRExpander)

Plosives are consonant sounds resulting from a sudden release of airflow. They are most pronounced in words beginning with p, d, and g sounds. Plosives can be emphasized by the recording process and are often displeasurable to hear. In this example, you minimize the plosives of a speech signal by applying highpass filtering and low-band compression.

Create a dsp.AudioFileReader System object™ and a audioDeviceWriter System object™ to read an audio signal from a file and write an audio signal to a device. Play the unprocessed signal. Then release the file reader and device writer.

fileReader   = dsp.AudioFileReader( ...
    fullfile(matlabroot,'examples','audio','Plosives.wav'));
deviceWriter = audioDeviceWriter;

while ~isDone(fileReader)
    audioIn = fileReader();
    deviceWriter(audioIn);
end
release(deviceWriter)
release(fileReader)

Design a highpass filter with a steep rolloff of all frequencies below 120 Hz. Use a dsp.BiquadFilter System object to implement the highpass filter design. Create a crossover filter with one crossover at 250 Hz. The crossover filter enables you to separate the band of interest for processing. Create a dynamic range compressor to compress the dynamic range of plosive sounds. To apply no make-up gain, set the MakeUpGainMode to 'Property' and use the default 0 dB MakeUpGain property value. Create a time scope to visualize the processed and unprocessed audio signal.

[B,A] = designVarSlopeFilter(48,120/(44100/2),'hi');
biquadFilter = dsp.BiquadFilter( ...
    'SOSMatrixSource','Input port', ...
    'ScaleValuesInputPort',false);

crossFilt = crossoverFilter( ...
    'NumCrossovers',1, ...
    'CrossoverFrequencies',250, ...
    'CrossoverSlopes',48);

dRCompressor = compressor( ...
    'Threshold',-35, ...
    'Ratio',10, ...
    'KneeWidth',20, ...
    'AttackTime',1e-4, ...
    'ReleaseTime',3e-1, ...
    'MakeUpGainMode','Property', ...
    'SampleRate',fileReader.SampleRate);

scope = dsp.TimeScope( ...
    'SampleRate',fileReader.SampleRate, ...
    'TimeSpan',3, ...
    'BufferLength',fileReader.SampleRate*3*2, ...
    'YLimits',[-1 1], ...
    'ShowGrid',true, ...
    'ShowLegend',true, ...
    'ChannelNames',{'Original','Processed'});

In an audio stream loop:

  1. Read in a frame of the audio file.

  2. Apply highpass filtering using your biquad filter.

  3. Split the audio signal into two bands.

  4. Apply dynamic range compression to the lower band.

  5. Remix the channels.

  6. Write the processed audio signal to your audio device for listening.

  7. Visualize the processed and unprocessed signals on a time scope.

As a best practice, release your objects once done.

while ~isDone(fileReader)
    audioIn = fileReader();

    audioIn = biquadFilter(audioIn,B,A);

    [band1,band2] = crossFilt(audioIn);

    band1compressed = dRCompressor(band1);

    audioOut  = band1compressed + band2;

    deviceWriter(audioOut);

    scope([audioIn audioOut]);
end

release(deviceWriter)
release(fileReader)
release(scope)
release(crossFilt)
release(dRCompressor)

Algorithms

expand all

The crossover System object is implemented as a binary tree of crossover pairs with additional phase-compensating sections [1]. Odd-order crossovers are implemented with Butterworth filters, while even-order crossovers are implemented with cascaded Butterworth filters (Linkwitz-Riley filters).

References

[1] D’Appolito, Joseph A. "Active Realization of Multiway All-Pass Crossover Systems." Journal of Audio Engineering Society. Vol. 35, Issue 4, 1987, pp. 239–245.

Extended Capabilities

See Also

Blocks

System Objects

Introduced in R2016a

Was this topic helpful?