Engee documentation

pulstran

A sequence of pulses.

Library

EngeeDSP

Syntax

Function call

  • y = pulstran(t,d,func) — generates a sequence of pulses based on continuous function samples func.

  • y = pulstran(t,d,func,fs) — uses the sampling rate fs.

  • y = pulstran(t,d,p) — generates a sequence of pulses, which is the sum of several delayed interpolations of the prototype pulse in the vector p.

  • y = pulstran(___,intfunc) — defines alternative interpolation methods. For a list of available methods, see the functions page. interp1. Argument intfunc It can be used with any of the above input syntax options.

Arguments

Input arguments

# t — time values

+ vector

Details

The time values at which the argument is calculated func, set as a vector.

# d — offset

+ vector string | a two-column matrix

Details

The offset removed from the vector values t, defined as a real vector. You can apply an optional gain to each deferred evaluation by specifying an argument d as a two-column matrix with the offset defined in column 1 and the corresponding gain in column 2. If d set as a string vector, the values are interpreted only as delays.

# func — continuous function

+ "rectpuls" | "gauspuls" | "tripuls"

Details

A continuous function used to generate a sequence of pulses based on its samples, defined as "rectpuls", "gauspuls" or "tripuls".

# p — Pulse prototype

+ vector

Details

A prototype function defined as a vector. Interval p set as [0,(length(p)−1)/fs], and its samples outside this range are identically zero. By default, linear interpolation is used to generate delays.

# fs — sampling rate
1 (by default) | the real scalar

Details

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

# intfunc — interpolation method

+ "linear" (by default) | "nearest" | "next" | "previous" | "pchip" | "cubic" | "v5cubic" | "makima" | "spline"

Details

The interpolation method specified as one of the options shown in the table.

Method Description Continuity Comments

"linear"

Linear interpolation. The interpolated value at the query point is based on linear interpolation of values at neighboring grid points in each corresponding dimension. This is the default interpolation method.

  • Requires at least 2 dots

  • It requires more memory and computing time than nearest neighbor interpolation.

"nearest"

Nearest neighbor interpolation. The interpolated value at the query point is the value at the nearest point in the sampling grid.

Intermittent

  • Requires at least 2 dots

  • Low memory requirements

  • Fastest calculation time

"next"

Interpolation to the next neighbor. The interpolated value at the query point is the value at the next point in the selection grid.

Intermittent

  • Requires at least 2 dots

  • The same memory requirements and computing time as for "nearest"

"previous"

Interpolation by the previous neighbor. The interpolated value at the query point is the value at the previous point in the selection grid.

Intermittent

  • Requires at least 2 dots

  • The same memory requirements and computing time as for "nearest"

"pchip" or "cubic"

Piecewise cubic shape-preserving interpolation. The interpolated value at the query point is based on piecewise cubic interpolation of values at neighboring grid points while preserving the shape.

  • Requires at least 4 points

  • Requires more memory and computing time than "linear"

"v5cubic"

Cubic convolution used in Engee.

The points should be evenly distributed

"makima"

Akim’s modified interpolation by cubic Hermite polynomials. The interpolated value at the query point is based on a piecewise linear function of polynomials of degree no higher than the third. Akim’s formula has been modified to prevent emissions.

  • Requires at least 2 points

  • Creates less undulation than "spline" But it doesn’t smooth out as aggressively as "pchip"

  • Calculations require more resources than "pchip", but usually less than "spline"

  • The memory requirements are similar "spline"

"spline"

Spline interpolation using "not-a-knot" conditions. The interpolated value at the query point is based on cubic interpolation of values at neighboring grid points in each corresponding dimension.

  • At least 4 points are required, and if there are 2 or 3 points, linear or quadratic interpolation is applied, respectively.

  • Requires more memory and computing time than "pchip"

Output arguments

# y — pulse sequence

+ vector

Details

A sequence of pulses generated by a function, returned as a vector.

Examples

Periodic rectangular pulse

Details

In this example, a pulse sequence is generated using a standard rectangular pulse of unit width. The repetition rate is 0.5 Hz, the duration of the signal — 60 c, and the sampling rate — 1 kHz. Gain factor — sinusoid with frequency 0.05 Hz.

import EngeeDSP.Functions: pulstran, rectpuls

t = 0:1/1e3:60
d = [0:2:60 sin.(2π*0.05*(0:2:60))]
y = pulstran(t, d, rectpuls)

plot(t, y, xlabel="Time (s)", ylabel="Waveform", legend=false)

pulstran 1

Asymmetric sawtooth signal

Details

In this example, an asymmetric sawtooth signal with a repetition rate is generated. 3 Hz. The width of the sawtooth signal is 0.2 c, and the shift coefficient — 1. The duration of the signal is 1 c, and the sampling rate — 1 kHz. Let’s plot the pulse sequence.

import EngeeDSP.Functions: tripuls, pulstran

fs = 1e3
t = 0:1/1e3:1
d = 0:1/3:1
x = tripuls(t, 0.2, -1)
y = pulstran(t, d, x, fs)

plot(t, y, xlabel="Time (s)", ylabel="Waveform", legend=false)

pulstran 2

Changing the interpolation method using a custom pulse

Details

Let’s write a function that generates a custom exponentially decaying sawtooth signal with a frequency of 0.25 Hz. The generating function has a second input argument, which specifies one value of the sawtooth frequency and the attenuation coefficient. Let’s display the generated pulse with the sampling frequency 0.1 kHz during 1 seconds, with frequency and attenuation factor equal to 50.

import EngeeDSP.Functions: sawtooth

fnx = (x, fn) -> sawtooth.(2π * fn * 0.25 * x) .* exp.(-2 * fn * x.^2)

fs = 100
t = 0:1/fs:1

pp = fnx(t, 50)

plot(t, pp, legend=false)

pulstran 3

Using the function pulstran to generate a sequence of user pulses. The sequence is sampled with frequency 0.1 kHz during 125 seconds. The pulses appear every 25 seconds and have an exponentially decreasing amplitude.

We will specify the generated pulse as a prototype. We will generate three pulse sequences using the standard linear interpolation method, nearest neighbor interpolation and piecewise cubic interpolation. Let’s compare the pulse sequences on the same graph.

import EngeeDSP.Functions: pulstran

d = [0:25:125 exp.(-0.015*(0:25:125))]
ffs = 100
tp = 0:1/ffs:125

fnx = (x, fn) -> sawtooth.(2π * fn * 0.25 * x) .* exp.(-2 * fn * x.^2)
pp = fnx(tp, 50)

r = pulstran(tp, d, pp)
y = pulstran(tp, d, pp, "nearest")
q = pulstran(tp, d, pp, "pchip")

plot(tp, r, label="Linear", xlims=(0, 125))
plot!(tp, y, label="Nearest neighbor")
plot!(tp, q, label="Piecewise cubic")

pulstran 4