Main Content

dsp.IIRHalfbandInterpolator

Interpolate by a factor of two using polyphase IIR

Description

The dsp.IIRHalfbandInterpolator System object™ performs efficient polyphase interpolation of the input signal by a factor of two. To design the halfband filter, you can specify the object to use an elliptic design or a quasi-linear phase design. The object uses these design methods to compute the filter coefficients. To filter the inputs, the object uses a polyphase structure. The allpass filters in the polyphase structure are in a minimum multiplier form.

Elliptic design introduces nonlinear phase and creates the filter using fewer coefficients than quasi linear design. Quasi-linear phase design overcomes phase nonlinearity at the cost of additional coefficients.

Alternatively, instead of designing the halfband filter using a design method, you can specify the filter coefficients directly. When you choose this option, the allpass filters in the two branches of the polyphase implementation can be in a minimum multiplier form or in a wave digital form.

You can also use dsp.IIRHalfbandInterpolator object to implement the synthesis portion of a two-band filter bank to synthesize a signal from lowpass and highpass subbands.

To upsample and interpolate your data:

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

iirhalfbandinterp = dsp.IIRHalfbandInterpolator returns an IIR halfband interpolation filter, iirhalfbandinterp, with the default settings. Under the default settings, the System object upsamples and interpolates the input data using a halfband frequency of 22050 Hz, a transition width of 4100 Hz, and a stopband attenuation of 80 dB.

iirhalfbandinterp = dsp.IIRHalfbandInterpolator(Name=Value) returns an IIR halfband interpolator, with additional properties specified by one or more Name-Value pair arguments.

Example: iirhalfbandinterp = dsp.IIRHalfbandInterpolator(Specification="Filter order and stopband attenuation") creates an IIR halfband interpolator object with filter order set to 9 and stopband attenuation set to 80 dB.

example

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.

Filter design parameters, specified as a character vector. When you set Specification to one of the filter design options, you can specify the filter design parameters using the corresponding FilterOrder, StopbandAttenuation, and TransitionWidth properties. Also, you can specify the design method using DesignMethod. When you set Specification to "Coefficients", you can specify the coefficients directly.

Order of the IIR halfband filter, specified as a positive scalar integer. If you set DesignMethod to "Elliptic", then FilterOrder must be an odd integer greater than one. If you set DesignMethod to "Quasi-linear phase", then FilterOrder must be a multiple of four.

Dependencies

To enable this property, set Specification to "Filter order and stopband attenuation" or "Filter order and transition width".

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

Minimum attenuation needed in the stopband of the IIR halfband filter, specified as a positive real scalar. Units are in dB.

Dependencies

To enable this property, set Specification to "Filter order and stopband attenuation" or "Transition width and stopband attenuation".

Data Types: single | double

Transition width of the IIR halfband filter, specified as a positive real scalar or in normalized frequency units (since R2023b).

If you set the NormalizedFrequency property to:

  • false –– The value of the transition width is in Hz and must be less than half the output sample rate (2 × SampleRate property) value.

  • true –– The value of the transition width is in normalized frequency units. The value must be a positive scalar less than 1.0.

    When you set the NormalizedFrequency property to true while creating the object and you do not set the transition width, the default transition width is automatically set to normalized frequency units using the default sample rate at which the filter operates (2 × 44100) Hz. The filter in the halfband interpolator effectively runs at twice the sample rate of the input signal.

    When you set the NormalizedFrequency property to true after you create the object, the transition width must be specified in normalized units before you run the object algorithm. To specify the normalized frequency value, set NormalizedFrequency to true and manually convert the frequency value in Hz to the normalized value using the input sample rate in Hz. For example, if the input sample rate is 22050 Hz, the corresponding transition width value in normalized units is TWHz/(2×Fs/2).

    iirhalfbandinterp = dsp.IIRHalfbandInterpolator;
    iirhalfbandinterp.NormalizedFrequency = true;
    iirhalfbandinterp.TransitionWidth = 4100/((2x22050)/2)

(since R2023b)

Dependencies

To enable this property, set Specification to "Transition width and stopband attenuation" or "Filter order and transition width".

Data Types: single | double

Design method for the IIR halfband filter, specified as "Elliptic" or "Quasi-linear phase". When you set this property to "Quasi-linear phase", the first branch of the polyphase structure is a pure delay, which results in an approximately linear phase response.

Dependencies

To enable this property, set Specification to any accepted value except "Coefficients".

Since R2023b

