Engee documentation

phasedelay

The phase delay of the digital filter.

Library

EngeeDSP

Syntax

Function call

  • phi,w = phasedelay(b,a,n) — calculates the phase delay of the specified digital filter. Specify a digital filter with numerator coefficients b and the coefficients of the denominator a. The function returns n-the point vector of the phase delay characteristic in the output argument phi and the corresponding angular frequency vector w.

  • phi,w = phasedelay(B,A,"ctf",n) — returns n-a point vector of the phase delay characteristic of a digital filter, represented as Cascaded Transfer Functions (Cascaded Transfer Functions, CTF) with numerator coefficients B and the coefficients of the denominator A.

  • phi,w = phasedelay((B,A,g),"ctf",n) — returns n-a point vector of the phase delay characteristic of a digital filter in CTF format. Specify a filter with numerator coefficients B, the coefficients of the denominator A and scale values g by filter sections.

  • phi,w = phasedelay(sos,n) — returns n`is the point vector of the phase delay characteristic corresponding to the matrix of second-order sections `sos.

  • phi,w = phasedelay(___,n,"whole") — returns the phase delay characteristic vector in n equidistant points along the entire unit circle.

  • phi,f = phasedelay(___,n,fs) — returns the vector of the phase delay characteristic and the corresponding n-a point vector of frequencies f for a digital filter designed to filter signals sampled with frequency fs.

  • phi,f = phasedelay(___,n,"whole",fs) — returns the frequency vector f in n points in the range from 0 before fs.

  • phi,w = phasedelay(___,w) — returns the vector of the phase delay characteristic calculated at the angular frequencies specified in the input argument w.

  • phi,f = phasedelay(___,f,fs) — returns the vector of the phase delay characteristic calculated at the frequencies specified in the input argument f.

  • phi = phasedelay(___;nout=1) — returns only the phase delay characteristic vector phi.

  • phasedelay(___;out=:plot) — plots the phase delay depending on the frequency.

Arguments

Input arguments

# b,a are the coefficients of the transfer function

+ vectors

Details

The coefficients of the transfer function, set as vectors.

Типы данных

Float32, Float64

# n is the number of frequency points from which the phase delay characteristic is calculated

+ 512 (by default) | a positive integer

Details

The number of frequency points from which the phase delay characteristic is calculated, set as a positive integer. Set for the argument n a value exceeding the filter order.

Типы данных

Float32, Float64

# B,A are the coefficients of the cascade transfer function

+ scalars | vectors | matrices

Details

The coefficients of the cascade transfer function, specified as scalars, vectors, or matrices. In matrices B and A The coefficients of the numerator and denominator of the cascade transfer function are listed, respectively.

The matrix B must have a size of on , and the matrix A on , where

  • — number of filter sections;

  • — the order of the numerators of the filter;

  • — the order of the denominators of the filter.

For more information about the cascade transfer function format and coefficient matrices, see Setting digital filters in CTF format.

If any element of the matrix A[:,1] not equal to 1, then the function phasedelay normalizes the filter coefficients by A[:,1]. In this case A[:,1] must be non-zero.
Типы данных

Float32, Float64

Support for complex numbers

Yes

# g — scale values

+ scalar | vector

Details

Scale values specified as a real scalar or vector with real values containing the element where — the number of sections of the cascade transfer function. The scale values represent the distribution of the filter gain across the sections of the cascade filter representation.

Function phasedelay applies the gain to the filter sections using the function scaleFilterSections depending on the way the argument is set g:

  • scalar — the function distributes the gain evenly across all filter sections;

  • vector — the function applies the first applies the gain values to the corresponding filter sections and distributes the last gain value evenly across all filter sections.

Типы данных

Float64, Float32

# sos — coefficients of the sections of the second order

+ the matrix

Details

Coefficients of the second-order sections, specified as a matrix. Argument sos — this is the matrix on , where is the number of sections must be greater than or equal to 2. If the number of sections is less 2, the function processes the input data as a vector of numerators b. Each line sos corresponds to the coefficients of the second-order filter (biquadrate filter); -I am a row of the matrix sos respond [bi[1] bi[2] bi[3] ai[1] ai[2] ai[3]].

Типы данных

Float32, Float64

# w — angular frequencies

+ vector

Details

The angular frequencies at which the function calculates the phase delay characteristic are set as a vector, the units of measurement are rad/count. The frequencies are usually in the range of 0 before . Vector w must contain at least two elements.

# fs — sampling rate
scalar

Details

The sampling frequency, set as a real scalar and expressed in Hz.

Типы данных

Float64

# f — frequencies

+ vector

Details

The frequencies at which the function calculates the phase delay characteristic, given as a vector and expressed in Hz. Vector f must contain at least two elements.

Name-value input arguments

# out — type of output data

+ :data (by default) | :plot

Details

