Main Content

freqzmr

Compute DTFT approximation of impulse response of multirate or single-rate filter

Since R2024a

Description

[Y,Fout] = freqzmr(filtObj) outputs the impulse response discrete-time Fourier transform (DTFT) and corresponding frequencies of the filter object specified in filtObj.

If the input filter is a single-rate FIR or IIR filter, the behavior of freqzmr and freqz functions is equivalent. If the filter is an irreducible multirate filter, use the freqzmr function to analyze the frequency response of the filter. For more details on the differences between these two functions, see Comparison of freqzmr and freqz functions. For more information on reducible and irreducible multirate filters, see Overview of Multirate Filters.

example

freqzmr(filtObj) plots the magnitude and phase of the impulse response DTFT. The function also color-codes the distortion caused by the rate changes. For more information on distortion, see Output Distortion.

example

Examples

collapse all

Compute and plot the impulse response DTFT of FIR rate converter using the freqzmr function.

firRC = dsp.FIRRateConverter(5,7);
freqzmr(firRC)

Figure Output spectrum (one sided) contains 2 axes objects. Axes object 1 with title Output Magnitude, xlabel Frequency (mHz), ylabel Magnitude (dB) contains an object of type patch. Axes object 2 with title Output Phase, xlabel Frequency (mHz), ylabel Phase (rad) contains an object of type line.

Compute the impulse response DTFT of sample rate converter using the freqzmr function.

SRC = dsp.SampleRateConverter(InputSampleRate=77,...
                               OutputSampleRate=32*24,...
                               Bandwidth=23,...
                               StopbandAttenuation=120);
 
[Y,F] = freqzmr(SRC,MinimumFFTLength=1024);

When you do not specify any output arguments, the function plots the impulse response DTFT on a convenience plot.

Plot the impulse response DTFT with maximum distortion sensitivity. In the red regions in the plot, you can expect some distortion due to the rate-conversion aliasing.

freqzmr(SRC,MinimumFFTLength=1024,DistortionThreshold=-inf);

Figure Output spectrum (one sided) contains 2 axes objects. Axes object 1 with title Output Magnitude, xlabel Frequency (Hz), ylabel Magnitude (dB) contains an object of type patch. Axes object 2 with title Output Phase, xlabel Frequency (Hz), ylabel Phase (rad) contains an object of type line.

To hide distortion coloring, set DistortionThreshold to 0.

freqzmr(SRC,MinimumFFTLength=1024,DistortionThreshold=0);

Figure Output spectrum (one sided) contains 2 axes objects. Axes object 1 with title Output Magnitude, xlabel Frequency (Hz), ylabel Magnitude (dB) contains an object of type line. Axes object 2 with title Output Phase, xlabel Frequency (Hz), ylabel Phase (rad) contains an object of type line.

Specify the frequency range to be "centered".

freqzmr(SRC,MinimumFFTLength=1024,DistortionThreshold=-inf,FrequencyRange="centered");

Figure Output spectrum contains 2 axes objects. Axes object 1 with title Output Magnitude, xlabel Frequency (Hz), ylabel Magnitude (dB) contains an object of type patch. Axes object 2 with title Output Phase, xlabel Frequency (Hz), ylabel Phase (rad) contains an object of type line.

To compare, pass a random white noise signal to the sample rate converter. View the spectrum of the corresponding output in the spectrum analyzer.

You can see that the impulse response DTFT that freqzmr function computes is exactly the same as the spectrum of the output signal when you input a random white noise signal.

sa = spectrumAnalyzer(SampleRate=SRC.OutputSampleRate,PlotAsTwoSidedSpectrum=true,YLimits=[-200 20]);

for k=1:10
    u = randn(4096,1);
    y = SRC(u);
    sa(y);
end

Design a composite filter that is a cascade of these filters:

  • Single-rate filter

  • Parallel structure of multirate filters

Design the single-rate filter using the dsp.LowpassFilter object in its default configuration.

singleRateFilter = dsp.LowpassFilter
singleRateFilter = 
  dsp.LowpassFilter with properties:

               FilterType: 'FIR'
    DesignForMinimumOrder: true
        PassbandFrequency: 8000
        StopbandFrequency: 12000
           PassbandRipple: 0.1000
      StopbandAttenuation: 80
      NormalizedFrequency: false
               SampleRate: 44100

  Show all properties

The parallel structure contains a cascade of dsp.FIRInterpolator and dsp.FIRDecimator objects and a dsp.FIRRateConverter object.

Design the dsp.FIRInterpolator and the dsp.FIRRateConverter objects using the designBandpassFIR function.

B1 = 2.5*designBandpassFIR(FilterOrder=256,...
    CenterFrequency=0.3,Bandwidth=1/5);
B2 = 0.25*designBandpassFIR(FilterOrder=256,...
    CenterFrequency=0.7,Bandwidth=1/20);

