octaveFilter

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.

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.

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.

When using the `parameterTuner`, the center frequency must be in the range [0.2, SampleRate/2] 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` | `string`

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

expand all

 `createAudioPluginClass` Create audio plugin class that implements functionality of System object `visualize` Visualize and validate filter response `isStandardCompliant` Verify octave filter design is ANSI S1.11-2004 compliant `getFilter` Return biquad filter object with design parameters set `getANSICenterFrequencies` Get the list of valid ANSI S1.11-2004 center frequencies `parameterTuner` Tune object parameters while streaming
 `configureMIDI` Configure MIDI connections between audio object and MIDI controller `disconnectMIDI` Disconnect MIDI controls from audio object `getMIDIConnections` Get MIDI connections of audio object
 `clone` Create duplicate System object `isLocked` Determine if System object is in use `release` Release resources and allow changes to System object property values and input characteristics `reset` Reset internal states of System object `step` Run System object algorithm

Note

`octaveFilter` supports additional filter analysis functions. See Analyze Octave Filter Design for details.

Examples

collapse all

Use `octaveFilter` 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` object.

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

Create an `octaveFilter` 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.

```while ~isDone(reader) x = reader(); y = octFilt(x); scope([x(:,1),y(:,1)]) end release(octFilt) release(reader) release(scope)```

Create an octave filter. Visualize the filter response and validate that it is class 2 compliant.

```octFilt = octaveFilter('CenterFrequency',1000); visualize(octFilt,'class 2')```

Analyze the filter using `fvtool`.

`fvtool(octFilt,'Fs',octFilt.SampleRate)`

The `octaveFilter` object supports several filter analysis methods. For more information, use `help `at the command line:

`help octaveFilter.helpFilterAnalysis`
``` The following analysis methods are available for discrete-time filter System objects: fvtool - Filter visualization tool info - Filter information freqz - Frequency response phasez - Phase response zerophase - Zero-phase response grpdelay - Group delay response phasedelay - Phase delay response impz - Impulse response impzlength - Length of impulse response stepz - Step response zplane - Pole/zero plot cost - Cost estimate for implementation of the filter System object measure - Measure characteristics of the frequency response order - Filter order coeffs - Filter coefficients in a structure firtype - Determine the type (1-4) of a linear phase FIR filter System object tf - Convert to transfer function zpk - Convert to zero-pole-gain ss - Convert to state space representation isallpass - Verify if filter System object is allpass isfir - Verify if filter System object is FIR islinphase - Verify if filter System object is linear phase ismaxphase - Verify if filter System object is maximum phase isminphase - Verify if filter System object is minimum phase isreal - Verify if filter System object is minimum real issos - Verify if filter System object is in second-order sections form isstable - Verify if filter System object is stable realizemdl - Filter realization (Simulink diagram) specifyall - Fully specify fixed-point filter System object settings cascade - Create a FilterCascade System object Second-order sections: scale - Scale second-order sections of BiquadFilter System object scalecheck - Check scaling of BiquadFilter System object reorder - Reorder second-order sections of BiquadFilter System object cumsec - Cumulative second-order section of BiquadFilter System object scaleopts - Create an options object for second-order section scaling sos - Convert to second-order-sections (for IIRFilter System objects only) Fixed-Point (Fixed-Point Designer Required): freqrespest - Frequency response estimate via filtering freqrespopts - Create an options object for frequency response estimate noisepsd - Power spectral density of filter output due to roundoff noise noisepsdopts - Create an options object for output noise PSD computation Multirate Analysis: polyphase - Polyphase decomposition of multirate filter System object gain (CIC decimator) - Gain of CIC decimator filter System object gain (CIC interpolator) - Gain of CIC interpolator filter System object For decimator, interpolator, or rate change filter System objects the analysis tools perform computations relative to the rate at which the filter is running. If a sampling frequency is specified, it is assumed that the filter is running at that rate. Help for octaveFilter.helpFilterAnalysis is inherited from superclass DSP.PRIVATE.FILTERANALYSIS ```

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

Create `audioOscillator` and `audioDeviceWriter` objects with default properties. Create an `octaveFilter` 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) release(scope)```

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×53 104 × 0.0000 0.0000 0.0000 0.0001 0.0001 0.0001 0.0001 0.0001 0.0002 0.0002 0.0003 0.0003 0.0004 0.0005 0.0006 0.0008 0.0010 0.0013 0.0016 0.0020 0.0025 0.0032 0.0040 0.0050 0.0063 0.0079 0.0100 0.0126 0.0158 0.0200 0.0251 0.0316 0.0398 0.0501 0.0631 0.0794 0.1000 0.1259 0.1585 0.1995 0.2512 0.3162 0.3981 0.5012 0.6310 0.7943 1.0000 1.2589 1.5849 1.9953 ```

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 `Oversample` 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×25 104 × 0.0000 0.0001 0.0001 0.0002 0.0003 0.0004 0.0006 0.0010 0.0016 0.0025 0.0040 0.0063 0.0100 0.0158 0.0251 0.0398 0.0631 0.1000 0.1585 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;`

Create a `dsp.AudioFileReader` to read in audio frame-by-frame. Create a `audioDeviceWriter` to write audio to your sound card. Create an `octaveFilter` to process the audio data. Call `visualize` to plot the frequency response of the octave filter.

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

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

`parameterTuner(octFilt)`

In an audio stream loop:

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

2. Apply octave filtering.

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

While streaming, tune parameters of the octave filter and listen to the effect.

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

As a best practice, release your objects once done.

```release(deviceWriter) release(fileReader) release(octFilt)```

expand all

Tips

The `createAudioPluginClass` and `configureMIDI` functions map tunable properties of the `octaveFilter` 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.

––

expand all

References

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

Get trial now