Engee documentation

pulsewidth

The pulse duration of a two-level signal.

Library

EngeeDSP

Syntax

Function call

  • w = pulsewidth(x) — returns the difference between the moments of the average reference level of the initial and final transitions of each pulse of positive polarity in the input two-level signal.

  • w = pulsewidth(x,fs) — determines the sampling rate fs in Hz. The first moment of time in the signal corresponds to the moment .

  • w = pulsewidth(x,t) — determines the sampling moments t.

  • w,initcross = pulsewidth(___) — returns moments initcross the average reference level of the initial transition of each pulse. You can specify an input combination of any of the above syntax options.

  • W = pulsewidth(___,Name,Value) — sets additional parameters using one or more arguments of the type Name,Value.

  • pulsewidth(___) — plots the signal and darkens the areas of each pulse in which the function calculates its duration. The function marks the position of the middle intersections and their corresponding reference level. The function also plots state levels and their associated lower and upper bounds.

Arguments

Input arguments

# x is a two— level signal

+ the real vector

Details

A two-level signal defined as a real vector.

# fs — sampling rate
positive real scalar

Details

The sampling frequency, specified as a positive real scalar, expressed in Hz.

# t — selection of time points
vector

Details

A selection of time points, set as a vector. Vector length t must be equal to the length of the two-level signal x.

Name-value input arguments

Specify optional argument pairs as Name,Value, where Name — the name of the argument, and Value — the appropriate value. Name-value arguments should be placed after other arguments, but the order of the pairs does not matter.

Use commas to separate the name and value, and Name put it in quotation marks.

# MidPercentReferenceLevel — the average reference level

+ 50 (by default) | the real scalar

Details

The average reference level as a percentage of the signal amplitude, set as a real scalar. For more information, see The average reference level.

# Polarity — the polarity of the pulse

+ "positive" (by default) | "negative"

Details

The polarity of the pulse, set as "positive" or "negative". If specified "positive" the function searches for pulses with positive initial transitions (positive polarity). If specified "negative", function pulsewidth It searches for pulses with negative initial transitions (negative polarity). For more information, see Pulse polarity.

# StateLevels — lower and upper state levels

+ the real vector

Details

The levels of the lower and upper states, defined as a vector of real values with the size 1 on 2. The first element is the lower state level. The second element is the upper state level. If the levels of the lower and upper states are not specified, the function pulsewidth evaluates the state levels based on the input signal using the histogram method. For a detailed description of the histogram method, see Assessment at the state level.

# Tolerance — tolerance levels

+ 2 (by default) | the real scalar

Details

Tolerance levels (boundaries of the lower and upper states), set as a real scalar, expressed as a percentage. For more information, see State-level tolerances.

# out — type of output data

+ :plot (default) | :data

Details

Type of output data:

  • :plot — the function returns a graph;

  • :data — the function returns data.

Output arguments

# w — pulse duration

+ vector

Details

Pulse duration in seconds, returned as a vector. The pulse duration is the time difference between the initial and final transitions of the pulse. In [1] the moments of the initial and final transitions are called the moments of transition occurrence.

Because the function pulsewidth uses interpolation to determine the moments of the average reference level, w It may contain values that do not correspond to the sampling moments of the two-level signal. x.

# initcross — the moment of the average reference level of the initial transition

+ column vector

Details

The moments of the average reference level of the initial transitions of each pulse, returned as a column vector.

# finalcross — the moment of the average reference level of the final transition

+ column vector

Details

The moments of the average reference level of the final transitions of each pulse, returned as a column vector.

# midlev — signal value

+ scalar

Details

The signal value corresponding to the average reference level, returned as a scalar.

Examples

The initial and final transitions of a two-level signal

Details

Let’s calculate the initial and final transitions for a two-level waveform sampled at a frequency 400 kHz.

import EngeeDSP.Functions: pulsewidth

fs = 4e5
t1 = collect(0:1/fs:3)
x1 = zeros(length(t1))
t2 = collect((3+1/fs):1/fs:4)
x2 = fill(5, length(t2))
t3 = collect((4+1/fs):1/fs:7)
x3 = zeros(length(t3))
t = vcat(t1, t2, t3)
x = vcat(x1, x2, x3)

w, initcross, finalcross, midlev = pulsewidth(x, fs)
(1.0000000000000004, 3.00000125, 4.00000125, 2.5)

Additional Info

Assessment at the state level

Details

To determine the transitions, the function pulsewidth evaluates the levels of the lower and upper states of the input signal x using the histogram method in the following steps.

  1. Determine the minimum and maximum data amplitudes.

  2. For a given number of histogram columns, determine the column width, which is the ratio of the amplitude range to the number of columns.

  3. Sort data values by histogram columns.

  4. Determine the lowest and highest indexed histogram columns with non-zero values.

  5. Divide the histogram into two sub-histograms.

  6. Calculate the state levels by determining the mode or the average of the upper and lower histograms.

The function identifies all regions that intersect the upper boundary of the lower state and the lower boundary of the upper state. The boundaries of the lower and upper states are expressed as the state level plus or minus a multiple of the difference between the state levels.

The average reference level

Details

The average reference level in a two-level signal with a lower state level and the upper state level equal to

The moment of the average reference level

Details

The moment of the average reference level is

where

  • indicates the average reference level;

  • and denote two consecutive sampling moments corresponding to the values of the signal closest in value to ;

  • and denote the values of the signal at the moment and .

Pulse polarity

Details

If the initial transition of the pulse is positive, the pulse has a positive polarity. Similarly, an impulse of positive polarity (with a positive increase) has an end state more positive than the initial one. This figure shows a positive polarity pulse.

dutycycle 1 en

If the initial transition of the pulse is negative, the pulse has a negative polarity. Similarly, an impulse of negative polarity (with a negative increase) has an initial state more positive than the final one. This figure shows a negative polarity pulse.

dutycycle 2 en

State-level tolerances

Details

You can specify the boundaries of the lower and upper states for each state level. Let’s define boundaries as the level of states plus or minus a scalar value that is a multiple of the difference between the upper and lower states. To set a useful tolerance range, we set a scalar value as a small number, for example or . In the general case, the area for the lower state, it is defined as

where — the level of the lower state, and — the level of the upper state. Let’s replace the first term in the equation with to get the tolerance area for the upper state level.

Literature

  1. IEEE Standard 181. IEEE® Standard on Transitions, Pulses, and Related Waveforms (2003).