Flag to set frequencies in normalized units, specified as one of these values:

  • true –– The transition width must be in the normalized frequency units and less than 1.0.

    When you set the NormalizedFrequency property to true while creating the object and you do not set the transition width, the default transition width is automatically set to normalized frequency units using the default sample rate at which the filter operates (2 × 44100) Hz. The filter in the halfband interpolator effectively runs at twice the sample rate of the input signal.

    When you set the NormalizedFrequency property to true after you create the object, the transition width must be specified in normalized units before you run the object algorithm. To specify the normalized frequency value, set NormalizedFrequency to true and manually convert the frequency value in Hz to the normalized value using the input sample rate in Hz. For example, if the input sample rate is 22050 Hz, the corresponding transition width value in normalized units is TWHz/(2×Fs/2).

    iirhalfbandinterp = dsp.IIRHalfbandInterpolator;
    iirhalfbandinterp.NormalizedFrequency = true;
    iirhalfbandinterp.TransitionWidth = 4100/((2x22050)/2)
  • false –– The transition width is in Hz. You can specify the input sample rate through the SampleRate property.

Dependency

To enable this property, set Specification to any accepted value except "Coefficients".

Data Types: logical

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

Dependency

To enable this property, set:

  • Specification to any accepted value except "Coefficients".

  • NormalizedFrequency to false. (since R2023b)

Data Types: single | double

Option to use object as synthesis filter bank, specified as a logical value. If this property is false, dsp.IIRHalfbandInterpolator acts as an interpolator. If this property is true, then dsp.IIRHalfbandInterpolator acts as a synthesis filter bank and the algorithm accepts two inputs: the lowpass and highpass subbands.

Dependencies

To enable this property, set Specification to any accepted value except "Coefficients".

Internal allpass filter implementation structure, specified as "Minimum multiplier" or "Wave Digital Filter". Each structure uses a different coefficients set, independently stored in the corresponding object property.

This property is not tunable.

Dependencies

To enable this property, set Specification to "Coefficients".

Allpass polynomial filter coefficients of the first branch, specified as an N-by-1 or N-by-2 matrix. N is the number of first-order or second-order allpass sections.

Tunable: Yes

Dependencies

To enable this property, set Specification to "Coefficients" and Structure to "Minimum multiplier".

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

Allpass polynomial filter coefficients of the second branch, specified as an N-by-1 or N-by-2 matrix. N is the number of first-order or second-order allpass sections.

Tunable: Yes

Dependencies

To enable this property, set Specification to "Coefficients" and Structure to "Minimum multiplier".

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

Allpass filter coefficients of the first branch in Wave Digital Filter form, specified as an N-by-1 or N-by-2 matrix. N is the number of first-order or second-order allpass sections. All elements must have an absolute value less than or equal to 1.

This property is not tunable.

Dependencies

To enable this property, set Specification to "Coefficients" and Structure to "Wave Digital Filter".

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

Allpass filter coefficients of the second branch in Wave Digital Filter form, specified as an N-by-1 or N-by-2 matrix. N is the number of first-order or second-order allpass sections. All elements must have an absolute value less than or equal to 1.

This property is not tunable.

Dependencies

To enable this property, set Specification to "Coefficients" and Structure to "Wave Digital Filter".

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

Flag to make the first allpass branch a delay, specified as a logical scalar. When this property is true, the first branch is treated as a pure delay and the properties AllpassCoefficients1 and WDFCoefficients1 do not apply.

This property is not tunable.

Dependencies

To enable this property, set Specification to "Coefficients".

Length of the first branch delay, specified as a finite positive scalar. The value of this property specifies the number of samples by which you can delay the input to the first branch.

This property is not tunable.

Dependencies

To enable this property, set Specification to "Coefficients" and HasPureDelayBranch to 1.

Data Types: single | double

Option to treat the last section of the second branch as first order, specified as a logical scalar. When this property is 1 and the coefficients of the second branch are in an N-by-2 matrix, the object ignores the second element of the last row of the matrix. The last section of the second branch then becomes a first-order section. When this property is set to 0, the last section of the second branch is a second-order section. When the coefficients of the second branch are in an N-by-1 matrix, this property is ignored.

This property is not tunable.

Dependencies

To enable this property, set Specification to "Coefficients".

Usage

Description

y = iirhalfbandinterp(x1) upsamples by two and interpolates the input signal x1 using the IIR halfband interpolator, iirhalfbandinterp.

example

y = iirhalfbandinterp(x1,x2) implements a halfband synthesis filter bank for the inputs x1 and x2. x1 is the lowpass output of a halfband analysis filter bank and x2 is the highpass output of a halfband analysis filter bank. dsp.IIRHalfbandInterpolator implements a synthesis filter bank only when the FilterBankInputPort property is true.

