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.

octaveFilter System object

Octave-band and fractional octave-band filter

Description

The octaveFilter System object™ performs octave-band or fractional octave-band filtering independently across each input channel. An octave-band is a frequency band where the highest frequency is twice the lowest frequency. Octave-band and fractional octave-band filters are commonly used to mimic how humans perceive loudness. Octave filters are best understood when viewed on a logarithmic scale, which models how the human ear weights the spectrum.

To perform octave-band or fractional octave-band filtering on your input:

  1. Create the octaveFilter 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

octFilt = octaveFilter
octFilt = octaveFilter(centerFreq)
octFilt = octaveFilter(centerFreq,bw)
octFilt = octaveFilter(___,Name,Value)

Description

octFilt = octaveFilter creates a System object, octFilt, that performs octave-band filtering independently across each input channel.

octFilt = octaveFilter(centerFreq) sets the CenterFrequency property to centerFreq.

octFilt = octaveFilter(centerFreq,bw) sets the Bandwidth property to bw.

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

Example: octFilt = octaveFilter(1000,'1/3 octave','SampleRate',96000) creates a System object, octFilt, with a center frequency of 1000 Hz, a 1/3 octave filter bandwidth, and a sample rate of 96,000 Hz.

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

Order of the octave filter, specified as an even integer.

Tunable: No

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

Center frequency of the octave filter in Hz, specified as a positive scalar.

  • The maximum center frequency is the value that causes the upper band edge to be equal to the Nyquist frequency, Fs/2. Frequencies above this value are saturated.

  • The minimum center frequency is the value that causes the lower band edge to be equal to 1 Hz. Frequencies below this value are quantized to the value that corresponds to lower band edge equal to 1 Hz.

Tunable: Yes

Data Types: single | double

Filter bandwidth in octaves, specified as '1 octave', '2/3 octave', '1/2 octave', '1/3 octave', '1/6 octave', '1/12 octave', '1/24 octave', or '1/48 octave'.

Tunable: Yes

Data Types: char

Oversample toggle, specified as false or true.

  • false –– The octave filter runs at the input sample rate.

  • true –– The octave filter runs at two times the input sample rate. Oversampling minimizes the frequency warping effects introduced by the bilinear transformation. An FIR halfband interpolator implements oversampling before octave filtering. A halfband decimator reduces the sample rate back to the input sampling rate after octave filtering.

Tunable: No

Data Types: logical

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

Tunable: Yes

Data Types: single | double

Usage

Syntax

audioOut = octFilt(audioIn)

Description

example

audioOut = octFilt(audioIn) applies octave-band filtering to the input signal, audioIn, and returns the filtered signal, audioOut. The type of filtering is specified by the algorithm and properties of the octaveFilter System object™, octFilt.

Input Arguments

expand all

Audio input to the octave 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 output from the octave filter, 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)
createAudioPluginClassCreate audio plugin class that implements functionality of System object
visualizeVisualize and validate filter response
isStandardCompliantVerify octave filter design is ANSI S1.11-2004 compliant
getFilterReturn biquad filter object with design parameters set
getANSICenterFrequenciesGet the list of valid ANSI S1.11-2004 center frequencies
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 octaveFilter System object to user-facing parameters:

PropertyRangeMappingUnits
CenterFrequency[3, 22000]logHz
Bandwidth'1 octave', '2/3 octave', '1/2 octave', '1/3 octave', '1/6 octave', '1/12 octave', '1/24 octave', or '1/48 octave'

Your MIDI controller range is discretized into seven levels, corresponding to the seven Bandwidth choices.

––

Examples

expand all

Use the octaveFilter System object™ to design a 1/3 octave-band filter centered at 1000 Hz. Process an audio signal using your octave filter design.

Create a dsp.AudioFileReader System object.

samplesPerFrame = 1024;
reader = dsp.AudioFileReader('Filename', ...
    'RockGuitar-16-44p1-stereo-72secs.wav', ...
    'SamplesPerFrame',samplesPerFrame, ...
    'PlayCount',Inf);

Create an octaveFilter System object. Use the sample rate of the reader as the sample rate of the octave filter.

centerFreq = 1000;
bw = '1/3 octave';
Fs = reader.SampleRate;

octFilt = octaveFilter(centerFreq,bw,'SampleRate',Fs);

Visualize the filter response and verify that it fits within the class 0 mask of the ANSI S1.11-2004 standard.

visualize(octFilt,'class 0')

Create a spectrum analyzer to visualize the original audio signal and the audio signal after octave-band filtering.

scope = dsp.SpectrumAnalyzer( ...
    'SampleRate',Fs, ...
    'PlotAsTwoSidedSpectrum',false, ...
    'FrequencyScale','Log', ...
    'FrequencyResolutionMethod','WindowLength', ...
    'WindowLength',samplesPerFrame, ...
    'Title','Octave-Band Filtering', ...
    'ShowLegend',true, ...
    'ChannelNames',{'Original signal','Filtered signal'});

Process the audio signal in an audio stream loop. Visualize the filtered audio and the original audio. As a best practice, release the System objects when complete.