Create a parallel structure of multirate filters using the parallel and cascade functions.

multirateFilter = parallel(cascade(dsp.FIRInterpolator(5,B1),...
    dsp.FIRDecimator(2)),dsp.FIRRateConverter(10,4,B2))
multirateFilter = 
  dsp.ParallelFilter with properties:

          Branch1: [1×1 dsp.FilterCascade]
          Branch2: [1×1 dsp.FIRRateConverter]
    CloneBranches: true

Create a composite filter that is a cascade of the single-rate filter and the parallel filter.

compositeFilter = cascade(singleRateFilter,multirateFilter)
compositeFilter = 
  dsp.FilterCascade with properties:

         Stage1: [1×1 dsp.LowpassFilter]
         Stage2: [1×1 dsp.ParallelFilter]
    CloneStages: true

Compute and plot the impulse response DTFT of this filter using the freqzmr function. Set MinimumFFTLength to 512. Set the frequency range to be "centered".

freqzmr(compositeFilter,MinimumFFTLength=512,FrequencyRange='centered')

Figure Output spectrum contains 2 axes objects. Axes object 1 with title Output Magnitude, xlabel Frequency (kHz), ylabel Magnitude (dB) contains an object of type patch. Axes object 2 with title Output Phase, xlabel Frequency (kHz), ylabel Phase (rad) contains an object of type line.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: src = dsp.SampleRateConverter(InputSampleRate=77,OutputSampleRate=32*24,Bandwidth=23,StopbandAttenuation=120); [Y,Fout] = freqzmr(src,MinimumFFTLength=1024,DistortionThreshold=-inf);

Shortest discrete spectrum length, specified as a positive integer. When the function resamples the spectrum internally (for example, during downsampling), the size of the resampled spectrum is no shorter than MinimumFFTLength. For more information, see DTFT of Downsampled Signal.

Data Types: double

Sample rate of the input signal FsIn in Hz, specified as a positive integer.

If you do not specify the input sample rate, the function inherits this value from the filter object. If the input filter object contains an explicit property to specify the input sample rate, the function uses the value of that property. If the filter object does not contain any such property, the function uses a value of 1.

Data Types: double

Frequency range of the DTFT, specified as one of these:

  • "auto" –– The function automatically determines the appropriate choice ("onesided" or "twosided") based on the system symmetry. The function selects "onesided" when the system spectrum is Hermitian symmetric and "twosided" otherwise.

  • "onesided" –– Impulse response DTFT contains only the positive frequencies. Frequency range is [0 Fsout/2].

  • "twosided" –– Frequency range is [0 Fsout].

  • "centered" –– Frequency range is [−Fsout/2 Fsout/2].

Fsout is the output sample rate and is given by the equation Fsout = FsIn×(L/M), where L/M is the rate conversion ratio of the input filter object.

Distortion threshold in dB to determine ambiguity in the convenience magnitude plot, specified as a scalar in the range (−∞ 0]. The DistortionThreshold argument is the threshold over which the signal is considered ambiguous.

Decrease the threshold value for a more sensitive detection of distortion. The function colors the convenience magnitude plot according to the distortion ratio. Red indicates maximum distortion (two or more branches have the same power), while blue indicates no distortion. If the distortion threshold is 0 dB, the function hides all distortion coloring.

The function ignores any distortion value below the value of DistortionThreshold and treats the output as non-ambiguous.

Here is a plot of the impulse response DTFT of an FIR rate converter with the distortion threshold of −∞. This plot shows the most sensitive detection of distortion.

Magnitude plot shows bright distinction between the red and blue areas in the distortion.

Increase the threshold value to −40 dB. The function ignores all distortions below −40 dB.

Magnitude plot shows bright distinction between the red and blue areas in the distortion.

Increasing the threshold value to 0 dB shows no distortion on the plot because the function ignores all the distortion values.

Magnitude plot shows no distortion.

For more information, see Output Distortion.

Data Types: double

Output Arguments

collapse all

DTFT approximation of the impulse response, returned as a column vector. The length of the impulse response DTFT depends on the MinimumFFTLength value and the rate conversion factors of the multirate filter stages.

Data Types: double
Complex Number Support: Yes

Output frequencies in Hz corresponding to the impulse response DTFT approximation, returned as a column vector. The length of Fout equals the length of Y. The range of Fout depends on the FrequencyRange.

Data Types: double

More About

collapse all

Algorithms

collapse all

The freqzmr algorithm treats the input filter object as a combination of FIR or IIR (single-rate) filters and multirate operations (upsample and downsample). The function processes the DTFT through each stage consecutively. For more information on DTFT, see Discrete-Time Fourier Transform (DTFT) and DFT and FFT.

Version History

Introduced in R2024a

expand all