example

Input Arguments

expand all

Data input to the IIR halfband interpolator, specified as a column vector or a matrix. This signal is the lowpass output of a halfband analysis filter bank. If the input signal is a matrix, each column of the matrix is treated as an independent channel.

Data Types: single | double
Complex Number Support: Yes

Second data input to the synthesis filter bank, specified as a column vector or a matrix. This signal is the highpass output of a halfband analysis filter bank. If the input signal is a matrix, each column of the matrix is treated as an independent channel.

The size, data type, and complexity of both the inputs must be the same.

Data Types: single | double
Complex Number Support: Yes

Output Arguments

expand all

Output of the interpolator, returned as a column vector or a matrix. The number of rows in the interpolator output is twice the number of rows in the input signal.

Data Types: single | double
Complex Number Support: Yes

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

freqzFrequency response of discrete-time filter System object
freqzmrCompute DTFT approximation of impulse response of multirate or single-rate filter
filterAnalyzerAnalyze filters with Filter Analyzer app
infoInformation about filter System object
costEstimate cost of implementing filter System object
polyphasePolyphase decomposition of multirate filter
outputDelayDetermine output delay of single-rate or multirate filter
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Create a minimum order lowpass IIR halfband interpolation filter. The filter has a transition width of 0.0930 in normalized frequency units, and a stopband attenuation of 80 dB.

IIRHalfbandInterp = dsp.IIRHalfbandInterpolator(...
    NormalizedFrequency=true,...
    DesignMethod="Quasi-linear phase");

Obtain filter coefficients

c = coeffs(IIRHalfbandInterp);

Plot the Magnitude and Phase response

freqz(IIRHalfbandInterp)

Figure contains 2 axes objects. Axes object 1 with title Phase, xlabel Normalized Frequency (\times\pi rad/sample), ylabel Phase (degrees) contains an object of type line. Axes object 2 with title Magnitude, xlabel Normalized Frequency (\times\pi rad/sample), ylabel Magnitude (dB) contains an object of type line.

Design an elliptic IIR halfband interpolator object of order 31 and a transition width of 0.1 using the designHalfbandIIR function. Set the Verbose argument to true.

hbIIR = designHalfbandIIR(FilterOrder=31,TransitionWidth=0.1,DesignMethod="ellip",...
    Structure='interp',SystemObject=true,Verbose=true)
designHalfbandIIR(FilterOrder=31, TransitionWidth=0.1, DesignMethod="ellip", Structure="interp", Datatype="double", SystemObject=true, Passband="lowpass")
hbIIR = 
  dsp.IIRHalfbandInterpolator with properties:

                   Specification: 'Coefficients'
             FilterBankInputPort: false
                       Structure: 'Minimum multiplier'
              HasPureDelayBranch: false
            AllpassCoefficients1: [8x1 double]
            AllpassCoefficients2: [7x1 double]
    HasTrailingFirstOrderSection: false

Create a dsp.DynamicFilterVisualizer object and visualize the magnitude response of the filter.

dfv = dsp.DynamicFilterVisualizer(NormalizedFrequency=true);
dfv(hbIIR);

The input is a cosine wave.