tic;
while toc < 20
    x = reader();
    y = octFilt(x);
    scope([x(:,1),y(:,1)])
end

release(octFilt)
release(scope)
release(reader)

Create an octave-band filter bank that conforms to ANSI S1.11-2004. Pass white noise through the filter bank and inspect the resulting power in each band.

Create an octave filter with default settings. Visualize the filter design and verify that it conforms to ANSI S1.11-2004 for class 0.

octFilt = octaveFilter;
visualize(octFilt,'class 0')

Get a vector of valid center frequencies, given the center frequency of octFilt. Create an octave filter bank using the valid center frequencies.

centerFrequencies = getANSICenterFrequencies(octFilt);
for i = 1:11
    octaveFilterBank{i} = octaveFilter(centerFrequencies(i),'FilterOrder',12);
end

Use getFilter to return biquad filter objects for each filter in your octave filter bank. Visualize the octave filter bank with a linear frequency scale.

plotter = fvtool(getFilter(octaveFilterBank{1}), ...
    getFilter(octaveFilterBank{2}), ...
    getFilter(octaveFilterBank{3}), ...
    getFilter(octaveFilterBank{4}), ...
    getFilter(octaveFilterBank{5}), ...
    getFilter(octaveFilterBank{6}), ...
    getFilter(octaveFilterBank{7}), ...
    getFilter(octaveFilterBank{8}), ...
    getFilter(octaveFilterBank{9}), ...
    getFilter(octaveFilterBank{10}), ...
    getFilter(octaveFilterBank{11}), ...
    'Fs',octaveFilterBank{1}.SampleRate);

Visualize the octave filter bank with a logarithmic frequency scale. The logarithmic frequency scale makes the center frequencies appear evenly distributed.

set(plotter,'FrequencyScale','Log')

Create a white noise signal. By definition, white noise has a flat power spectral density.

whiteNoiseGenerator = dsp.ColoredNoise(0,1024);
whiteNoise = whiteNoiseGenerator();

Pass the white noise signal through the octave-band filter bank.

for i = 1:11
    filteredWhiteNoise(:,i) = octaveFilterBank{i}(whiteNoise);
end

Calculate and plot the power in each octave.

for i = 1:11
    powerPerBand(i) = bandpower(filteredWhiteNoise(:,i));
end

bar(powerPerBand)
title('Power Distribution of Octave Band Filter Bank')
set(gca,'XTickLabel',{round(centerFrequencies)})
xlabel('Center Frequency of Octave Band Filter (Hz)')
ylabel('Normalized Power')

The bandpower increases by a factor of approximately two because the octave bandwidth increases by a factor of two. The power distribution of an octave filter bank mimics how higher frequencies are percieved louder in white noise. You can use octave filter banks to weight a spectrum for percieved loudness.

Process a speech signal using different octave bands from an octave-band filter bank.

Design a 1/2 octave filter with an estimated center frequency of 800 Hz. Use isStandardCompliant to find the nearest compliant center frequency.

octFilt = octaveFilter(800,'1/2 octave');
[complianceStatus,suggestedCenterFrequency] = isStandardCompliant(octFilt,'class 0')
complianceStatus =

  logical

   0


suggestedCenterFrequency =

  841.3951

Change the center frequency of the octFilt object to the suggested center frequency returned by isStandardCompliant. Get a list of valid ANSI S1.11-2004 center frequencies, given your specified octFilt center frequency.

octFilt.CenterFrequency = suggestedCenterFrequency;
Fo = getANSICenterFrequencies(octFilt);

Create an audio file reader and audio device writer.

fileReader = dsp.AudioFileReader('Counting-16-44p1-mono-15secs.wav');
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);

Create a scope to visualize the filtered and unfiltered signals.

scope = dsp.SpectrumAnalyzer(...
    'PlotAsTwoSidedSpectrum',false,...
    'FrequencyScale','Log',...
    'Title','Octave-Band Filtering',...
    'ShowLegend',true,...
    'ChannelNames',{'Original signal','Filtered signal'});

In an audio stream loop, process the audio signal using your octave-band filter. Vary the center frequency to hear the effect. As a best practice, release your objects after processing.

index = 12;
octFilt.CenterFrequency = Fo(index);
count = 1;
while ~isDone(fileReader)
    x = fileReader();
    y = octFilt(x);
    scope([x,y])
    deviceWriter(y);

    if mod(count,100)==0
        octFilt.CenterFrequency = Fo(index);
        index = index+1;
    end
    count = count+1;
end

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

Remove additive noise from an audio tone scale using an octaveFilter System object™.

Create audioOscillator and audioDeviceWriter System objects with default properties. Create an octaveFilter System object with the center frequency set to 100 Hz.

osc = audioOscillator;
deviceWriter = audioDeviceWriter;
octFilt = octaveFilter(100);

In an audio stream loop, listen to a tone created by your audio oscillator. The tone contains additive Gaussian noise.

for i = 1:400
    x = osc();
    x1 = x + 0.1*randn(512,1);
    deviceWriter(x1);
    if rem(i,100)==0
        osc.Frequency = osc.Frequency*2;
    end