Type of output data:

  • :data — the function returns data;

  • :plot — the function returns a graph.

# nout — number of output arguments

+ 2 (default) | 1

Details

The number of output arguments, set as 2 or 1. If the argument is nout omitted, the default function returns a tuple of two vectors. If nout = 1, the function will return only the phase delay characteristic vector phi.

Output arguments

# phi — phase delay characteristic

+ vector

Details

The phase delay characteristic returned as a length vector n. The phase delay characteristic is calculated in n equidistant points along the upper half of the unit circle.

If the input data of the function is phasedelay It has single precision, the function calculates the phase delay characteristic using single precision arithmetic. Output argument phi it has a single precision.

# w — angular frequencies

+ vector

Details

Angular frequencies returned as a vector and expressed in rad/count. If an argument is given n, vector w has a length of n. If n if it is not specified or set as an empty vector, then the length of the vector is w equal to 512.

# f — frequencies

+ vector

Details

Frequencies returned as a vector and expressed in Hz. If an argument is given n, vector f has a length of n. If n if it is not specified or set as an empty vector, then the length of the vector is f equal to 512.

Examples

Phase delay characteristic for second-order sections

Details

Let’s design a third-order Butterworth low-pass filter with a cutoff frequency 200 Hz. The sampling rate is 1000 Hz.

import EngeeDSP.Functions: butter

fc = 200
fs = 1000

z, p, k = butter(3, fc/(fs/2), "low", out = 3)

Using the function zp2sos to convert zeros, poles, and gain into second-order sections. Calculate the characteristic of the phase delay of the filter and set the number of evaluation points to 1024. Let’s plot the result graph.

import EngeeDSP.Functions: zp2sos, phasedelay

sos = zp2sos(z, p, k)
phasedelay(sos, 1024, out = :plot)

phasedelay

Phase delay characteristic of an elliptical filter

Details

Let’s design an elliptical filter 10-th order with normalized bandwidth frequency 0.4. Setting the ripple in the bandwidth 0.5 dB and attenuation in the delay band 20 dB. Let’s plot the characteristics of the phase delay of the filter on the entire unit circle.

import EngeeDSP.Functions: ellip, phasedelay

b, a = ellip(10, 0.5, 20, 0.4)
phasedelay(b, a, 512, "whole", out = :plot)

phasedelay 1

Additional Info

Cascading transfer functions

Details

Splitting a digital IIR filter into cascaded sections increases its numerical stability and reduces its susceptibility to coefficient quantization errors. Cascade form of the transfer function expressed in terms of transfer functions , has the form

butter en

Setting digital filters in CTF format

Details

Digital filters can be designed in CTF format to analyze, visualize, and filter signals. The filter is set by enumerating its coefficients B and A. You can also specify the scaling factor of the filter by sections by setting a scalar or vector value. g.

coeffects of the filter

When setting coefficients in the form -lowercase matrices

it is assumed that the filter is set as a sequence of cascade transfer functions, so that the complete transfer function of the filter has the form

where — the order of the filter numerator, and — the order of the denominator.

  • If and defined as vectors, it is assumed that the basic system is a single-section IIR filter ( ), where represents the numerator of the transfer function, and — its denominator.

  • If — scalar, it is assumed that the filter is a cascade of all-pole IIR filters, with the total system gain of each cascade equal to .

  • If — scalar, it is assumed that the filter is a cascade of FIR filters, and the total gain of the system of each cascade is equal to .

  • To convert second-order section matrices into cascade transfer functions, use the function sos2ctf.

  • To convert the filter representation with zeros, poles, and gain into cascaded transfer functions, use the function zp2ctf.

coeffects and amplification

If there is a common scale gain or several scale gain factors that are outside the values of the filter coefficients, you can specify the coefficients and gain as a tuple. (B, A, g). Scaling the filter sections is especially important when working with fixed-point arithmetic to ensure that the output signals of each filter section have similar amplitude levels, which helps to avoid inaccuracies in the frequency response of the filter due to limited computational accuracy.

The gain can be a scalar total gain or a vector of section gain coefficients.

  • If the gain is scalar, its value is applied uniformly to all sections of the cascade filter.

  • If the gain is a vector, it must contain one element more than the number of filter sections. in the cascade. Each of the first The scale value is applied to the corresponding filter section, and the last value is applied evenly to all sections of the cascade filter.

If you specify the filter coefficient matrices and the gain coefficient vector as

it is assumed that the transfer function of the filter system has the form

Algorithms

The characteristic of the phase delay of the filter corresponds to the time delay experienced by each frequency component as the input signal passes through the system. Function phasedelay returns the phase delay characteristic vector and the frequency vector of the filter

given the coefficients of the numerator and denominator in the input arguments b and a.

Literature

  1. Lyons, Richard G. Understanding Digital Signal Processing. Upper Saddle River, NJ: Prentice Hall, 2004.