Fs = 1;
Fc = 0.08;
input = cos(2*pi*Fc*(0:39)'/Fs);

Interpolate the cosine signal using the IIR halfband interpolator.

output = hbIIR(input);

Plot the original and interpolated signals. In order to plot the two signals in the same plot, you must account for the output delay introduced by the IIR halfband interpolator and the scaling introduced by the filter. Use the outputDelay function to compute the delay introduced by the interpolator. Shift the output by this delay value.

Visualize the input and the resampled signals. The input and output values coincide every other sample, due to the interpolation factor of 2.

[delay,FsOut] = outputDelay(hbIIR,FsIn=Fs,Fc=Fc)
delay = 
3.5090
FsOut = 
2
nInput = (0:length(input)-1);
tOutput = (0:length(output)-1)/FsOut-delay;
stem(tOutput,output,'filled',MarkerSize=4); hold on;
stem(nInput,input); hold off;
xlim([-5,20])
legend('Interpolated by 2','Input signal','Location','best');

Figure contains an axes object. The axes object contains 2 objects of type stem. These objects represent Interpolated by 2, Input signal.

Use a halfband analysis filter bank and interpolation filter to extract the low frequency subband from a speech signal.

Note: The audioDeviceWriter System object™ is not supported in MATLAB Online.

Set up the audio file reader, the analysis filter bank, the audio device writer, and the interpolation filter. The sampling rate of the audio data is 22050 Hz. The halfband filter has an order of 21 and a transition width of 2 kHz.

afr = dsp.AudioFileReader('speech_dft.mp3',SamplesPerFrame=1024);

filterspec = "Filter order and transition width";
Order = 21;
TW = 2000;

IIRHalfbandDecim = dsp.IIRHalfbandDecimator(...
    Specification=filterspec,FilterOrder=Order,...
    TransitionWidth=TW,SampleRate=afr.SampleRate);

IIRHalfbandInterp = dsp.IIRHalfbandInterpolator(...
    Specification=filterspec,FilterOrder=Order,...
    TransitionWidth=TW,SampleRate=afr.SampleRate/2);

ap = audioDeviceWriter(SampleRate=afr.SampleRate);

View the magnitude response of the halfband filter.

filterAnalyzer(IIRHalfbandDecim)

Read the speech signal from the audio file in frames of 1024 samples. Filter the speech signal into lowpass and highpass subbands with a halfband frequency of 5512.5 Hz. Reconstruct a lowpass approximation of the speech signal by interpolating the lowpass subband. Play the filtered output.

while ~isDone(afr)
  audioframe = afr();
  xlo = IIRHalfbandDecim(audioframe);
  ylow = IIRHalfbandInterp(xlo);
  ap(ylow);
end

Wait until the audio file ends, and then close the input file and release the audio output resource.

release(afr);           
release(ap);

Use a halfband decimator and interpolator to implement a two-channel filter bank. This example uses an audio file input and shows that the power spectrum of the filter bank output does not differ significantly from the input.

Note: The audioDeviceWriter System object™ is not supported in MATLAB Online.

Set up the audio file reader and audio device writer. Construct the IIR halfband decimator and interpolator. Finally, set up the spectrum analyzer to display the power spectra of the filter-bank input and output.

AF = dsp.AudioFileReader('speech_dft.mp3',SamplesPerFrame=1024);
AP = audioDeviceWriter(SampleRate=AF.SampleRate);

filterspec = "Filter order and transition width";
Order = 51;
TW = 2000;

IIRHalfbandDecim = dsp.IIRHalfbandDecimator(...
    Specification=filterspec,FilterOrder=Order,...
    TransitionWidth=TW,SampleRate=AF.SampleRate);

IIRHalfbandInterp = dsp.IIRHalfbandInterpolator(...
    Specification=filterspec,FilterOrder=Order,...
    TransitionWidth=TW,SampleRate=AF.SampleRate/2,...
    FilterBankInputPort=true);

SpecAna = spectrumAnalyzer(SampleRate=AF.SampleRate,...
    PlotAsTwoSidedSpectrum=false,...
    ShowLegend=true,...
    ChannelNames={'Input signal','Filtered output signal'});

Read the audio 1024 samples at a time. Filter the input to obtain the lowpass and highpass subband signals decimated by a factor of two. This is the analysis filter bank. Use the halfband interpolator as the synthesis filter bank. Display the running power spectrum of the audio input and the output of the synthesis filter bank. Play the output.

while ~isDone(AF)
    audioInput = AF();
    [xlo,xhigh] = IIRHalfbandDecim(audioInput);
    audioOutput = IIRHalfbandInterp(xlo,xhigh);
    spectrumInput = [audioInput audioOutput];
    SpecAna(spectrumInput);
    AP(audioOutput);
end

release(AF);
release(AP);
release(SpecAna);

Create a halfband interpolation filter. The filter order is 51 with a transition width of 0.0930 in normalized frequency units.

filterspec = "Filter order and transition width";
Order = 51;
TW = 0.0930;  
iirhalfbandinterp = dsp.IIRHalfbandInterpolator(...
    NormalizedFrequency=true,...
    Specification=filterspec,...
    FilterOrder=Order,...
    TransitionWidth=TW);

Use the filter to upsample and interpolate a multichannel input.

x = randn(1024,4);
y = iirhalfbandinterp(x);

Algorithms

expand all

References

[1] Lang, M. Allpass Filter Design and Applications. IEEE Transactions on Signal Processing. Vol. 46, No. 9, Sept 1998, pp. 2505–2514.

[2] Harris, F.J. Multirate Signal Processing for Communication Systems. Prentice Hall. 2004, pp. 208–209.

[3] Regalia, Phillip A., Sanjit K. Mitra, and P. P. Vaidyanathan. "The Digital All-Pass Filter: A Versatile Signal Processing Building Block." Proceedings of the IEEE. Vol. 76, Number 1, 1988, pp. 19-37.

Extended Capabilities

Version History

Introduced in R2015b

expand all