end

Create a spectrum analyzer to view your filtered and unfiltered signals.

scope = dsp.SpectrumAnalyzer( ...
    'PlotAsTwoSidedSpectrum',false, ...
    'FrequencyScale','Log', ...
    'FrequencyResolutionMethod','WindowLength', ...
    'Title','Octave-Band Filtering', ...
    'ShowLegend',true, ...
    'SpectralAverages',10, ...
    'ChannelNames',{'Original signal','Filtered signal'});

Reset the frequency of your audio oscillator to its default, 100 Hz.

osc.Frequency = 100;

In an audio stream loop, filter the corrupted tone using your octave-band filter. When the tone changes frequency in the loop, change the center frequency of your octave filter to match. As a best practice, release your audio device once done.

for i = 1:400
    x = osc();
    x1 = x + 0.1*randn(512,1);
    x2 = octFilt(x1);
    deviceWriter(x2);
    if rem(i,100)==0
        osc.Frequency = osc.Frequency*2;
        octFilt.CenterFrequency = octFilt.CenterFrequency*2;
    end
    scope([x1,x2])
end

release(deviceWriter)

Design a sixth-order 1/3 octave filter with a sample rate of 96 kHz.

octFilt = octaveFilter('FilterOrder',6, ...
    'Bandwidth','1/3 octave', ...
    'SampleRate',96e3);

Get the center frequencies defined by the ANSI S1.11-2004 standard. The center frequencies defined by the standard depend on the Bandwidth and SampleRate properties.

centerFrequencies = getANSICenterFrequencies(octFilt)
centerFrequencies =

   1.0e+04 *

  Columns 1 through 7

    0.0004    0.0005    0.0006    0.0008    0.0010    0.0013    0.0016

  Columns 8 through 14

    0.0020    0.0025    0.0032    0.0040    0.0050    0.0063    0.0079

  Columns 15 through 21

    0.0100    0.0126    0.0158    0.0200    0.0251    0.0316    0.0398

  Columns 22 through 28

    0.0501    0.0631    0.0794    0.1000    0.1259    0.1585    0.1995

  Columns 29 through 35

    0.2512    0.3162    0.3981    0.5012    0.6310    0.7943    1.0000

  Columns 36 through 41

    1.2589    1.5849    1.9953    2.5119    3.1623    3.9811

Set the center frequency of the octave filter to 19.953 kHz and visualize the response with a 'class 0' compliance mask.

octFilt.CenterFrequency = centerFrequencies(38);
visualize(octFilt,'class 0')

The red mask on the plot defines the bounds for the magnitude response of the filter. The magnitude response of this filter goes above the upper bound of the compliance mask around 6.6 kHz. One way to counter this is to increase the filter order so that the filter's rolloff is steeper.

To bring the octave filter design into compliance, set the octave filter order to 8.

octFilt.FilterOrder = 8;

Another option to bring the octave filter design into compliance is to set the Overample property to true. This designs and runs the filter at twice the specified SampleRate to reduce the effects of the bilinear transformation during the design stage.

octFilt.FilterOrder = 6;
octFilt.Oversample = true;

Design a sixth-order 2/3 octave filter with a 96 kHz sample rate.

octFilt = octaveFilter('FilterOrder',6, ...
    'Bandwidth','2/3 octave', ...
    'SampleRate',96e3);

Get the center frequencies defined by the ANSI S1.11-2004 standard. The center frequencies defined by the standard depend on the Bandwidth and SampleRate properties.

centerFrequencies = getANSICenterFrequencies(octFilt)
centerFrequencies =

   1.0e+04 *

  Columns 1 through 7

    0.0004    0.0006    0.0010    0.0016    0.0025    0.0040    0.0063

  Columns 8 through 14

    0.0100    0.0158    0.0251    0.0398    0.0631    0.1000    0.1585

  Columns 15 through 20

    0.2512    0.3981    0.6310    1.0000    1.5849    2.5119

Set the center frequency of the octave filter to ~6 Hz and visualize the response with a 'class 0' compliance mask.

octFilt.CenterFrequency = centerFrequencies(2);
visualize(octFilt,'class 0')

The red mask on the plot defines the bounds for the magnitude response of the filter. The magnitude response of this filter goes below the lower bound of the compliance mask between 5.5 and 7.5 Hz.

Low-frequency filters in an octave filter bank have very low normalized center frequencies, and the filters designed for them have poles that are almost on the unit circle. To make this filter ANSI compliant, it has to be designed and operated at a lower sample rate.

To bring the octave filter design into compliance, set the sample rate to 48 kHz.

octFilt.SampleRate = 48e3;

Definitions

expand all

Algorithms

expand all

References

[1] Orfanidis, Sophocles J. Introduction to Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 2010.

[2] Acoustical Society of America. American National Standard Specification for Octave-Band and Fractional-Octave-Band Analog and Digital Filters. ANSI S1.11-2004. Melville, NY: Acoustical Society of America, 2009.

Extended Capabilities

Introduced in R2016b

Was this topic helpful?